Created
May 8, 2017 09:44
-
-
Save chrisseaton/2e28c9c5e388d5d957b72b52d56cdb63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### | |
# 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