Skip to content

fix: set Location header on POST 201 and add WithBaseURL option#198

Merged
q-uint merged 1 commit into
masterfrom
fix/post-location-header
Mar 26, 2026
Merged

fix: set Location header on POST 201 and add WithBaseURL option#198
q-uint merged 1 commit into
masterfrom
fix/post-location-header

Conversation

@q-uint
Copy link
Copy Markdown
Collaborator

@q-uint q-uint commented Mar 26, 2026

resourcePostHandler never set the HTTP Location header on 201 responses, violating RFC 7644 Section 3.3 which states the server SHALL return the resource URI in the Location header.

Additionally, meta.location and Location headers were always relative paths (e.g. "Users/123"). The RFC examples consistently use absolute URIs. Add a WithBaseURL server option that prepends a configurable base URL to all resource locations, enabling RFC-compliant absolute URIs when configured.

Summary

  • Set the HTTP Location header on 201 Created responses in
    resourcePostHandler, as required by RFC 7644 Section 3.3
  • Extract resource location construction into a shared
    resourceLocation() function used by all handlers (GET, PATCH,
    POST, PUT) and list responses
  • Add WithBaseURL server option to produce absolute URIs in both
    meta.location and the Location header (e.g.
    https://example.com/v2/Users/123 instead of Users/123)
  • Without WithBaseURL, behavior is unchanged (relative paths)

resourcePostHandler never set the HTTP Location header on 201
responses, violating RFC 7644 Section 3.3 which states the server
SHALL return the resource URI in the Location header.

Additionally, meta.location and Location headers were always
relative paths (e.g. "Users/123"). The RFC examples consistently
use absolute URIs. Add a WithBaseURL server option that prepends
a configurable base URL to all resource locations, enabling
RFC-compliant absolute URIs when configured.
@q-uint q-uint self-assigned this Mar 26, 2026
@q-uint q-uint merged commit 2da0e0a into master Mar 26, 2026
8 checks passed
@q-uint q-uint deleted the fix/post-location-header branch March 26, 2026 13:05
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