Skip to content

Instantly share code, notes, and snippets.

/output Secret

Created August 24, 2017 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/b2603ec8a7067fc690c031934533171b to your computer and use it in GitHub Desktop.
Save anonymous/b2603ec8a7067fc690c031934533171b to your computer and use it in GitHub Desktop.
Crystal HTTP Request
> crystal --version
Crystal 0.23.1 [e2a1389] (2017-07-13) LLVM 3.8.1
> ./songsearch radiohead
#<HTTP::Client::Response:0x8384ea8>
HTTP::Headers{"Server" => "nginx", "Date" => "Thu, 24 Aug 2017 19:29:09 GMT", "Content-Type" => "text/html", "Content-Length" => "178", "Connection" => "keep-alive", "Location" => "https://www.azlyrics.com/r/radiohead"}
301
Unexpected end of http response (Exception)
0x80c2279: *CallStack::unwind:Array(Pointer(Void)) at ??
0x8188a00: exec_internal at /opt/crystal/src/http/client.cr 498:0
0x81853ca: exec at /opt/crystal/src/http/client.cr 483:5
0x818508b: exec at /opt/crystal/src/http/client.cr 586:5
0x8184864: exec at /opt/crystal/src/http/client.cr 612:7
0x8184598: get at /opt/crystal/src/http/client.cr 329:3
0x818454d: request at /home/**/dev/songsearch/src/songsearch/http.cr 9:5
0x80a5c39: __crystal_main at /home/**/dev/songsearch/src/songsearch.cr 10:1
0x80b8bfd: main at /opt/crystal/src/main.cr 12:15
0xb7371533: __libc_start_main at ??
0x80a51a1: ??? at ??
require "./songsearch/*"
module SongSearch
extend self
end
artist = ARGV[0]
puts SongSearch.request("https://azlyrics.com/#{artist[0]}/#{artist}")
require "http/client"
module SongSearch
def request(url)
resp = HTTP::Client.get(url)
resp = HTTP::Client.get(resp.headers["Location"]) if resp.status_code == 301
resp
end # request
end # SongSearch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment