Go's http.Header
has these two methods:
I see that the standard library uses these methods for example when writing request headers, but why are they public/what is a standard use case?
Go's http.Header
has these two methods:
I see that the standard library uses these methods for example when writing request headers, but why are they public/what is a standard use case?
In general, you would want to export anything that some other package needs to call. Sometimes this can get fairly low-level.
Header.WriteSubset()
would be useful in writing an HTTP proxy. The HTTP specifications say that certain headers are hop-by-hop headers, so that proxies that receive them must not pass them on to the next hop. By contrast, end-to-end headers are always passed on.
There are probably other uses. httputil.DumpRequest()
uses WriteSubset()
to exclude some irrelevant headers from its output.
Exporting Header.Write()
is less obvious. Though the Go standard library uses it to implement its CGI and FastCGI servers.