Skip to content

fix(server): normalize trailing slashes so /health/ returns 200 - #21

Merged
arber-salihi merged 1 commit into
mainfrom
fix-slash-issue
Jun 18, 2026
Merged

fix(server): normalize trailing slashes so /health/ returns 200#21
arber-salihi merged 1 commit into
mainfrom
fix-slash-issue

Conversation

@hibare

@hibare hibare commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds path normalization middleware to strip trailing slashes from request URLs before they reach downstream handlers and middleware. This ensures endpoints like /health/ return 200 instead of 404, and that all path-aware middleware (loggers, telemetry, heartbeat checks) observe a single canonical path.

What Changed

  • Added NormalizePath middleware that strips trailing slashes from r.URL.Path and r.URL.RawPath
  • Middleware performs shallow request cloning when normalization is needed, avoiding mutation of the original request
  • Preserves root path / unchanged
  • Added comprehensive test suite covering normalization behavior, request immutability, and edge cases
  • Integrated middleware into server initialization

Technical Details

Chi's built-in middleware.StripSlashes only modifies the routing context, not the actual URL path. Middleware that reads r.URL.Path directly (structured loggers, OpenTelemetry span formatters, heartbeat checks) continue to see unnormalized paths with trailing slashes. This middleware normalizes the URL at the top of the handler chain so all downstream components see consistent paths.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

@hibare
hibare marked this pull request as ready for review June 18, 2026 07:10

@arber-salihi arber-salihi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me.

@arber-salihi
arber-salihi merged commit c2bc02f into main Jun 18, 2026
2 checks passed
@arber-salihi
arber-salihi deleted the fix-slash-issue branch June 18, 2026 07:50
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.

2 participants