Skip to content

Commit

Permalink
Handle x-forwarded-host header (#586)
Browse files Browse the repository at this point in the history
* Handle x-forwarded-host header

* chore: update changelog

---------

Co-authored-by: Pete Gadomski <[email protected]>
  • Loading branch information
renzodf and gadomski authored Sep 13, 2023
1 parent 587e38b commit 0a54bf0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions stac_fastapi/api/stac_fastapi/api/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def _get_forwarded_url_parts(self, scope: Scope) -> Tuple[str]:
# 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:
Expand Down
9 changes: 9 additions & 0 deletions stac_fastapi/api/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"),
],
Expand Down

0 comments on commit 0a54bf0

Please sign in to comment.