Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staticcheck: warn when "Content-Length" or "Connection" is added to http.Request.Header #735

Open
vcabbage opened this issue Apr 29, 2020 · 0 comments
Labels
needs-decision We have to decide if this check is feasible and desirable new-check

Comments

@vcabbage
Copy link
Sponsor

// For client requests, certain headers such as Content-Length
// and Connection are automatically written when needed and
// values in Header may be ignored. See the documentation
// for the Request.Write method.

https://golang.org/pkg/net/http/#Request.Header

Instead of setting Content-Length or Connection directly in the headers, Request.ContentLength and Request.Close should be used instead.

Match statements like:

request.Header.Set("Content-Length", ...)
request.Header.Add("Content-Length", ...)
request.Header.Set("Connection", "close")
request.Header.Add("Connection", "close")

Since headers are canonicalized, a case insensitive match of the header name would be ideal.

Matching entries when the header map is manually constructed would also be nice, but I imagine would be more involved.

@vcabbage vcabbage added the needs-triage Newly filed issue that needs triage label Apr 29, 2020
@dominikh dominikh changed the title Warn when "Content-Type" or "Connection" is added to http.Request.Header staticcheck: warn when "Content-Length" or "Connection" is added to http.Request.Header Apr 29, 2020
@dominikh dominikh added needs-decision We have to decide if this check is feasible and desirable new-check and removed needs-triage Newly filed issue that needs triage labels Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision We have to decide if this check is feasible and desirable new-check
Projects
None yet
Development

No branches or pull requests

2 participants