I wrote a quick script, ReadURL, which uses sockets (instead of urllib) to
read a URL so I could see a raw response with no interpretation. As
discussed earlier on the Webware list, web servers that get a request for:
http://host/somedirectory Send back a redirect for:
http://host/somedirectory/ in order that relative URLs in the resulting
page will work correctly when the user clicks on them. In order to test
this, I created a directory foo/ on my local machine and requested
http://localhost/foo. What I got was this: #--begin >python ReadURL.py
Sending request: GET /foo... Sent. Reading response... Read 291 bytes. Read
0 bytes. Read. Contents:
The document has moved <http://localhost/foo/>here.
Apache/1.3.12 Server at localhost Port 80 Done. #--end The "Contents:"
part is everything that I get from the socket and as far as HTML goes, it
looks like what I would expect Apache to return. However, I also expected
some kind of HTTP headers right before it like: Status: 301 Redirect:
http://localhost/foo/ However, I don't see this. Anyone know what code or
concept I'm missing here? My program is playing the part of the browser,
but I don't see how it's supposed to know the HTTP status code or anything
else. I also get the same results with telnet. I'm using Apache 1.3.x on
Windows. If it helps, here's an excerpt of the code. I'll send the whole
thing if need be. s = socket(AF_INET, SOCK_STREAM) s.connect(host, port)
request = 'GET /foo' print 'Sending request: %s...' % request
s.send(request+'\r\n\r\n') print 'Sent.' s.shutdown(1) # read the raw
reponse (which is a marshalled dictionary) print 'Reading response...'
response = '' while 1: chunk = s.recv(bufsize) print 'Read %d bytes.' %
len(chunk) if not chunk: break response = response + chunk print 'Read.'