@@ -18,6 +18,7 @@ package settings
18
18
19
19
import (
20
20
"fmt"
21
+ "net/http"
21
22
"strings"
22
23
23
24
"github.com/onsi/ginkgo/v2"
@@ -29,11 +30,27 @@ import (
29
30
var _ = framework .DescribeSetting ("gzip" , func () {
30
31
f := framework .NewDefaultFramework ("gzip" )
31
32
33
+ host := "gzip"
34
+
35
+ ginkgo .BeforeEach (func () {
36
+ f .NewHttpbinDeployment ()
37
+ f .EnsureIngress (framework .NewSingleIngress (host , "/" , host , f .Namespace , framework .HTTPBinService , 80 , nil ))
38
+ })
39
+
32
40
ginkgo .It ("should be disabled by default" , func () {
33
41
f .WaitForNginxConfiguration (
34
42
func (cfg string ) bool {
35
43
return ! strings .Contains (cfg , "gzip on;" )
36
- })
44
+ },
45
+ )
46
+
47
+ f .HTTPTestClient ().
48
+ GET ("/xml" ).
49
+ WithHeader ("Host" , host ).
50
+ WithHeader ("Accept-Encoding" , "gzip" ).
51
+ Expect ().
52
+ Status (http .StatusOK ).
53
+ ContentEncoding ()
37
54
})
38
55
39
56
ginkgo .It ("should be enabled with default settings" , func () {
@@ -50,7 +67,16 @@ var _ = framework.DescribeSetting("gzip", func() {
50
67
strings .Contains (cfg , fmt .Sprintf ("gzip_types %s;" , defaultCfg .GzipTypes )) &&
51
68
strings .Contains (cfg , "gzip_proxied any;" ) &&
52
69
strings .Contains (cfg , "gzip_vary on;" )
53
- })
70
+ },
71
+ )
72
+
73
+ f .HTTPTestClient ().
74
+ GET ("/xml" ).
75
+ WithHeader ("Host" , host ).
76
+ WithHeader ("Accept-Encoding" , "gzip" ).
77
+ Expect ().
78
+ Status (http .StatusOK ).
79
+ ContentEncoding ("gzip" )
54
80
})
55
81
56
82
ginkgo .It ("should set gzip_comp_level to 4" , func () {
@@ -61,7 +87,16 @@ var _ = framework.DescribeSetting("gzip", func() {
61
87
func (cfg string ) bool {
62
88
return strings .Contains (cfg , "gzip on;" ) &&
63
89
strings .Contains (cfg , "gzip_comp_level 4;" )
64
- })
90
+ },
91
+ )
92
+
93
+ f .HTTPTestClient ().
94
+ GET ("/xml" ).
95
+ WithHeader ("Host" , host ).
96
+ WithHeader ("Accept-Encoding" , "gzip" ).
97
+ Expect ().
98
+ Status (http .StatusOK ).
99
+ ContentEncoding ("gzip" )
65
100
})
66
101
67
102
ginkgo .It ("should set gzip_disable to msie6" , func () {
@@ -72,28 +107,87 @@ var _ = framework.DescribeSetting("gzip", func() {
72
107
func (cfg string ) bool {
73
108
return strings .Contains (cfg , "gzip on;" ) &&
74
109
strings .Contains (cfg , `gzip_disable "msie6";` )
75
- })
110
+ },
111
+ )
112
+
113
+ f .HTTPTestClient ().
114
+ GET ("/xml" ).
115
+ WithHeader ("Host" , host ).
116
+ WithHeader ("Accept-Encoding" , "gzip" ).
117
+ WithHeader ("User-Agent" , "Mozilla/4.8 [en] (Windows NT 5.1; U)" ).
118
+ Expect ().
119
+ Status (http .StatusOK ).
120
+ ContentEncoding ("gzip" )
121
+
122
+ f .HTTPTestClient ().
123
+ GET ("/xml" ).
124
+ WithHeader ("Host" , host ).
125
+ WithHeader ("Accept-Encoding" , "gzip" ).
126
+ WithHeader ("User-Agent" , "Mozilla/45.0 (compatible; MSIE 6.0; Windows NT 5.1)" ).
127
+ Expect ().
128
+ Status (http .StatusOK ).
129
+ ContentEncoding ()
76
130
})
77
131
78
132
ginkgo .It ("should set gzip_min_length to 100" , func () {
79
133
f .UpdateNginxConfigMapData ("use-gzip" , "true" )
80
134
f .UpdateNginxConfigMapData ("gzip-min-length" , "100" )
135
+ f .UpdateNginxConfigMapData ("gzip-types" , "application/octet-stream" )
81
136
82
137
f .WaitForNginxConfiguration (
83
138
func (cfg string ) bool {
84
139
return strings .Contains (cfg , "gzip on;" ) &&
85
- strings .Contains (cfg , "gzip_min_length 100;" )
86
- })
140
+ strings .Contains (cfg , "gzip_min_length 100;" ) &&
141
+ strings .Contains (cfg , "gzip_types application/octet-stream;" )
142
+ },
143
+ )
144
+
145
+ f .HTTPTestClient ().
146
+ GET ("/bytes/99" ).
147
+ WithHeader ("Host" , host ).
148
+ WithHeader ("Accept-Encoding" , "gzip" ).
149
+ Expect ().
150
+ Status (http .StatusOK ).
151
+ ContentType ("application/octet-stream" ).
152
+ ContentEncoding ()
153
+
154
+ f .HTTPTestClient ().
155
+ GET ("/bytes/100" ).
156
+ WithHeader ("Host" , host ).
157
+ WithHeader ("Accept-Encoding" , "gzip" ).
158
+ Expect ().
159
+ Status (http .StatusOK ).
160
+ ContentType ("application/octet-stream" ).
161
+ ContentEncoding ("gzip" )
87
162
})
88
163
89
- ginkgo .It ("should set gzip_types to application/javascript " , func () {
164
+ ginkgo .It ("should set gzip_types to text/html " , func () {
90
165
f .UpdateNginxConfigMapData ("use-gzip" , "true" )
91
- f .UpdateNginxConfigMapData ("gzip-types" , "application/javascript " )
166
+ f .UpdateNginxConfigMapData ("gzip-types" , "text/html " )
92
167
93
168
f .WaitForNginxConfiguration (
94
169
func (cfg string ) bool {
95
170
return strings .Contains (cfg , "gzip on;" ) &&
96
- strings .Contains (cfg , "gzip_types application/javascript;" )
97
- })
171
+ strings .Contains (cfg , "gzip_types text/html;" )
172
+ },
173
+ )
174
+
175
+ f .HTTPTestClient ().
176
+ GET ("/xml" ).
177
+ WithHeader ("Host" , host ).
178
+ WithHeader ("Accept-Encoding" , "gzip" ).
179
+ Expect ().
180
+ Status (http .StatusOK ).
181
+ ContentType ("application/xml" ).
182
+ ContentEncoding ()
183
+
184
+ f .HTTPTestClient ().
185
+ GET ("/html" ).
186
+ WithHeader ("Host" , host ).
187
+ WithHeader ("Accept-Encoding" , "gzip" ).
188
+ Expect ().
189
+ Status (http .StatusOK ).
190
+ ContentType ("text/html" ).
191
+ ContentEncoding ("gzip" )
98
192
})
99
193
})
0 commit comments