MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / parse_headers

Function parse_headers

tools/python-3.11.9-amd64/Lib/http/client.py:231–243  ·  view source on GitHub ↗

Parses only RFC2822 headers from a file pointer. email Parser 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, for

(fp, _class=HTTPMessage)

Source from the content-addressed store, hash-verified

229 return headers
230
231def parse_headers(fp, _class=HTTPMessage):
232 """Parses only RFC2822 headers from a file pointer.
233
234 email Parser wants to see strings rather than bytes.
235 But a TextIOWrapper around self.rfile would buffer too many bytes
236 from the stream, bytes which we later need to read as bytes.
237 So we read the correct bytes here, as bytes, for email Parser
238 to parse.
239
240 """
241 headers = _read_headers(fp)
242 hstring = b''.join(headers).decode('iso-8859-1')
243 return email.parser.Parser(_class=_class).parsestr(hstring)
244
245
246class HTTPResponse(io.BufferedIOBase):

Callers 1

beginMethod · 0.85

Calls 4

_read_headersFunction · 0.85
decodeMethod · 0.45
joinMethod · 0.45
parsestrMethod · 0.45

Tested by

no test coverage detected