Skip to content

Support HEAD requests on all public routes#525

Merged
compscidr merged 2 commits intomainfrom
fix/head-request-support
Mar 19, 2026
Merged

Support HEAD requests on all public routes#525
compscidr merged 2 commits intomainfrom
fix/head-request-support

Conversation

@compscidr
Copy link
Collaborator

Summary

  • Gin does not automatically handle HEAD for GET routes, causing curl -I and crawlers to get 404 responses
  • Add getAndHead helper that registers both GET and HEAD handlers
  • Apply to all public-facing routes: home, posts, tags, search, sitemap, login

Test plan

  • All existing tests pass
  • curl -I https://www.jasonernst.com returns 200 after deploy
  • curl -I https://www.jasonernst.com/posts/... returns 200

🤖 Generated with Claude Code

Gin does not automatically handle HEAD for GET routes. Add a getAndHead
helper that registers both methods, and use it for all public-facing
routes (home, posts, tags, search, sitemap). Fixes curl -I and similar
tools returning 404 instead of 200.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 19, 2026 17:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds explicit HEAD handling alongside GET for public-facing endpoints so curl -I and crawlers no longer receive 404s when probing resources.

Changes:

  • Introduce a getAndHead helper to register both GET and HEAD handlers for a route.
  • Apply getAndHead to core public routes (home, login, posts, tags, search, sitemap).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Replace handlersRegistered bool with sync.Once for thread-safe route
  registration, preventing potential race when concurrent GET and HEAD
  requests trigger addRoutes simultaneously
- Change goblog methods to pointer receivers so sync.Once state persists
- Accept gin.IRoutes instead of *gin.Engine in getAndHead for reuse
  with router groups

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@compscidr compscidr merged commit b29b495 into main Mar 19, 2026
1 check passed
@compscidr compscidr deleted the fix/head-request-support branch March 19, 2026 18:14
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