forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_extensions.go
49 lines (41 loc) · 1.18 KB
/
http_extensions.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
40
41
42
43
44
45
46
47
48
49
package ravendb
import (
"net/http"
"strings"
)
func gttpExtensionsGetRequiredEtagHeader(response *http.Response) (*string, error) {
hdr := response.Header.Get(headersEtag)
if hdr == "" {
return nil, newIllegalStateError("Response did't had an ETag header")
}
etag := httpExtensionsEtagHeaderToChangeVector(hdr)
return &etag, nil
}
func gttpExtensionsGetEtagHeader(response *http.Response) *string {
hdr := response.Header.Get(headersEtag)
if hdr == "" {
return nil
}
res := httpExtensionsEtagHeaderToChangeVector(hdr)
return &res
}
func gttpExtensionsGetEtagHeaderFromMap(headers map[string]string) *string {
hdr := headers[headersEtag]
if hdr == "" {
return nil
}
res := httpExtensionsEtagHeaderToChangeVector(hdr)
return &res
}
// TODO: add test
func httpExtensionsEtagHeaderToChangeVector(responseHeader string) string {
panicIf(responseHeader == "", "Response did't had an ETag header")
if strings.HasPrefix(responseHeader, `"`) {
return responseHeader[1 : len(responseHeader)-1]
}
return responseHeader
}
func httpExtensionsGetBooleanHeader(response *http.Response, header string) bool {
hdr := response.Header.Get(header)
return strings.EqualFold(hdr, "true")
}