Support X-Forwarded-Host/Path for IIIF URL generation#49
Merged
Conversation
Search API can be served via CloudFront custom domains that rewrite the host and path. EndpointHelpers.Resolve reads both headers once, validates the host against AllowedCustomHosts, extracts the effective job id from X-Forwarded-Path (by stripping the route prefix), and returns a ResolvedRequest(EffectiveId, SelfUrl, BaseUrl). All endpoint call sites collapse to a single Resolve call. TextAugmentedRequest gains an optional UrlId so the handler can use the forwarded id for service descriptor URLs while still loading artefacts by the canonical storage id. X-Forwarded-Proto is handled by ForwardedHeadersMiddleware; trust is restricted via KnownNetworks/KnownProxies config keys so on-prem deployments can pin trusted proxy IPs/CIDRs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The ?q= param was being embedded mid-path in annotation and context IDs because SelfUrl (which includes the query) was used as the base for both the response id and child resource IDs. Adds ResourceUrl (path only, no query) to ResolvedRequest and threads it through SearchRequest, SearchV2Request, and SearchHandlerBase so annotation and context IDs are built from the clean path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds AllowFileImageProxy and AllowedCustomHosts to the configuration table, plus a new section explaining X-Forwarded-Host / X-Forwarded-Path behaviour and the allowlist requirement. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
AllowedCustomHostsconfig - a whitelist of hostnames accepted fromX-Forwarded-Host. When a request carries a matching header, the forwarded host (and job ID extracted fromX-Forwarded-Path) replace the internal values in all generated IIIF self-referencing URLs.?q=query string mid-path - child resource IDs now use the path-only URL, while the responseidstill includes the query string per the IIIF spec.AllowedCustomHosts,AllowFileImageProxy, and the forwarded-header rewriting behaviour indocs/search-api.md.Test plan
idvalues no longer contain?q=- confirmed by three new handler tests (Handle_WithQueryInSelfUrl_*)X-Forwarded-Hostset to a whitelisted host and verify IIIF responseidvalues use the forwarded hostX-Forwarded-Hostfrom a non-whitelisted host is ignoredGenerated with Claude Code