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

Method send

starlette/middleware/cors.py:151–172  ·  view source on GitHub ↗
(self, message: Message, send: Send, request_headers: Headers)

Source from the content-addressed store, hash-verified

149 await self.app(scope, receive, send)
150
151 async def send(self, message: Message, send: Send, request_headers: Headers) -> None:
152 if message["type"] != "http.response.start":
153 await send(message)
154 return
155
156 message.setdefault("headers", [])
157 headers = MutableHeaders(scope=message)
158 origin = request_headers.get("Origin")
159 if origin is not None:
160 headers.update(self.simple_headers)
161
162 # If credentials are allowed, then we must respond with the specific origin instead of '*'.
163 if origin is not None and self.allow_all_origins and self.allow_credentials:
164 self.allow_explicit_origin(headers, origin)
165
166 # If we only allow specific origins, then we have to mirror back the Origin header in the response.
167 elif origin is not None and not self.allow_all_origins and self.is_allowed_origin(origin=origin):
168 self.allow_explicit_origin(headers, origin)
169 else:
170 headers["Vary"] = ", ".join([*headers.getlist("Vary"), "Origin"])
171
172 await send(message)
173
174 @staticmethod
175 def allow_explicit_origin(headers: MutableHeaders, origin: str) -> None:

Callers 2

send_no_errorMethod · 0.45
send_with_compressionMethod · 0.45

Calls 8

updateMethod · 0.95
allow_explicit_originMethod · 0.95
is_allowed_originMethod · 0.95
MutableHeadersClass · 0.90
sendFunction · 0.50
setdefaultMethod · 0.45
getMethod · 0.45
getlistMethod · 0.45

Tested by

no test coverage detected