diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2007-08-10 18:49:32 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2007-08-10 18:49:32 (GMT) |
commit | 7ffe2998cdc5bb78a5301d3a2a137042b1cf088e (patch) | |
tree | 892644304c9f82496399a0d1c97ef5e80ff148c9 | |
parent | 4b878bd3d55613a3d31216ef5d8c1cffb681b7ab (diff) | |
download | cpython-7ffe2998cdc5bb78a5301d3a2a137042b1cf088e.zip cpython-7ffe2998cdc5bb78a5301d3a2a137042b1cf088e.tar.gz cpython-7ffe2998cdc5bb78a5301d3a2a137042b1cf088e.tar.bz2 |
Allow rfc822 to process headers from an incoming HTTP request.
-rw-r--r-- | Lib/BaseHTTPServer.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/BaseHTTPServer.py b/Lib/BaseHTTPServer.py index 699b359..1ba0ac7 100644 --- a/Lib/BaseHTTPServer.py +++ b/Lib/BaseHTTPServer.py @@ -70,6 +70,7 @@ __version__ = "0.3" __all__ = ["HTTPServer", "BaseHTTPRequestHandler"] +import io import sys import time import socket # For gethostbyaddr() @@ -278,7 +279,13 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler): self.command, self.path, self.request_version = command, path, version # Examine the headers and look for a Connection directive - self.headers = self.MessageClass(self.rfile, 0) + # MessageClass == rfc822 expects ascii, so use a text wrapper. + text = io.TextIOWrapper(self.rfile) + self.headers = self.MessageClass(text, 0) + # The text wrapper does buffering (as does self.rfile). We + # don't want to leave any data in the buffer of the text + # wrapper. + assert not text.buffer.peek() conntype = self.headers.get('Connection', "") if conntype.lower() == 'close': |