Skip to content

Instantly share code, notes, and snippets.

@johnboxall
Created May 14, 2019 19:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnboxall/f7e1449e5d442b030e1114ae0ec73d9d to your computer and use it in GitHub Desktop.
Save johnboxall/f7e1449e5d442b030e1114ae0ec73d9d to your computer and use it in GitHub Desktop.
cURL Bash Aliases
# Print the headers of URL.
alias curl-headers='curl ${CURL_ARGS[@]} --dump-header -'
# Print Time to First Byte of URL.
alias curl-ttfb='curl ${CURL_ARGS[@]} --write-out "%{time_starttransfer}\n"'
# Print bytes file size of URL.
alias curl-size='curl ${CURL_ARGS[@]} --write-out "%{size_download}\n"'
# https://ec.haxx.se/usingcurl-writeout.html
alias curl-timing='curl ${CURL_ARGS[@]} --write-out "
namelookup: %{time_namelookup} Start to name resolving
connect: %{time_connect} Start to TCP connect to host
appconnect: %{time_appconnect} Start to TLS
pretransfer: %{time_pretransfer} Start to file transfer is about to begin
redirect: %{time_redirect}
starttransfer: %{time_starttransfer} Start to first byte
----------
total: %{time_total}
"'
# Test with:
# curl -H "Origin: http://example.com" \
# -H "Access-Control-Request-Method: POST" \
# -H "Access-Control-Request-Headers: X-Requested-With" \
# -X OPTIONS --verbose \
# https://www.googleapis.com/discovery/v1/apis?fields=
# Simple API that allows this stuff.
# https://jsonplaceholder.typicode.com/todos/1
alias curl-cors='curl ${CURL_ARGS[@]} --dump-header - -H "Origin: http://example.com"'
curl-diff() {
diff \
<(curl --silent "$1") \
<(curl --silent "$2")
}
# Display a poor diff between two HTTP headers: https://www.computerhope.com/unix/udiff.htm
# Inspired by: https://twitter.com/bagder/status/1128041424291803143
curl-diff-headers () {
ARGS=(
--silent
--output /dev/null
--dump-header -
)
diff -y \
<(curl ${ARGS[@]} "$1" | sort) \
<(curl ${ARGS[@]} "$2" | sort)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment