Repository navigation
Conversation
When a STAC object was read over HTTP and the server redirected, the requested URL became the object's self href, so relative links resolved against the old location. RFC 3986 section 5.1.3 says the base URI is the one the document was actually retrieved from. DefaultStacIO and RetryStacIO now record the final URL of each read, and read_stac_object and STACObject.from_file use it as the self href. urllib3 reports the raw Location header, so it is resolved against the request that was redirected. Closes stac-utils#1816
urllib only follows 308 redirects from Python 3.11 on, so the urllib-backed cases failed on 3.10 before reaching the code under test.
gadomski
self-requested a review
October 5, 2026 13:57
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue(s):
Description:
When a STAC object is read over HTTP and the server redirects, the requested URL became the object's self href, so relative links resolved against the old location. Per RFC 3986 section 5.1.3, the base is the URL the document was actually retrieved from.
DefaultStacIO(urllib and urllib3 paths) andRetryStacIOrecord the final URL of each read via a small_set_final_href/_get_final_hrefpair onStacIO. The entry is cleared when a later read of the same href isn't redirected, so a stale redirect isn't reused.StacIO.read_stac_objectandSTACObject.from_fileuse the final URL as the self href.Locationheader (often relative), so it's resolved against the URL of the request that was redirected, taken from the retry history.Custom
StacIOsubclasses that don't call_set_final_hrefkeep the current behaviour.Tests: a local HTTP server that 308-redirects
/old/to/new/, parametrized over urllib, urllib3 andRetryStacIO, and overCatalog.from_fileandpystac.read_file. The new tests fail on main and pass here.PR Checklist:
pre-commit run --all-files). I ranruff check,ruff format --checkand mypy on the changed files rather than the hooks; mypy reports no new errors.pytest).tests/test_stac_io.py26 passed. The full suite is 1051 passed, 5 skipped, with 20shutil.Errorerrors in asset/item copy tests that fail the same way on main on Windows.AI tool usage: