Skip to content

net/http: Elaborate requirement for header key format #53140

Closed
@minherz

Description

@minherz

What is the URL of the page with the issue?

https://pkg.go.dev/net/http

What is your user agent?

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36

What did you expect to see?

An easy way to find information that helps troubleshooting cases when a function Get of the Header type returns nil instead of the header's value.
It happens when the Request object is initialized like in the following example:

&http.Request{
    URL:    "http://acme.com/index",
    Header: http.Header{"x-cloud-trace-context": {"105445aa7843bc8bf206b12000100012/000012345;o=1"}},
}

In this case the header's key does not get converted into the cannonical format and, in result, executing the following code prints <nil>:

req := &http.Request{
    URL:    "http://acme.com/index",
    Header: http.Header{"x-cloud-trace-context": {"105445aa7843bc8bf206b12000100012/000012345;o=1"}},
}
fmt.Println(req.Header.Get(x-cloud-trace-context")

What did you see instead?

The current documentation about Get() function of the Header does not clearly elaborates that if the header's key is stored not in the canonical format then it will not be returned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions