Created
August 5, 2013 10:01
-
-
Save akshaymankar/6154786 to your computer and use it in GitHub Desktop.
Simple http server in ruby. Because you can't install gems everywhere !
This file contains 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
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