Conversation
The analyzer resolved net/http.Header from the first object named
"Header" found in TypesInfo.Uses. That map also holds the
ResponseWriter.Header method and the Request.Header field, and its
iteration order is random, so calls such as w.Header().Set("foo", "x")
were silently skipped whenever the method won.
Compare the receiver type against net/http.Header directly.
Indexing http.Header, deleting from it and building a composite literal all skip the canonicalization Get, Set, Add, Del and Values perform. A non-canonical key in those positions is a silent lookup miss, which is worse than the extra work the method checks catch. Report string literals and constants used as keys in index expressions, the delete builtin and http.Header composite literals. Keys must match http.CanonicalHeaderKey exactly: exclusions and well-known spellings such as "ETag" are ignored, since net/http never stores them. Closes lasiar#80
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.
Closes #80
Indexing
http.Header,deleteandhttp.Header{...}literals skip canonicalization, so a non-canonical key silently misses. This reports literal and constant keys in those positions. Keys must matchhttp.CanonicalHeaderKeyexactly: exclusions and well-known spellings such asETagdon't apply, since net/http never stores them. Deliberate non-canonical writes need//nolint:canonicalheader.The first commit fixes a detection bug found while testing:
net/http.Headerwas taken from the first object namedHeaderinTypesInfo.Uses, which also holds theResponseWriter.Headermethod and iterates in random order.w.Header().Set("foo", "x")was skipped whenever the method won.Both commits add diagnostics golangci-lint users will see on upgrade. On Caddy (caddyserver/caddy#8025), the map check finds 2 deliberate RFC 6455 spellings in non-test code and nothing else.
This overlaps with #87 in
analyzer.go; happy to rebase if it lands first.