Debug request and response headers using curl

0
5986
Debug request and response headers using curl

Just another nice tip using curl. I will show you how to debug request and response headers using curl utility.

Debug request and response headers using curl

To see the detail of the request and response, we use -v option to print out result in verbose mode when issuing curl request.

$ curl -v https://petehouston.com

* Rebuilt URL to: https://petehouston.com/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 128.199.103.243...
* TCP_NODELAY set
* Connected to petehouston.com (128.199.103.243) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: E:/program_files/Git/mingw64/ssl/certs/ca-bundle.crt
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [107 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [2579 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [365 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [102 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=petehouston.com
*  start date: Feb 16 16:09:43 2019 GMT
*  expire date: May 17 16:09:43 2019 GMT
*  subjectAltName: host "petehouston.com" matched cert's "petehouston.com"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]
* Using Stream ID: 1 (easy handle 0x2049120)
} [5 bytes data]
> GET / HTTP/2
> Host: petehouston.com
> User-Agent: curl/7.61.1
> Accept: */*
>
{ [5 bytes data]
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
} [5 bytes data]
< HTTP/2 200
< server: nginx/1.10.0 (Ubuntu)
< date: Wed, 27 Mar 2019 06:19:01 GMT
< content-type: text/html
< content-length: 3538
< last-modified: Fri, 24 Nov 2017 11:25:11 GMT
< vary: Accept-Encoding
< etag: "5a180197-dd2"
< x-content-type-options: nosniff
< accept-ranges: bytes
<
{ [3538 bytes data]

The downloading progress bar looks quite annoying, we can remove it with -s option.

$ curl -sv https://petehouston.com

It looks better, but since we don’t have interest in response body, we should opt it out, which can be done by redirecting response body to /dev/null

$ curl -sv https://petehouston.com 1> /dev/null
....<omitted>
> GET / HTTP/2
> Host: petehouston.com
> User-Agent: curl/7.61.1
> Accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 200
< server: nginx/1.10.0 (Ubuntu)
< date: Wed, 27 Mar 2019 06:22:46 GMT
< content-type: text/html
< content-length: 3538
< last-modified: Fri, 24 Nov 2017 11:25:11 GMT
< vary: Accept-Encoding
< etag: "5a180197-dd2"
< x-content-type-options: nosniff
< accept-ranges: bytes
<
* Connection #0 to host petehouston.com left intact

When you have problems with making requests, it is very helpful to debug response headers using curl.