Add x-amz-request-id header to all responses - #20
Merged
Conversation
Real S3 returns an x-amz-request-id header on every response (GetObject, HeadObject, ListObjectsV2, errors) so clients can reference a specific request when correlating logs or reporting issues. Add an S3-style 16-char uppercase-alphanumeric request id via a pure-ASGI middleware that injects the header on the response start event, which works for streaming responses without buffering the body. Expose the header via CORS. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Real S3 returns an
x-amz-request-idheader on every response (GetObject,HeadObject,ListObjectsV2, errors) so clients can reference a specific request when correlating logs or reporting issues. This adds the same to x2s3.Verified against
s3://janelia-data-examples: the header is a 16-char uppercase-alphanumeric string, unique per request, present on success and error responses alike.Changes
x2s3/utils.py—generate_request_id()produces an S3-style 16-char uppercase-alphanumeric id viasecrets.x2s3/app.py—RequestIdMiddleware, a pure-ASGI middleware that generates one id per request and injects the header on thehttp.response.startevent. Pure ASGI (rather thanBaseHTTPMiddleware) is deliberate: it does not re-wrap the response body, so it leaves the app's streaming/cancellation logic inS3Streamandfile_iteratoruntouched. The id is also stashed onscope["state"]["request_id"]for log correlation.x-amz-request-idadded to CORSexpose_headersso browser clients (Neuroglancer/N5/Vizarr) can read it.tests/test_file.py— assertions that the header is present and well-formed on HTML root, list, HEAD, GET, and 404 responses, plus a uniqueness check.pyproject.toml— version bump to 1.3.0.A single middleware covers all response paths (success, streaming, errors, templates, static), so no per-client changes were needed.
@StephanPreibisch @cmhulbert @bogovicj