Use header constants across the handler package - #301
Merged
Conversation
goconst tripped on main after #259 landed on top of #280: five composite-literal occurrences each of "Content-Length" and "Content-Type" across container.go, container_manifest.go, container_tags.go, handler.go, and swift.go crossed the min-occurrences: 5 threshold. Neither PR hit it alone. Add headerContentType and headerContentLength beside headerAcceptEncoding and use them throughout the package rather than only at the flagged sites, so the next handler that adds one does not re-trip the check.
There was a problem hiding this comment.
🟢 Approval recommended
The changes are a mechanical, package-local refactor to shared header-name constants with no functional behavior changes observed.
Pull request overview
This PR standardizes HTTP header key usage across the internal/handler package by introducing shared constants for Content-Type and Content-Length, preventing goconst from flagging repeated header strings and reducing future duplication.
Changes:
- Added
headerContentTypeandheaderContentLengthconstants alongside the existingheaderAcceptEncoding. - Replaced
Content-Type/Content-Lengthstring literals with the new constants across handler implementations. - Updated header-copying/header-proxying loops to use the constants for consistent header key handling.
File summaries
| File | Description |
|---|---|
| internal/handler/handler.go | Defines headerContentType / headerContentLength and uses them in shared handler utilities. |
| internal/handler/container.go | Switches container blob response header setting/copying to constants. |
| internal/handler/container_manifest.go | Uses constants when reading/writing/copying manifest Content-* headers. |
| internal/handler/container_tags.go | Uses constants for cached tag list Content-* metadata and header copying. |
| internal/handler/swift.go | Uses constants for Swift archive/metadata/problem responses and header copying. |
| internal/handler/rpm.go | Uses headerContentType for RPM download responses. |
| internal/handler/pypi.go | Uses headerContentType when serving rewritten HTML/JSON responses. |
| internal/handler/pub.go | Uses headerContentType when serving proxied/rewritten JSON metadata. |
| internal/handler/nuget.go | Uses headerContentType when serving proxied/rewritten JSON responses. |
| internal/handler/npm.go | Uses headerContentType when serving proxied/rewritten package metadata. |
| internal/handler/hex.go | Uses headerContentType for passthrough and rewritten hex package responses. |
| internal/handler/helm.go | Uses headerContentType when defaulting chart content type. |
| internal/handler/gradle.go | Uses constants for Gradle build-cache Content-Type and Content-Length responses. |
| internal/handler/gem.go | Uses headerContentLength in case-insensitive header filtering logic. |
| internal/handler/debian.go | Uses headerContentType for Debian package download responses. |
| internal/handler/conda.go | Uses headerContentType for proxied/rewritten JSON responses. |
| internal/handler/composer.go | Uses headerContentType for Composer JSON responses. |
| internal/handler/cargo.go | Uses headerContentType for Cargo config/index responses. |
Review details
- Files reviewed: 18/18 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
goconsttripped on main after #259 landed on top of #280: five composite-literal occurrences each of"Content-Length"and"Content-Type"acrosscontainer.go,container_manifest.go,container_tags.go,handler.go, andswift.gocrossed themin-occurrences: 5threshold. Neither PR hit it alone; the CIlintjob on #259's rebased head failed but auto-merge proceeded becauselintis not a required check.Add
headerContentTypeandheaderContentLengthbeside the existingheaderAcceptEncodingand use them throughout the package rather than only at the flagged sites, so the next handler that adds one does not re-trip the check.