Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(69957)

Side by Side Diff: Lib/http/client.py

Issue 16037: httplib: header parsing is not delimited
Patch Set: Created 5 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_httplib.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """HTTP/1.1 client library 1 """HTTP/1.1 client library
2 2
3 <intro stuff goes here> 3 <intro stuff goes here>
4 <other stuff, too> 4 <other stuff, too>
5 5
6 HTTPConnection goes through a number of "states", which define when a client 6 HTTPConnection goes through a number of "states", which define when a client
7 may legally make another request or fetch the response for a particular 7 may legally make another request or fetch the response for a particular
8 request. This diagram details these state transitions: 8 request. This diagram details these state transitions:
9 9
10 (null) 10 (null)
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 503: 'Service Unavailable', 199 503: 'Service Unavailable',
200 504: 'Gateway Timeout', 200 504: 'Gateway Timeout',
201 505: 'HTTP Version Not Supported', 201 505: 'HTTP Version Not Supported',
202 } 202 }
203 203
204 # maximal amount of data to read at one time in _safe_read 204 # maximal amount of data to read at one time in _safe_read
205 MAXAMOUNT = 1048576 205 MAXAMOUNT = 1048576
206 206
207 # maximal line length when calling readline(). 207 # maximal line length when calling readline().
208 _MAXLINE = 65536 208 _MAXLINE = 65536
209 _MAXHEADERS = 100
210
209 211
210 class HTTPMessage(email.message.Message): 212 class HTTPMessage(email.message.Message):
211 # XXX The only usage of this method is in 213 # XXX The only usage of this method is in
212 # http.server.CGIHTTPRequestHandler. Maybe move the code there so 214 # http.server.CGIHTTPRequestHandler. Maybe move the code there so
213 # that it doesn't need to be part of the public API. The API has 215 # that it doesn't need to be part of the public API. The API has
214 # never been defined so this could cause backwards compatibility 216 # never been defined so this could cause backwards compatibility
215 # issues. 217 # issues.
216 218
217 def getallmatchingheaders(self, name): 219 def getallmatchingheaders(self, name):
218 """Find all header lines matching a given header name. 220 """Find all header lines matching a given header name.
(...skipping 27 matching lines...) Expand all
246 So we read the correct bytes here, as bytes, for email Parser 248 So we read the correct bytes here, as bytes, for email Parser
247 to parse. 249 to parse.
248 250
249 """ 251 """
250 headers = [] 252 headers = []
251 while True: 253 while True:
252 line = fp.readline(_MAXLINE + 1) 254 line = fp.readline(_MAXLINE + 1)
253 if len(line) > _MAXLINE: 255 if len(line) > _MAXLINE:
254 raise LineTooLong("header line") 256 raise LineTooLong("header line")
255 headers.append(line) 257 headers.append(line)
258 if len(headers) > _MAXHEADERS:
259 raise TooManyHeaders()
256 if line in (b'\r\n', b'\n', b''): 260 if line in (b'\r\n', b'\n', b''):
257 break 261 break
258 hstring = b''.join(headers).decode('iso-8859-1') 262 hstring = b''.join(headers).decode('iso-8859-1')
259 return email.parser.Parser(_class=_class).parsestr(hstring) 263 return email.parser.Parser(_class=_class).parsestr(hstring)
260 264
261 265
262 _strict_sentinel = object() 266 _strict_sentinel = object()
263 267
264 class HTTPResponse(io.RawIOBase): 268 class HTTPResponse(io.RawIOBase):
265 269
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 if not line: 1189 if not line:
1186 line = repr(line) 1190 line = repr(line)
1187 self.args = line, 1191 self.args = line,
1188 self.line = line 1192 self.line = line
1189 1193
1190 class LineTooLong(HTTPException): 1194 class LineTooLong(HTTPException):
1191 def __init__(self, line_type): 1195 def __init__(self, line_type):
1192 HTTPException.__init__(self, "got more than %d bytes when reading %s" 1196 HTTPException.__init__(self, "got more than %d bytes when reading %s"
1193 % (_MAXLINE, line_type)) 1197 % (_MAXLINE, line_type))
1194 1198
1199
1200 class TooManyHeaders(HTTPException):
berkerpeksag 2013/10/24 22:23:22 For 3.4, this should be documented in http://docs.
1201 def __init__(self):
1202 HTTPException.__init__(self, "got more than %d headers" % _MAXHEADERS)
1203
1195 # for backwards compatibility 1204 # for backwards compatibility
1196 error = HTTPException 1205 error = HTTPException
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_httplib.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+