MCPcopy
hub / github.com/aio-libs/aiohttp / send_headers

Method send_headers

aiohttp/protocol.py:645–675  ·  aiohttp/protocol.py::HttpMessage.send_headers

Writes headers to a stream. Constructs payload writer.

(self, _sep=': ', _end='\r\n')

Source from the content-addressed store, hash-verified

643 self.add_header(name, value)
644
645 def send_headers(self, _sep=&class="cm">#x27;: class="st">', _end='\r\n'):
646 class="st">""class="st">"Writes headers to a stream. Constructs payload writer."class="st">""
647 class="cm"># Chunked response is only for HTTP/1.1 clients or newer
648 class="cm"># and there is no Content-Length header is set.
649 class="cm"># Do not use chunked responses when the response is guaranteed to
650 class="cm"># not have a response body (304, 204).
651 assert not self.headers_sent, &class="cm">#x27;headers have been sent already'
652 self.headers_sent = True
653
654 if self.chunked or self.autochunked():
655 self.writer = self._write_chunked_payload()
656 self.headers[hdrs.TRANSFER_ENCODING] = &class="cm">#x27;chunked'
657
658 elif self.length is not None:
659 self.writer = self._write_length_payload(self.length)
660
661 else:
662 self.writer = self._write_eof_payload()
663
664 next(self.writer)
665
666 self._add_default_headers()
667
668 class="cm"># status + headers
669 headers = self.status_line + &class="cm">#x27;'.join(
670 [k + _sep + v + _end for k, v in self.headers.items()])
671 headers = headers.encode(&class="cm">#x27;utf-8class="st">') + b'\r\n'
672
673 self.output_length += len(headers)
674 self.headers_length = len(headers)
675 self.transport.write(headers)
676
677 def _add_default_headers(self):
678 class="cm"># set the connection header

Callers 15

writeMethod · 0.95
_startMethod · 0.80
start_responseMethod · 0.80
sendMethod · 0.80
handle_errorMethod · 0.80
handle_requestMethod · 0.80
handle_requestMethod · 0.80
_responseMethod · 0.80
test_send_headersFunction · 0.80

Calls 7

autochunkedMethod · 0.95
_write_length_payloadMethod · 0.95
_write_eof_payloadMethod · 0.95
_add_default_headersMethod · 0.95
encodeMethod · 0.80
writeMethod · 0.45

Tested by 15

handle_requestMethod · 0.64
_responseMethod · 0.64
test_send_headersFunction · 0.64
test_prepare_lengthFunction · 0.64
test_prepare_eofFunction · 0.64
test_write_payload_eofFunction · 0.64