Skip to content

Instantly share code, notes, and snippets.

@burke
Created November 22, 2018 18:54
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 burke/24da0609603e2de13715dd7cc0c6bbaf to your computer and use it in GitHub Desktop.
Save burke/24da0609603e2de13715dd7cc0c6bbaf to your computer and use it in GitHub Desktop.
ctx = OpenSSL::SSL::SSLContext.new
ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER)
raw_sock = TCPSocket.new(host, 443)
ssl_sock = OpenSSL::SSL::SSLSocket.new(raw_sock, ctx)
ssl_sock.hostname = host
ssl_sock.sync_close = true
ssl_sock.connect
req = Net::HTTP::Head.new(url)
req['Host'] = host
req['Authorization'] = "Bearer #{token}"
req['Connection'] = 'close'
req.exec(ssl_sock, '1.0', req.path)
proc do
resp = Net::HTTPResponse.read_new(Net::BufferedIO.new(ssl_sock))
ssl_sock.close
if resp.code.to_i != 302
raise(OperationFailed, "wanted #{code}, got #{resp.code}") unless resp.code.to_i == code
end
URI.parse(resp['Location'])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment