Skip to content

Fix #83: httpserver HandleGroup should mount both group root and subtree#84

Merged
mishankov merged 2 commits into
mainfrom
issue-83-handle-group-root-and-subtree
Apr 27, 2026
Merged

Fix #83: httpserver HandleGroup should mount both group root and subtree#84
mishankov merged 2 commits into
mainfrom
issue-83-handle-group-root-and-subtree

Conversation

@mishankov
Copy link
Copy Markdown
Member

Closes #83

Summary

httpserver.HandlerGroup.HandleGroup(pattern, handler) previously registered only pattern + "/" and applied http.StripPrefix(pattern, handler). This meant a mounted group did not handle its exact root path unless the caller also registered the same handler with Handle(pattern, handler).

This change updates HandleGroup to mount the group at both:

  • /pattern -> nested handler receives /
  • /pattern/... -> nested handler receives /...

What changed

  • handlergroup.go:

    • HandleGroup now normalizes the mount pattern (trims trailing /) and registers both exact root and slash subtree routes.
    • Added stripPrefix helper that behaves like http.StripPrefix, but maps an empty stripped URL.Path to / so nested groups can naturally register GET / etc.
    • stripPrefix also propagates URL.RawPath for parity with standard library behavior.
  • httpserver_test.go:

    • Added regression test for exact group root routing (/hg -> GET /).
    • Added regression test for subtree routing (/domains/verify -> GET /verify).
    • Added test for trailing-slash pattern normalization (HandleGroup("/hg/", ...) behaves like HandleGroup("/hg", ...)).
    • Added negative test for 404 when prefix does not match.

Testing / validation

  • go test ./httpserver/... — passed
  • task check (lint + race tests) — passed with 0 issues

Code review summary

  • P1 blocker found and fixed: Initial implementation of stripPrefix only rewrote URL.Path but ignored URL.RawPath, creating a behavior regression vs. http.StripPrefix. Fixed by also stripping RawPath when non-empty.
  • P2 gaps addressed: Added tests for trailing-slash pattern normalization and 404 on prefix mismatch.
  • No remaining P0/P1 blockers.

Known limitations / follow-ups

None.

@mishankov mishankov merged commit c16e5f7 into main Apr 27, 2026
8 checks passed
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.

httpserver: HandleGroup should mount both group root and subtree

1 participant