Skip to content

Instantly share code, notes, and snippets.

@chrisseaton
Created May 8, 2017 09:44
Show Gist options
  • Save chrisseaton/2e28c9c5e388d5d957b72b52d56cdb63 to your computer and use it in GitHub Desktop.
Save chrisseaton/2e28c9c5e388d5d957b72b52d56cdb63 to your computer and use it in GitHub Desktop.
###
# Usage:
#
# $ ruby this_script.rb
# $ ruby this_script.rb https://tenderlovemaking.com
# jt run --sulong -Xpatching=false ../openssl-raw.rb
require 'openssl'
require 'socket'
require 'uri'
def get_headers sock
headers = {}
while (line = sock.readline) && line != "\r\n"
k, v = line.chomp.split(": ")
headers[k] = v
end
headers
end
uri = URI.parse(ARGV[0] || 'https://rubygems.org')
host = uri.host
path = uri.path.empty? ? "/" : uri.path
ctx = OpenSSL::SSL::SSLContext.new
tcp = TCPSocket.new uri.host, 443
ssl_client = OpenSSL::SSL::SSLSocket.new tcp, ctx
ssl_client.connect
ssl_client.write "GET #{path} HTTP/1.1\r\nHost: #{host}\r\n\r\n"
headers = get_headers(ssl_client)
p headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment