-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcookies.go
39 lines (30 loc) · 795 Bytes
/
cookies.go
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
35
36
37
38
39
package azuretls
import (
"bytes"
http "github.com/Noooste/fhttp"
"strings"
)
var cookieNameSanitizer = strings.NewReplacer("\n", "-", "\r", "-")
func CookiesToString(cookies []*http.Cookie) string {
var buf bytes.Buffer
var length = 0
for _, el := range cookies {
length += len(el.Name) + len(el.Value) + 3
}
buf.Grow(length)
for _, el := range cookies {
buf.WriteString(cookieNameSanitizer.Replace(el.Name))
buf.WriteByte('=')
buf.WriteString(cookieNameSanitizer.Replace(el.Value))
buf.WriteString("; ")
}
buf.Truncate(buf.Len() - 2)
return buf.String()
}
func GetCookiesMap(cookies []*http.Cookie) map[string]string {
var result = make(map[string]string, len(cookies))
for _, cookie := range cookies {
result[cookie.Name] = cookie.Value
}
return result
}