fix: resolve ServeMux conflict between attachments and SMTP message routes#336
Merged
Conversation
…outes
RegisterAttachmentAPI used /api/{module}/{eventUuid}/attachments/{uuid},
which Go 1.22's ServeMux rejects against the newly added SMTP routes at
/api/smtp/message/{uuid}/raw — both are 4-segment patterns and neither
is more specific, so the server panics at boot. Nest the attachment
routes under a literal /attachments segment instead so collisions can't
recur as more module-specific 4-segment paths are added.
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.
What
Server panics at boot with
pattern "GET /api/smtp/{eventUuid}/attachments/{uuid}" ... conflicts with pattern "GET /api/smtp/message/{uuid}/raw". This PR nests the attachment routes under a literal/attachments/segment so they no longer collide with the SMTP module's 4-segment routes.Why
The attachment API was registered as
/api/{module}/{eventUuid}/attachments/{uuid}— wildcard at position 2. After #334 added/api/smtp/message/{uuid}/raw, both 4-segment patterns claim/api/smtp/message/attachments/rawand Go 1.22'sServeMuxrefuses to register them.How
internal/server/http/attachments.go— routes are now/api/{module}/attachments/{eventUuid}[/{uuid}][/preview/{uuid}]. Theattachmentsliteral at position 2 makes them disjoint from any future module-specific route at position 2.modules/httpdumps/handler.go:109— the generated attachment URI follows the new layout.src/shared/lib/io/use-attachments.tsto call the new paths. Both PRs must land together.Testing
internal/server/http/attachments_test.go(new) — registersRegisterAttachmentAPIand the SMTP module on the same mux and asserts no panic. Without the fix this panics at registration.go test ./... -count=1clean;go vet ./...clean.Note
PR #335 is independent and can be rebased on top of this once it lands.