Skip to content

Instantly share code, notes, and snippets.

@andresvia
Last active July 5, 2016 17:05
Show Gist options
  • Save andresvia/da0b1505b8e883a1fa5ebf65171ddcc1 to your computer and use it in GitHub Desktop.
Save andresvia/da0b1505b8e883a1fa5ebf65171ddcc1 to your computer and use it in GitHub Desktop.
#!/bin/bash
# this is only suited for text files
set -eu
url="$1"
scheme="${url/:\/\/*}"
if [ "$scheme" != "https" ]
then
echo oops... only https:// is supported
exit 1
fi
no_scheme="${url#$scheme://}"
host_port="${no_scheme/\/*/}"
host=${host_port/:*}
port=${host_port#$host}
path="${no_scheme#$host_port}"
connect_to="${host}${port:-:443}"
get="${path:-/}"
openssl s_client -quiet -connect "${connect_to}" << EOF | tr -d '\r' | sed '1,/^$/d'
GET ${get} HTTP/1.1
Host: ${host_port}
User-Agent: opensslget
Connection: close
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment