MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / send_response

Method send_response

mitmproxy/proxy/layers/http/__init__.py:494–535  ·  view source on GitHub ↗

We have either consumed the entire response from the server or the response was set by an addon.

(self, already_streamed: bool = False)

Source from the content-addressed store, hash-verified

492 yield from self.send_response()
493
494 def send_response(self, already_streamed: bool = False):
495 """We have either consumed the entire response from the server or the response was set by an addon."""
496 assert self.flow.response
497 self.flow.response.timestamp_end = time.time()
498
499 is_websocket = (
500 self.flow.response.status_code == 101
501 and self.flow.response.headers.get("upgrade", "").lower() == "websocket"
502 and self.flow.request.headers.get("Sec-WebSocket-Version", "").encode()
503 == wsproto.handshake.WEBSOCKET_VERSION
504 and self.context.options.websocket
505 )
506 if is_websocket:
507 # We need to set this before calling the response hook
508 # so that addons can determine if a WebSocket connection is following up.
509 self.flow.websocket = WebSocketData()
510
511 yield HttpResponseHook(self.flow)
512 self.server_state = self.state_done
513 if (yield from self.check_killed(False)):
514 return
515
516 if not already_streamed:
517 content = self.flow.response.raw_content
518 done_after_headers = not (content or self.flow.response.trailers)
519 yield SendHttp(
520 ResponseHeaders(self.stream_id, self.flow.response, done_after_headers),
521 self.context.client,
522 )
523 if content:
524 yield SendHttp(
525 ResponseData(self.stream_id, content), self.context.client
526 )
527
528 if self.flow.response.trailers:
529 yield SendHttp(
530 ResponseTrailers(self.stream_id, self.flow.response.trailers),
531 self.context.client,
532 )
533
534 if self.client_state == self.state_done:
535 yield from self.flow_done()
536
537 def flow_done(self) -> layer.CommandGenerator[None]:
538 if not self.flow.websocket:

Calls 10

check_killedMethod · 0.95
flow_doneMethod · 0.95
WebSocketDataClass · 0.90
HttpResponseHookClass · 0.85
SendHttpClass · 0.85
ResponseHeadersClass · 0.85
ResponseTrailersClass · 0.85
ResponseDataClass · 0.70
getMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected