0

Let's say I have 2 response headers with the same name "Set-Cookie"

The .Get method can only get the first value

In the document it said: To access multiple values of a key, or to use non-canonical keys, access the map directly.

fmt.Println(headers.Get("Set-Cookie"))
// -> Can only get the first one

However when read the map

for key,value := range headers {
  fmt.Println(key, value)
}
// -> cannot range over headers (type *http.Header)

Currently I'm not sure the right way to read this data.

1
  • headers is a slice of strings. Commented Nov 5, 2019 at 4:53

2 Answers 2

2

http.Header is already a map[string][]string so there should be no need to pass the address of it around. If you somehow passed &request.Header, then you should pass it directly instead, without taking the address. If you have to pass the address for some reason, range over *headers instead of headers:

for key,value := range *headers {
}
Sign up to request clarification or add additional context in comments.

Comments

2

Use Values instead of Get. Values returns all values associated with the given key.

1 Comment

this is the only right answer lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.