Skip to content

Instantly share code, notes, and snippets.

@frenata
Created May 26, 2018 17:43
Show Gist options
  • Save frenata/9fe6f0cf3c9b0567b4a94667b665bb46 to your computer and use it in GitHub Desktop.
Save frenata/9fe6f0cf3c9b0567b4a94667b665bb46 to your computer and use it in GitHub Desktop.
http headers in coconut
import sys
import requests as req
def get(url) =
outputs |> fmap$(print) where:
result = url |> req.get
status = (result
|> .status_code
|> "Status Code: {}".format$())
headers = (result
|> .headers
|> .items()
|> starmap$((k,v) -> "{}: {}".format(k,v))
|> list
|> sorted)
body = "\n" + result.text$[:500]
outputs = [status] + headers + [body]
def main() = get .. sys.argv[] <| 1
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment