stac-fastapi.api 4.0.0__tar.gz → 4.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/PKG-INFO +1 -1
  2. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/middleware.py +7 -6
  3. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/version.py +1 -1
  4. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi.api.egg-info/PKG-INFO +1 -1
  5. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/tests/test_middleware.py +14 -0
  6. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/README.md +0 -0
  7. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/setup.cfg +0 -0
  8. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/setup.py +0 -0
  9. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/__init__.py +0 -0
  10. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/app.py +0 -0
  11. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/config.py +0 -0
  12. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/errors.py +0 -0
  13. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/models.py +0 -0
  14. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/openapi.py +0 -0
  15. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi/api/routes.py +0 -0
  16. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi.api.egg-info/SOURCES.txt +0 -0
  17. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi.api.egg-info/dependency_links.txt +0 -0
  18. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi.api.egg-info/not-zip-safe +0 -0
  19. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi.api.egg-info/requires.txt +0 -0
  20. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/stac_fastapi.api.egg-info/top_level.txt +0 -0
  21. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/tests/test_api.py +0 -0
  22. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/tests/test_app.py +0 -0
  23. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/tests/test_app_prefix.py +0 -0
  24. {stac_fastapi_api-4.0.0 → stac_fastapi_api-4.0.1}/tests/test_models.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: stac-fastapi.api
3
- Version: 4.0.0
3
+ Version: 4.0.1
4
4
  Summary: An implementation of STAC API based on the FastAPI framework.
5
5
  Home-page: https://github.com/stac-utils/stac-fastapi
6
6
  Author: Arturo Engineering
@@ -4,7 +4,7 @@ import contextlib
4
4
  import re
5
5
  import typing
6
6
  from http.client import HTTP_PORT, HTTPS_PORT
7
- from typing import List, Tuple
7
+ from typing import List, Optional, Tuple
8
8
 
9
9
  from starlette.middleware.cors import CORSMiddleware as _CORSMiddleware
10
10
  from starlette.types import ASGIApp, Receive, Scope, Send
@@ -95,12 +95,13 @@ class ProxyHeaderMiddleware:
95
95
  domain = header_host_parts[0]
96
96
  port = None
97
97
 
98
+ port_str = None # make sure it is defined in all paths since we access it later
99
+
98
100
  if forwarded := self._get_header_value_by_name(scope, "forwarded"):
99
101
  for proxy in forwarded.split(","):
100
- if (proto_expr := _PROTO_HEADER_REGEX.search(proxy)) and (
101
- host_expr := _HOST_HEADER_REGEX.search(proxy)
102
- ):
102
+ if proto_expr := _PROTO_HEADER_REGEX.search(proxy):
103
103
  proto = proto_expr.group("proto")
104
+ if host_expr := _HOST_HEADER_REGEX.search(proxy):
104
105
  domain = host_expr.group("host")
105
106
  port_str = host_expr.group("port") # None if not present in the match
106
107
 
@@ -115,8 +116,8 @@ class ProxyHeaderMiddleware:
115
116
  return (proto, domain, port)
116
117
 
117
118
  def _get_header_value_by_name(
118
- self, scope: Scope, header_name: str, default_value: str = None
119
- ) -> str:
119
+ self, scope: Scope, header_name: str, default_value: Optional[str] = None
120
+ ) -> Optional[str]:
120
121
  headers = scope["headers"]
121
122
  candidates = [
122
123
  value.decode() for key, value in headers if key.decode() == header_name
@@ -1,3 +1,3 @@
1
1
  """Library version."""
2
2
 
3
- __version__ = "4.0.0"
3
+ __version__ = "4.0.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: stac-fastapi.api
3
- Version: 4.0.0
3
+ Version: 4.0.1
4
4
  Summary: An implementation of STAC API based on the FastAPI framework.
5
5
  Home-page: https://github.com/stac-utils/stac-fastapi
6
6
  Author: Arturo Engineering
@@ -183,6 +183,20 @@ def test_replace_header_value_by_name(
183
183
  },
184
184
  ("https", "test", 1234),
185
185
  ),
186
+ (
187
+ {
188
+ "scheme": "http",
189
+ "server": ["testserver", 80],
190
+ "headers": [
191
+ (
192
+ b"forwarded",
193
+ # proto is set, but no host
194
+ b'for="85.193.181.55";proto=https,for="85.193.181.55";proto=https',
195
+ )
196
+ ],
197
+ },
198
+ ("https", "testserver", 80),
199
+ ),
186
200
  ],
187
201
  )
188
202
  def test_get_forwarded_url_parts(