Skip to content

Instantly share code, notes, and snippets.

@colstrom
Last active December 9, 2016 06:46
Show Gist options
  • Select an option

  • Save colstrom/e32efbc4fc7bdf075e552705a890a738 to your computer and use it in GitHub Desktop.

Select an option

Save colstrom/e32efbc4fc7bdf075e552705a890a738 to your computer and use it in GitHub Desktop.
https-get.fish: a minimalist HTTPS client in fish
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
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