Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.