requests
Utility functions for working with HTTP requests.
MatchResult
dataclass
¶
Result of a match between a path and method and a set of endpoints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_private
|
bool
|
|
required |
required_scopes
|
Sequence[str]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
<dynamic>
|
Source code in src/stac_auth_proxy/utils/requests.py
82 83 84 85 86 87 |
|
build_server_timing_header(current_value: Optional[str] = None, *, name: str, desc: str, dur: float)
¶
Append a timing header to headers.
Source code in src/stac_auth_proxy/utils/requests.py
90 91 92 93 94 95 96 97 |
|
dict_to_bytes(d: dict) -> bytes
¶
Convert a dictionary to a body.
Source code in src/stac_auth_proxy/utils/requests.py
29 30 31 |
|
extract_variables(url: str) -> dict
¶
Extract variables from a URL path. Being that we use a catch-all endpoint for the proxy, we can't rely on the path parameters that FastAPI provides.
Source code in src/stac_auth_proxy/utils/requests.py
17 18 19 20 21 22 23 24 25 26 |
|
find_match(path: str, method: str, private_endpoints: EndpointMethods, public_endpoints: EndpointMethods, default_public: bool) -> MatchResult
¶
Check if the given path and method match any of the regex patterns and methods in the endpoints.
Source code in src/stac_auth_proxy/utils/requests.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
get_base_url(request: Request) -> str
¶
Get the request's base URL, accounting for forwarded headers from load balancers/proxies.
This function handles both the standard Forwarded header (RFC 7239) and legacy X-Forwarded-* headers to reconstruct the original client URL when the service is deployed behind load balancers or reverse proxies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
Request
|
The Starlette request object |
required |
Returns:
Type | Description |
---|---|
str
|
The reconstructed client base URL |
Example
With Forwarded header¶
request.headers = {"Forwarded": "for=192.0.2.43; proto=https; host=api.example.com"} get_base_url(request) "api.example.com/"
With X-Forwarded-* headers¶
request.headers = {"X-Forwarded-Host": "api.example.com", "X-Forwarded-Proto": "https"} get_base_url(request) "api.example.com/"
Source code in src/stac_auth_proxy/utils/requests.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
parse_forwarded_header(forwarded_header: str) -> Dict[str, str]
¶
Parse the Forwarded header according to RFC 7239.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forwarded_header
|
str
|
The Forwarded header value |
required |
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dictionary containing parsed forwarded information (proto, host, for, by, etc.) |
Example
parse_forwarded_header("for=192.0.2.43; by=203.0.113.60; proto=https; host=api.example.com")
Source code in src/stac_auth_proxy/utils/requests.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|