MCPcopy Create free account
hub / github.com/encode/starlette / __call__

Method __call__

starlette/middleware/base.py:224–248  ·  view source on GitHub ↗
(self, scope: Scope, receive: Receive, send: Send)

Source from the content-addressed store, hash-verified

222 self.background = None
223
224 async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
225 if self.info is not None:
226 await send({"type": "http.response.debug", "info": self.info})
227 await send(
228 {
229 "type": "http.response.start",
230 "status": self.status_code,
231 "headers": self.raw_headers,
232 }
233 )
234
235 should_close_body = True
236 async for chunk in self.body_iterator:
237 if isinstance(chunk, dict):
238 # We got an ASGI message which is not response body (eg: pathsend)
239 should_close_body = False
240 await send(chunk)
241 continue
242 await send({"type": "http.response.body", "body": chunk, "more_body": True})
243
244 if should_close_body:
245 await send({"type": "http.response.body", "body": b"", "more_body": False})
246
247 if self.background:
248 await self.background()

Callers

nothing calls this directly

Calls 2

backgroundMethod · 0.80
sendFunction · 0.50

Tested by

no test coverage detected