nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: stac-utils/stac-fastapi
Pull request #586 (2023-07-05 15:41:53)

Handle x-forwarded-host header
**Related Issue(s):**

- # https://github.com/stac-utils/stac-fastapi/issues/585

**Description:**
See issue
**PR Checklist:**

- [x] `pre-commit` hooks pass locally
- [x] Tests pass (run `make test`)
- [ ] Documentation has been updated to reflect changes, if applicable, and docs build successfully (run `make docs`)
- [x] Changes are added to the [CHANGELOG](https://github.com/stac-utils/stac-fastapi/blob/main/CHANGES.md).



Patch:
diff --git a/CHANGES.md b/CHANGES.md
index bd3ecd3..d4c259a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,6 +2,8 @@
 
 ## [Unreleased]
 
+* Forward `x-forwarded-host` ([#586](https://github.com/stac-utils/stac-fastapi/pull/586))
+
 ## [2.4.8] - 2023-06-07
 
 ### Changed
diff --git a/stac_fastapi/api/stac_fastapi/api/middleware.py b/stac_fastapi/api/stac_fastapi/api/middleware.py
index 84b4e3d..3ed67d6 100644
--- a/stac_fastapi/api/stac_fastapi/api/middleware.py
+++ b/stac_fastapi/api/stac_fastapi/api/middleware.py
@@ -103,6 +103,7 @@ class ProxyHeaderMiddleware:
                             # ignore ports that are not valid integers
                             pass
         else:
+            domain = self._get_header_value_by_name(scope, "x-forwarded-host", domain)
             proto = self._get_header_value_by_name(scope, "x-forwarded-proto", proto)
             port_str = self._get_header_value_by_name(scope, "x-forwarded-port", port)
             try:


Test patch:
diff --git a/stac_fastapi/api/tests/test_middleware.py b/stac_fastapi/api/tests/test_middleware.py
index e3e90be..041dc41 100644
--- a/stac_fastapi/api/tests/test_middleware.py
+++ b/stac_fastapi/api/tests/test_middleware.py
@@ -108,6 +108,14 @@ def test_replace_header_value_by_name(
             },
             ("https", "test", 80),
         ),
+        (
+            {
+                "scheme": "http",
+                "server": ["testserver", 80],
+                "headers": [(b"x-forwarded-host", b"test")],
+            },
+            ("http", "test", 80),
+        ),
         (
             {
                 "scheme": "http",
@@ -138,6 +146,7 @@ def test_replace_header_value_by_name(
                 "server": ["testserver", 80],
                 "headers": [
                     (b"forwarded", b"proto=https;host=test:1234"),
+                    (b"x-forwarded-host", b"another-test"),
                     (b"x-forwarded-port", b"1111"),
                     (b"x-forwarded-proto", b"https"),
                 ],
Repository: stac-utils/stac-fastapi
Pull request #662 (2024-04-18 10:56:09)

fix datetime validator
**Related Issue(s):**

- #

**Description:**

The str_to_interval function is not allowing datetime = None values which is preventing GET /search requests from working if no datetime value is specified. ex. this request would fail: `http://localhost:8080/search?bbox=178,-73,180,-71`

**PR Checklist:**

- [x] `pre-commit` hooks pass locally
- [x] Tests pass (run `make test`)
- [x] Documentation has been updated to reflect changes, if applicable, and docs build successfully (run `make docs`)
- [x] Changes are added to the [CHANGELOG](https://github.com/stac-utils/stac-fastapi/blob/main/CHANGES.md).



Patch:
diff --git a/CHANGES.md b/CHANGES.md
index 6bf2c50..e3a91da 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,6 +2,10 @@
 
 ## [Unreleased]
 
+### Fixed
+
+* BaseSearchGetRequest datetime validator str_to_interval not allowing GET /search requests with datetime = None ([#662](https://github.com/stac-utils/stac-fastapi/pull/662))
+
 ## [2.5.1] - 2024-04-18
 
 ### Fixed
diff --git a/stac_fastapi/types/stac_fastapi/types/rfc3339.py b/stac_fastapi/types/stac_fastapi/types/rfc3339.py
index 43baa8d..b1d4099 100644
--- a/stac_fastapi/types/stac_fastapi/types/rfc3339.py
+++ b/stac_fastapi/types/stac_fastapi/types/rfc3339.py
@@ -45,9 +45,7 @@ def rfc3339_str_to_datetime(s: str) -> datetime:
     return iso8601.parse_date(s)
 
 
-def str_to_interval(
-    interval: str,
-) -> Optional[DateTimeType]:
+def str_to_interval(interval: Optional[str]) -> Optional[DateTimeType]:
     """Extract a tuple of datetimes from an interval string.
 
     Interval strings are defined by
@@ -56,12 +54,19 @@ def str_to_interval(
     or end (but not both) to be open-ended with '..' or ''.
 
     Args:
-        interval (str) : The interval string to convert to a :class:`datetime.datetime`
-        tuple.
+        interval (str or None): The interval string to convert to a tuple of
+        datetime.datetime objects, or None if no datetime is specified.
+
+    Returns:
+        Optional[DateTimeType]: A tuple of datetime.datetime objects or None if
+        input is None.
 
     Raises:
-        ValueError: If the string is not a valid interval string.
+        ValueError: If the string is not a valid interval string and not None.
     """
+    if interval is None:
+        return None
+
     if not interval:
         raise ValueError("Empty interval string is invalid.")
 


Test patch:
diff --git a/stac_fastapi/types/tests/test_rfc3339.py b/stac_fastapi/types/tests/test_rfc3339.py
index 0a40269..23f6242 100644
--- a/stac_fastapi/types/tests/test_rfc3339.py
+++ b/stac_fastapi/types/tests/test_rfc3339.py
@@ -103,3 +103,10 @@ def test_now_functions() -> None:
     assert now1.tzinfo == timezone.utc
 
     rfc3339_str_to_datetime(now_to_rfc3339_str())
+
+
+def test_str_to_interval_with_none():
+    """Test that str_to_interval returns None when provided with None."""
+    assert (
+        str_to_interval(None) is None
+    ), "str_to_interval should return None when input is None"