(self)
| 316 | return version, status, reason |
| 317 | |
| 318 | def begin(self): |
| 319 | if self.headers is not None: |
| 320 | # we've already started reading the response |
| 321 | return |
| 322 | |
| 323 | # read until we get a non-100 response |
| 324 | while True: |
| 325 | version, status, reason = self._read_status() |
| 326 | if status != CONTINUE: |
| 327 | break |
| 328 | # skip the header from the 100 response |
| 329 | skipped_headers = _read_headers(self.fp) |
| 330 | if self.debuglevel > 0: |
| 331 | print("headers:", skipped_headers) |
| 332 | del skipped_headers |
| 333 | |
| 334 | self.code = self.status = status |
| 335 | self.reason = reason.strip() |
| 336 | if version in ("HTTP/1.0", "HTTP/0.9"): |
| 337 | # Some servers might still return "0.9", treat it as 1.0 anyway |
| 338 | self.version = 10 |
| 339 | elif version.startswith("HTTP/1."): |
| 340 | self.version = 11 # use HTTP/1.1 code for HTTP/1.x where x>=1 |
| 341 | else: |
| 342 | raise UnknownProtocol(version) |
| 343 | |
| 344 | self.headers = self.msg = parse_headers(self.fp) |
| 345 | |
| 346 | if self.debuglevel > 0: |
| 347 | for hdr, val in self.headers.items(): |
| 348 | print("header:", hdr + ":", val) |
| 349 | |
| 350 | # are we using the chunked-style of transfer encoding? |
| 351 | tr_enc = self.headers.get("transfer-encoding") |
| 352 | if tr_enc and tr_enc.lower() == "chunked": |
| 353 | self.chunked = True |
| 354 | self.chunk_left = None |
| 355 | else: |
| 356 | self.chunked = False |
| 357 | |
| 358 | # will the connection close at the end of the response? |
| 359 | self.will_close = self._check_close() |
| 360 | |
| 361 | # do we have a Content-Length? |
| 362 | # NOTE: RFC 2616, S4.4, #3 says we ignore this if tr_enc is "chunked" |
| 363 | self.length = None |
| 364 | length = self.headers.get("content-length") |
| 365 | if length and not self.chunked: |
| 366 | try: |
| 367 | self.length = int(length) |
| 368 | except ValueError: |
| 369 | self.length = None |
| 370 | else: |
| 371 | if self.length < 0: # ignore nonsensical negative lengths |
| 372 | self.length = None |
| 373 | else: |
| 374 | self.length = None |
| 375 |
no test coverage detected