-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheader.go
More file actions
34 lines (30 loc) · 926 Bytes
/
header.go
File metadata and controls
34 lines (30 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package lambada
import "net/http"
// toSingleValueHeaders converts the headers to single value headers.
// If any header is multi-valued, only the first value is retained.
func toSingleValueHeaders(h http.Header) map[string]string {
res := map[string]string{}
for k, v := range h {
if len(v) > 0 {
res[k] = v[0]
}
}
return res
}
// fromSingleValueHeaders returns a http.Header from a map of single-valued headers.
// Header keys are canonicalized (using textproto.CanonicalMIMEHeaderKey) during the copy.
func fromSingleValueHeaders(h map[string]string) http.Header {
res := make(http.Header)
for k, v := range h {
res.Set(k, v)
}
return res
}
// canonicalizeHeader returns a copy of h with all the keys canonicalized using http.CanonicalHeaderKey
func canonicalizeHeader(h http.Header) http.Header {
res := make(http.Header)
for k, v := range h {
res[http.CanonicalHeaderKey(k)] = v
}
return res
}