forked from nytimes/gziphandler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gzip_go18_test.go
70 lines (55 loc) · 1.98 KB
/
gzip_go18_test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// +build go1.8
package gziphandler
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSetAcceptEncodingForPushOptionsWithoutHeaders(t *testing.T) {
var opts *http.PushOptions
opts = setAcceptEncodingForPushOptions(opts)
assert.NotNil(t, opts)
assert.NotNil(t, opts.Header)
for k, v := range opts.Header {
assert.Equal(t, "Accept-Encoding", k)
assert.Len(t, v, 1)
assert.Equal(t, "gzip", v[0])
}
opts = &http.PushOptions{}
opts = setAcceptEncodingForPushOptions(opts)
assert.NotNil(t, opts)
assert.NotNil(t, opts.Header)
for k, v := range opts.Header {
assert.Equal(t, "Accept-Encoding", k)
assert.Len(t, v, 1)
assert.Equal(t, "gzip", v[0])
}
}
func TestSetAcceptEncodingForPushOptionsWithHeaders(t *testing.T) {
opts := &http.PushOptions{
Header: http.Header{
"User-Agent": []string{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36"},
},
}
opts = setAcceptEncodingForPushOptions(opts)
assert.NotNil(t, opts)
assert.NotNil(t, opts.Header)
assert.Equal(t, "gzip", opts.Header.Get("Accept-Encoding"))
assert.Equal(t, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36", opts.Header.Get("User-Agent"))
opts = &http.PushOptions{
Header: http.Header{
"User-Agent": []string{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36"},
acceptEncoding: []string{"deflate"},
},
}
opts = setAcceptEncodingForPushOptions(opts)
assert.NotNil(t, opts)
assert.NotNil(t, opts.Header)
e, found := opts.Header["Accept-Encoding"]
if !found {
assert.Fail(t, "Missing Accept-Encoding header value")
}
assert.Len(t, e, 1)
assert.Equal(t, "deflate", e[0])
assert.Equal(t, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36", opts.Header.Get("User-Agent"))
}