MCPcopy Index your code
hub / github.com/google/adk-python / _get_request_origin

Function _get_request_origin

src/google/adk/cli/api_server.py:168–194  ·  view source on GitHub ↗

Compute the effective origin for the current HTTP/WebSocket request.

(scope: dict[str, Any])

Source from the content-addressed store, hash-verified

166
167
168def _get_request_origin(scope: dict[str, Any]) -> Optional[str]:
169 """Compute the effective origin for the current HTTP/WebSocket request."""
170 forwarded = _get_scope_header(scope, b"forwarded")
171 if forwarded is not None:
172 proto = None
173 host = None
174 for element in forwarded.split(",", 1)[0].split(";"):
175 if "=" not in element:
176 continue
177 name, value = element.split("=", 1)
178 if name.strip().lower() == "proto":
179 proto = _strip_optional_quotes(value.strip())
180 elif name.strip().lower() == "host":
181 host = _strip_optional_quotes(value.strip())
182 if proto is not None and host is not None:
183 return f"{_normalize_origin_scheme(proto)}://{host}"
184
185 host = _get_scope_header(scope, b"x-forwarded-host")
186 if host is None:
187 host = _get_scope_header(scope, b"host")
188 if host is None:
189 return None
190
191 proto = _get_scope_header(scope, b"x-forwarded-proto")
192 if proto is None:
193 proto = scope.get("scheme", "http")
194 return f"{_normalize_origin_scheme(proto)}://{host}"
195
196
197def _is_request_origin_allowed(

Callers 1

Calls 6

_get_scope_headerFunction · 0.85
_strip_optional_quotesFunction · 0.85
_normalize_origin_schemeFunction · 0.85
splitMethod · 0.80
stripMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected