Support HEAD requests on all public routes#525
Merged
Conversation
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>
There was a problem hiding this comment.
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
getAndHeadhelper to register both GET and HEAD handlers for a route. - Apply
getAndHeadto core public routes (home, login, posts, tags, search, sitemap).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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>
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.
Summary
curl -Iand crawlers to get 404 responsesgetAndHeadhelper that registers both GET and HEAD handlersTest plan
curl -I https://www.jasonernst.comreturns 200 after deploycurl -I https://www.jasonernst.com/posts/...returns 200🤖 Generated with Claude Code