Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
HTTP CONNECT by example
require 'socket'
listen_socket ='', 9292)
client_conn = listen_socket.accept
request_line = client_conn.gets
while(line = client_conn.gets) do
break unless line.include?(':')
host, port = *request_line.split[1].split(':')
dest_conn =, port)
client_conn.write "HTTP/1.1 200 OK\r\n"
def transfer(src_conn, dest_conn)
IO.copy_stream(src_conn, dest_conn)
rescue => e
puts e.message
[ { transfer(client_conn, dest_conn) }, { transfer(dest_conn, client_conn) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment