On a side note, Webrick is a quick way to add a HTP server to a some code
http://www.notwork.org/ipr/webrick/
···
-----Original Message-----
From: Michael Hale [mailto:mhale@rolemodelsoft.com]
Sent: Thursday, September 19, 2002 9:13 AM
To: ruby-talk@ruby-lang.org
Subject: How should I print the http request?
I am trying to implement a simple http server for debugging purposes.
The problem I am having is when I try to do something simple to print
out the request like:
p session.readlines
My code hangs apparently waiting for more lines to be sent.
The code below shows how I currently print the request but I would
really prefer something that does not depend on timing. Any
suggestions?
require ‘socket’
server = TCPServer.new(‘localhost’, 8090)
while (session = server.accept)
body = "<html><body>you are not authorized to view this page.
#1\r\n"
headers = {}
headers["Content-type"]= "text/html"
headers["Connection"]= "close"
headers["WWW-Authenticate"]= "NTLM"
headers["Server"]= "Microsoft-IIS/5.1"
headers["Content-length"]= "#{body.length}"
session.puts "HTTP/1.1 401 Access Denied\r\n"
headers.each {|key, value| session.puts "#{key}: #{value}\r\n"}
session.puts "\r\n"
session.puts body
########Printing the request#########
begin
thread = Thread.new {
session.each {|line| p line}
}
sleep .1
thread.kill
rescue Exception
end
#####################################
session.close
end
Michael Hale - Software Developer
RoleModel Software Inc. - The XP Software Studio
www.rolemodelsoftware.com