Last active
December 9, 2016 06:46
-
-
Save colstrom/e32efbc4fc7bdf075e552705a890a738 to your computer and use it in GitHub Desktop.
https-get.fish: a minimalist HTTPS client in fish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name = https-get | |
| author = Chris Olstrom | |
| license = MIT | |
| provides = fish/functions/https-get | |
| requires | |
| command/cat | |
| command/mktemp | |
| command/ncat | |
| command/rm | |
| fish/builtin/and | |
| fish/builtin/case | |
| fish/builtin/count | |
| fish/builtin/echo | |
| fish/builtin/end | |
| fish/builtin/function | |
| fish/builtin/return | |
| fish/builtin/set | |
| fish/builtin/switch | |
| fish/functions/lines-after | |
| fish/functions/lines-before |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function https-get --argument host path | |
| switch (count $argv) | |
| case 0 | |
| echo "usage: https-get <host> <path>" | |
| return 100 | |
| case '*' | |
| set buffer (mktemp) | |
| set protocol "HTTP/1.1" | |
| set agent "fish $FISH_VERSION (what do you even do with this header?)" | |
| set request "GET $path $protocol\r\nHost: $host\r\nUser-Agent: $agent\r\nConnection: close\r\n" | |
| echo -e $request | ncat --ssl $host 443 > $buffer | |
| set --query VERBOSE | |
| and cat $buffer | lines-before '^\r$' >&2 | |
| cat $buffer | lines-after '^\r$' | |
| rm $buffer | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment