diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2009-03-27 17:14:18 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2009-03-27 17:14:18 (GMT) |
commit | e6fdd04b37ff4a49b36cb2d1f0963b4062e8ccb3 (patch) | |
tree | e7291b29d8f1395eea497def307bcea58529e9a4 | |
parent | ef9f48e578a14c91fb101a4fbe73e5c3d400dcbf (diff) | |
download | cpython-e6fdd04b37ff4a49b36cb2d1f0963b4062e8ccb3.zip cpython-e6fdd04b37ff4a49b36cb2d1f0963b4062e8ccb3.tar.gz cpython-e6fdd04b37ff4a49b36cb2d1f0963b4062e8ccb3.tar.bz2 |
Replace duplicate code in http.server with call to http.client.parse_headers().
-rw-r--r-- | Lib/http/client.py | 2 | ||||
-rw-r--r-- | Lib/http/server.py | 17 |
2 files changed, 2 insertions, 17 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py index 0477ddd..1fe010c 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -237,8 +237,6 @@ def parse_headers(fp): to parse. """ - # XXX: Copied from http.server.BaseHTTPRequestHandler.parse_request, - # maybe we can just call this function from there. headers = [] while True: line = fp.readline() diff --git a/Lib/http/server.py b/Lib/http/server.py index 5726017..59d92db 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -88,6 +88,7 @@ import io import os import sys import cgi +import http.client import time import socket # For gethostbyaddr() import shutil @@ -312,20 +313,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler): self.command, self.path, self.request_version = command, path, version # Examine the headers and look for a Connection directive. - - # MessageClass wants to see strings rather than bytes. - # But a TextIOWrapper around self.rfile would buffer too many bytes - # from the stream, bytes which we later need to read as bytes. - # So we read the correct bytes here, as bytes, then use StringIO - # to make them look like strings for MessageClass to parse. - headers = [] - while True: - line = self.rfile.readline() - headers.append(line) - if line in (b'\r\n', b'\n', b''): - break - hfile = io.StringIO(b''.join(headers).decode('iso-8859-1')) - self.headers = email.parser.Parser(_class=self.MessageClass).parse(hfile) + self.headers = http.client.parse_headers(self.rfile) conntype = self.headers.get('Connection', "") if conntype.lower() == 'close': @@ -524,7 +512,6 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler): protocol_version = "HTTP/1.0" # MessageClass used to parse headers - import http.client MessageClass = http.client.HTTPMessage # Table mapping response codes to messages; entries have the |