How can I obtain all available http headers from a request as array in Go? I see only the following two methods:
But in this case I need to know the name of the Header and can't return all existing headers. I'd like to copy the http headers from one request to anther one.
Use Request.Header to access all headers. Because Header is a map[string][]string, two loops are required to access all headers.
// Loop over header names
for name, values := range r.Header {
// Loop over all values for the name.
for _, value := range values {
fmt.Println(name, value)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With