feat: return x-amz-request-id header when serving data links - #392
Merged
Conversation
Bump x2s3 to >=1.3.0,<2. x2s3 1.3.0 (PR #20) adds an S3-style x-amz-request-id header to every response from a standalone x2s3 server via its own RequestIdMiddleware. Fileglancer serves data links through its own FastAPI app using x2s3's FileProxyClient directly, so that middleware never runs for these responses. Carry the feature over with a pure-ASGI RequestIdMiddleware scoped to the /files/ proxy paths (Fileglancer's S3-compatible data-serving surface). It reuses x2s3's generate_request_id() and injects the header on the http.response.start event, so streaming responses are unaffected. The header is added to CORS expose_headers so browser clients (Neuroglancer/N5/Vizarr) can read it. Co-Authored-By: Claude Opus 4.8 (1M context) <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
Bumps x2s3 to
>=1.3.0,<2and carries over the new request-id feature so Fileglancer returns it when serving data links.x2s3 1.3.0 (PR #20) adds an S3-style
x-amz-request-idheader to every response — but only from a standalone x2s3 server, via x2s3's ownRequestIdMiddleware. Fileglancer serves data links through its own FastAPI app using x2s3'sFileProxyClientdirectly, so that middleware never runs for these responses. Bumping the dependency alone would not surface the header.Changes
pyproject.toml—x2s3 >=1.2.0,<2→>=1.3.0,<2(pixi.lockupdated to 1.3.0).fileglancer/server.py— add a pure-ASGIRequestIdMiddlewarescoped to the/files/proxy paths (Fileglancer's S3-compatible data-serving surface). It reuses x2s3'sgenerate_request_id()and injects the header on thehttp.response.startevent, so file-streaming responses are unaffected.x-amz-request-idadded to CORSexpose_headersso browser clients (Neuroglancer/N5/Vizarr) can read it.tests/test_endpoints.py— assert a data-link response carries a well-formed, uniquex-amz-request-id, and that non-/files/endpoints do not.Why scoped to
/files/x-amz-request-idis an S3 semantic; Fileglancer's S3-compatible surface is the/files/{sharing_key}/...proxy. Scoping keeps the header off the regular/api/endpoints while matching real-S3 / x2s3 behavior for data links.Testing
pixi run -e test test-backend— full suite passes (400 tests), including the new header assertions.@StephanPreibisch @JaneliaSciComp/fileglancer