Skip to content

Instantly share code, notes, and snippets.

@akshaymankar
Created August 5, 2013 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akshaymankar/6154786 to your computer and use it in GitHub Desktop.
Save akshaymankar/6154786 to your computer and use it in GitHub Desktop.
Simple http server in ruby. Because you can't install gems everywhere !
require 'socket'
server = TCPServer.open 9000
puts "Listening on port 9000"
loop {
client = server.accept()
while((x = client.gets) != "\r\n")
puts x
end
resp = "Here be dragons"
headers = ["HTTP/1.1 200 OK",
"Date: Tue, 14 Dec 2010 10:48:45 GMT",
"Server: Ruby",
"Content-Type: text/html; charset=iso-8859-1",
"Content-Length: #{resp.length}\r\n\r\n"].join("\r\n")
client.puts headers
client.puts resp
client.close
puts "Request Handled"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment