Skip to content

Add x-amz-request-id header to all responses - #20

Merged
krokicki merged 2 commits into
mainfrom
add-x-amz-request-id
Jun 21, 2026
Merged

Add x-amz-request-id header to all responses#20
krokicki merged 2 commits into
mainfrom
add-x-amz-request-id

Conversation

@krokicki

@krokicki krokicki commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

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. 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.pygenerate_request_id() produces an S3-style 16-char uppercase-alphanumeric id via secrets.
  • x2s3/app.pyRequestIdMiddleware, a pure-ASGI middleware that generates one id per request and injects the header on the http.response.start event. Pure ASGI (rather than BaseHTTPMiddleware) is deliberate: it does not re-wrap the response body, so it leaves the app's streaming/cancellation logic in S3Stream and file_iterator untouched. The id is also stashed on scope["state"]["request_id"] for log correlation. x-amz-request-id added to CORS expose_headers so 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

krokicki and others added 2 commits June 21, 2026 13:13
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>
@krokicki
krokicki merged commit 3a98842 into main Jun 21, 2026
5 checks passed
@krokicki
krokicki deleted the add-x-amz-request-id branch June 21, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant