Get the Size of HTTP Response using cURL Command (Content Length)


If you want to know what is the size of an HTTP/HTTPS request response-payload, you need to look at the content-length header from the response headers.

Example:
% curl -sI "https://code.jquery.com/jquery-3.5.0.min.js"
HTTP/2 200 
date: Wed, 30 Nov 2022 12:02:51 GMT
content-length: 89493
content-type: application/javascript; charset=utf-8
last-modified: Fri, 20 Aug 2021 17:47:53 GMT
accept-ranges: bytes
server: nginx
etag: W/"611feac9-15d95"
cache-control: max-age=315360000
cache-control: public
access-control-allow-origin: *
vary: Accept-Encoding
x-hw: 1669809771.dop244.fr8.t,1669809771.cds237.fr8.hn,1669809771.cds139.fr8.c

You can pipe it with grep command to just get the size of the response in bytes.

Exmple:
% curl -sI "https://code.jquery.com/jquery-3.5.0.min.js" | grep content-length
content-length: 89493

Note: The way Content-Lenght is displayed in the HTTP response may differ in upper-lowercase, so it's better to make use of case-insensitivity options with grep.

% curl -sI "https://code.jquery.com/jquery-3.5.0.min.js" | grep -iF 'content-length'
content-length: 89493
Get Content Size using cURL Command

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap