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

Delta Between Two Patch Sets: Lib/httplib.py

Issue 16037: httplib: header parsing is not delimited
Left Patch Set: Created 5 years, 10 months ago
Right Patch Set: Created 4 years, 11 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:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Lib/test/test_httplib.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 r"""HTTP/1.1 client library 1 r"""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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 503: 'Service Unavailable', 207 503: 'Service Unavailable',
208 504: 'Gateway Timeout', 208 504: 'Gateway Timeout',
209 505: 'HTTP Version Not Supported', 209 505: 'HTTP Version Not Supported',
210 } 210 }
211 211
212 # maximal amount of data to read at one time in _safe_read 212 # maximal amount of data to read at one time in _safe_read
213 MAXAMOUNT = 1048576 213 MAXAMOUNT = 1048576
214 214
215 # maximal line length when calling readline(). 215 # maximal line length when calling readline().
216 _MAXLINE = 65536 216 _MAXLINE = 65536
217 _MAXHEADERS = 100
217 218
218 class HTTPMessage(mimetools.Message): 219 class HTTPMessage(mimetools.Message):
219 220
220 def addheader(self, key, value): 221 def addheader(self, key, value):
221 """Add header for field key handling repeats.""" 222 """Add header for field key handling repeats."""
222 prev = self.dict.get(key) 223 prev = self.dict.get(key)
223 if prev is None: 224 if prev is None:
224 self.dict[key] = value 225 self.dict[key] = value
225 else: 226 else:
226 combined = ", ".join((prev, value)) 227 combined = ", ".join((prev, value))
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 self.headers = hlist = [] 265 self.headers = hlist = []
265 self.status = '' 266 self.status = ''
266 headerseen = "" 267 headerseen = ""
267 firstline = 1 268 firstline = 1
268 startofline = unread = tell = None 269 startofline = unread = tell = None
269 if hasattr(self.fp, 'unread'): 270 if hasattr(self.fp, 'unread'):
270 unread = self.fp.unread 271 unread = self.fp.unread
271 elif self.seekable: 272 elif self.seekable:
272 tell = self.fp.tell 273 tell = self.fp.tell
273 while True: 274 while True:
275 if len(hlist) > _MAXHEADERS:
276 raise HTTPException("got more than %d headers" % _MAXHEADERS)
274 if tell: 277 if tell:
275 try: 278 try:
276 startofline = tell() 279 startofline = tell()
277 except IOError: 280 except IOError:
278 startofline = tell = None 281 startofline = tell = None
279 self.seekable = 0 282 self.seekable = 0
280 line = self.fp.readline(_MAXLINE + 1) 283 line = self.fp.readline(_MAXLINE + 1)
281 if len(line) > _MAXLINE: 284 if len(line) > _MAXLINE:
282 raise LineTooLong("header line") 285 raise LineTooLong("header line")
283 if not line: 286 if not line:
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 def readlines(self, size=None): 1358 def readlines(self, size=None):
1356 if self._line_consumed: 1359 if self._line_consumed:
1357 return self._file.readlines(size) 1360 return self._file.readlines(size)
1358 assert self._line_left 1361 assert self._line_left
1359 L = [self._line[self._line_offset:]] 1362 L = [self._line[self._line_offset:]]
1360 self._done() 1363 self._done()
1361 if size is None: 1364 if size is None:
1362 return L + self._file.readlines() 1365 return L + self._file.readlines()
1363 else: 1366 else:
1364 return L + self._file.readlines(size) 1367 return L + self._file.readlines(size)
LEFTRIGHT

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