A mini web server in ruby
require 'socket'
server = TCPServer.new '127.0.0.1', 8888
while session = server.accept
session.print "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
if request = session.gets
route = request.gsub(/GET\ \//, '').gsub(/\ HTTP.*/, '').chomp
session.print "<h1>You requested a file: #{route}</h1><br />"
for route in route.split('/')
session.print route + "<br />"
end
end
session.close
end
Written by Clayton McIlrath
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#