Created
November 17, 2010 22:04
-
-
Save cvonkleist/704188 to your computer and use it in GitHub Desktop.
forking retarded web server
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
require 'socket' | |
listener = TCPServer.new(8888) | |
loop do | |
puts 'waiting for connection...' | |
sock = listener.accept | |
fork do | |
puts 'i am child' | |
filename = sock.gets.split[1] | |
begin | |
sock.puts 'HTTP/1.0 200 OK', File.read(filename) | |
rescue | |
sock.puts 'HTTP/1.0 404 OH SNAP', '', 'WHERE IZ FILEZ?' | |
end | |
puts 'child done' | |
exit 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment