Get size of sent curl request

Is there a way to get the size of a curl request programmatically?

E.g. if I do

curl 'http://www.example.com/url' \
-H 'Cookie: cookie=cookiedata;' \
-H 'X-CSRFToken: csrffake' \
--data 'example=moredata \
--compressed

I want to know how big my sent request is?

Answer

Ok after some man curl digging, I think I’ve found out the answer, though I’m not 100% sure about it’s validity:

 -w, --write-out <format>
     Defines  what  to display on stdout after a completed and successful operation.
     [...]
     The variables present in the output format will be substituted by the
     value or text  that  curl thinks fit, as described below.
     All variables are specified as %{variable_name} and to output a
     normal % you just write them as %%.

     [...]
          size_request   The total amount of bytes
                         that were sent in the HTTP request.

          size_upload    The total amount of bytes that were uploaded.

That means adding a -w '%{size_request} %{size_upload}' and then adding the resulting numbers in the output after the request will give you the request size in total.

Attribution
Source : Link , Question Author : polym , Answer Author : polym

Leave a Comment