Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A friendly formatter for curl requests to help with debugging.
\n
============= HOST: ==========\n
\n
local_ip: %{local_ip}\n
local_port: %{local_port}\n
remote_ip: %{remote_ip}\n
remote_port: %{remote_port}\n
\n
======= CONNECTION: ==========\n
\n
http_version: %{http_version}\n
http_code: %{http_code}\n
http_connect: %{http_connect}\n
num_connects: %{num_connects}\n
num_redirects: %{num_redirects}\n
redirect_url: %{redirect_url}\n
\n
============= FILE: ==========\n
\n
content_type: %{content_type}\n
filename_effective: %{filename_effective}\n
ftp_entry_path: %{ftp_entry_path}\n
size_download: %{size_download}\n
size_header: %{size_header}\n
size_request: %{size_request}\n
size_upload: %{size_upload}\n
speed_download: %{speed_download}\n
speed_upload: %{speed_upload}\n
ssl_verify_result: %{ssl_verify_result}\n
url_effective: %{url_effective}\n
\n
=== TIME BREAKDOWN: ==========\n
\n
time_appconnect: %{time_appconnect}\n
time_connect: %{time_connect}\n
time_namelookup: %{time_namelookup}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
\n
@manifestinteractive

This comment has been minimized.

Copy link
Owner Author

commented Aug 17, 2015

Steps to Use:

#1. Make a file named sniff.txt and paste the contents of this gist into it
#2. Make an alias in your .bash_profile or .zshrc ( or whatever you use ) that looks like this ( make sure to source .bash_profile the file afterwards ):

alias sniff='curl -w "@/path/to/sniff.txt" -o /dev/null -O --remote-name --remote-header-name -s'

#3. Now you can use your alias to get some fun data back:

sniff https://api.twitter.com/1.1/search/tweets.json?q=@mrmidi

You will get a response that looks like this:

=============  HOST:  ==========

           local_ip:  192.168.1.28
         local_port:  49364
          remote_ip:  104.244.42.130
        remote_port:  443

=======  CONNECTION:  ==========

       http_version:  1.1
          http_code:  400
       http_connect:  000
       num_connects:  1
      num_redirects:  0
       redirect_url:  

=============  FILE:  ==========

       content_type:  application/json; charset=utf-8
 filename_effective:  /dev/null
     ftp_entry_path:  
      size_download:  62
        size_header:  510
       size_request:  111
        size_upload:  0
     speed_download:  247.000
       speed_upload:  0.000
  ssl_verify_result:  0
      url_effective:  https://api.twitter.com/1.1/search/tweets.json?q=@mrmidi

===  TIME BREAKDOWN:  ==========

    time_appconnect:  0.209910
       time_connect:  0.103317
    time_namelookup:  0.063557
   time_pretransfer:  0.210209
      time_redirect:  0.000000
 time_starttransfer:  0.250681
                      ----------
         time_total:  0.250819
@ssteinerx

This comment has been minimized.

Copy link

commented Jul 1, 2016

Only piece missing is:

"http_version": "%{http_version}",\n

@reitermarkus

This comment has been minimized.

Copy link

commented Aug 3, 2016

Also, filename_effective will always be /dev/null if you don't use -O, --remote-name and --remote-name-header.

@cgoldberg

This comment has been minimized.

Copy link

commented Mar 25, 2017

won't num_redirects always be zero since you don't pass the -L parameter to curl? and if you do use -L, wouldn't that mess up the timings since you then have multiple requests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.