Created
November 22, 2018 18:54
-
-
Save burke/24da0609603e2de13715dd7cc0c6bbaf to your computer and use it in GitHub Desktop.
This file contains 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
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