This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author joru
Recipients docs@python, georg.brandl, joru
Date 2013-10-06.15:39:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1381073989.11.0.419670748927.issue18229@psf.upfronthosting.co.za>
In-reply-to
Content
#minimal server:
#!/c/Python33/python.exe
from http.server import HTTPServer as S, BaseHTTPRequestHandler as H
class HNDL(H):
	def log_request(req,code):
		print('header is',req.headers.get('X-Forwarder-For'),', code',code)
		H.log_request(req)
s=S(('',54321),HNDL)
s.serve_forever()


#non-http client:
#!/c/Python33/python.exe
import socket,os
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 54321))
s.sendall(os.urandom(1024))
buf=s.recv(2048)
s.close()
print(buf)


#running server:
$ ./server.py
127.0.0.1 - - [06/Oct/2013 17:33:41] code 400, message Bad HTTP/0.9 request type
 ('E)\xaeE^2¤\xf2W\x8f\xb3aG')
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 18234)
Traceback (most recent call last):
  File "c:\Python33\lib\socketserver.py", line 306, in _handle_request_noblock
    self.process_request(request, client_address)
  File "c:\Python33\lib\socketserver.py", line 332, in process_request
    self.finish_request(request, client_address)
  File "c:\Python33\lib\socketserver.py", line 345, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\Python33\lib\socketserver.py", line 666, in __init__
    self.handle()
  File "c:\Python33\lib\http\server.py", line 400, in handle
    self.handle_one_request()
  File "c:\Python33\lib\http\server.py", line 380, in handle_one_request
    if not self.parse_request():
  File "c:\Python33\lib\http\server.py", line 311, in parse_request
    "Bad HTTP/0.9 request type (%r)" % command)
  File "c:\Python33\lib\http\server.py", line 428, in send_error
    self.send_response(code, message)
  File "c:\Python33\lib\http\server.py", line 443, in send_response
    self.log_request(code)
  File "./server.py", line 5, in log_request
    print('header is',req.headers.get('X-Forwarder-For'),', code',code)
AttributeError: 'HNDL' object has no attribute 'headers'
----------------------------------------


#running client:
$ ./client.py
b''
$
History
Date User Action Args
2013-10-06 15:39:49jorusetrecipients: + joru, georg.brandl, docs@python
2013-10-06 15:39:49jorusetmessageid: <1381073989.11.0.419670748927.issue18229@psf.upfronthosting.co.za>
2013-10-06 15:39:49jorulinkissue18229 messages
2013-10-06 15:39:48jorucreate