Skip to content

Instantly share code, notes, and snippets.

@drldcsta
Last active July 9, 2019 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drldcsta/98f6d7a63554f80faabe2625fad225ed to your computer and use it in GitHub Desktop.
Save drldcsta/98f6d7a63554f80faabe2625fad225ed to your computer and use it in GitHub Desktop.

curl-format

A simple curl formatter wrapped in node for extreme laziness purposes. To run: npx https://gist.github.com/drldcsta/98f6d7a63554f80faabe2625fad225ed <url to test>

Example output:

ddecosta at Darrells-MacBook-Pro in /tmp
$ npx https://gist.github.com/drldcsta/98f6d7a63554f80faabe2625fad225ed https://drl.fyi
npx: installed 1 in 2.115s
23:43:45.031317 * Rebuilt URL to: https://drl.fyi/
[snip]
23:43:45.074939 * Connection state changed (MAX_CONCURRENT_STREAMS updated)!
23:43:45.115445 < HTTP/2 200
23:43:45.115560 < server: GitHub.com
23:43:45.115669 < content-type: text/html; charset=utf-8
23:43:45.115779 < last-modified: Sun, 13 Jan 2019 23:03:46 GMT
23:43:45.115886 < etag: "5c3bc3d2-8dc"
23:43:45.115992 < access-control-allow-origin: *
23:43:45.116094 < expires: Wed, 13 Feb 2019 07:53:45 GMT
23:43:45.116200 < cache-control: max-age=600
23:43:45.116302 < x-github-request-id: 9A82:64F7:A29F9:B4AFE:5C63CAAD
23:43:45.116405 < via: 1.1 varnish
23:43:45.116523 < x-fastly-request-id: b62ba5d911520fa9a56c6a39b59968359bd413c4
23:43:45.116620 < accept-ranges: bytes
23:43:45.116718 < date: Wed, 13 Feb 2019 07:43:45 GMT
23:43:45.116836 < via: 1.1 varnish
23:43:45.116936 < age: 0
23:43:45.117037 < x-served-by: cache-pao17436-PAO, cache-pao17435-PAO
23:43:45.117141 < x-cache: MISS, MISS
23:43:45.117246 < x-cache-hits: 0, 0
23:43:45.117351 < x-timer: S1550043825.096667,VS0,VE39
23:43:45.117454 < vary: Accept-Encoding
23:43:45.117559 < strict-transport-security: max-age=900
23:43:45.117664 < content-length: 2268
23:43:45.117768 <
23:43:45.117896 { [2268 bytes data]
100  2268  100  2268    0     0  26121      0 --:--:-- --:--:-- --:--:-- 26372
23:43:45.118403 * Connection #0 to host drl.fyi left intact

  time_namelookup:    0.006210
  time_connect:       0.010712
  time_appconnect:    0.038523
  time_pretransfer:   0.039305
  time_redirect:      0.000000
  time_starttransfer: 0.084129
                      ----------
  time_total:         0.086825
CSV: 0.006210,0.010712,0.038523,0.039305,0.000000,0.084129,0.086825,"https://drl.fyi/"



  speed_download:     26121.000
  speed_upload:       0.000

  size_download:      2268
  size_header:        679
  size_request:       69
  size_upload:        0

  num_connects:       1
  num_redirects:      0
#!/usr/bin/env node
const child_process = require('child_process');
function runCmd(cmd) {
let resp = child_process.execSync(cmd);
let result = resp.toString('UTF8');
return result;
}
cmd = `curl -w '
time_namelookup: %{time_namelookup}
time_connect: %{time_connect}
time_appconnect: %{time_appconnect}
time_pretransfer: %{time_pretransfer}
time_redirect: %{time_redirect}
time_starttransfer: %{time_starttransfer}
----------
time_total: %{time_total}
CSV: %{time_namelookup},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{time_total},"%{url_effective}"
speed_download: %{speed_download}
speed_upload: %{speed_upload}
size_download: %{size_download}
size_header: %{size_header}
size_request: %{size_request}
size_upload: %{size_upload}
num_connects: %{num_connects}
num_redirects: %{num_redirects}
' ${process.argv[2]} -H "Fastly-debug: 1" --trace-time --no-keepalive --get -v -o /dev/null`
console.log(runCmd(cmd))
{"name": "curl-format", "version": "0.0.0", "bin": "./index.js"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment