@@ -52,6 +52,7 @@ func TestServerHeaders(t *testing.T) {
52
52
53
53
// test for chrome
54
54
response , _ := requestToServer (url , app , chromeUA , acceptWebP )
55
+ defer response .Body .Close ()
55
56
ratio := response .Header .Get ("X-Compression-Rate" )
56
57
etag := response .Header .Get ("Etag" )
57
58
@@ -60,7 +61,8 @@ func TestServerHeaders(t *testing.T) {
60
61
61
62
// test for safari
62
63
response , _ = requestToServer (url , app , safariUA , acceptLegacy )
63
- ratio = response .Header .Get ("X-Compression-Rate" )
64
+ defer response .Body .Close ()
65
+ // ratio = response.Header.Get("X-Compression-Rate")
64
66
etag = response .Header .Get ("Etag" )
65
67
66
68
assert .NotEqual (t , "" , etag )
@@ -96,14 +98,16 @@ func TestConvert(t *testing.T) {
96
98
97
99
// test Chrome
98
100
for url , respType := range testChromeLink {
99
- _ , data := requestToServer (url , app , chromeUA , acceptWebP )
101
+ resp , data := requestToServer (url , app , chromeUA , acceptWebP )
102
+ defer resp .Body .Close ()
100
103
contentType := getFileContentType (data )
101
104
assert .Equal (t , respType , contentType )
102
105
}
103
106
104
107
// test Safari
105
108
for url , respType := range testSafariLink {
106
- _ , data := requestToServer (url , app , safariUA , acceptLegacy )
109
+ resp , data := requestToServer (url , app , safariUA , acceptLegacy )
110
+ defer resp .Body .Close ()
107
111
contentType := getFileContentType (data )
108
112
assert .Equal (t , respType , contentType )
109
113
}
@@ -119,12 +123,14 @@ func TestConvertNotAllowed(t *testing.T) {
119
123
120
124
// not allowed, but we have the file, this should return File extension not allowed
121
125
url := "http://127.0.0.1:3333/webp_server.bmp"
122
- _ , data := requestToServer (url , app , chromeUA , acceptWebP )
126
+ resp , data := requestToServer (url , app , chromeUA , acceptWebP )
127
+ defer resp .Body .Close ()
123
128
assert .Contains (t , string (data ), "File extension not allowed" )
124
129
125
130
// not allowed, random file
126
131
url = url + "hagdgd"
127
- _ , data = requestToServer (url , app , chromeUA , acceptWebP )
132
+ resp , data = requestToServer (url , app , chromeUA , acceptWebP )
133
+ defer resp .Body .Close ()
128
134
assert .Contains (t , string (data ), "File extension not allowed" )
129
135
130
136
}
@@ -139,6 +145,7 @@ func TestConvertProxyModeBad(t *testing.T) {
139
145
// this is local random image, should be 500
140
146
url := "http://127.0.0.1:3333/webp_8888server.bmp"
141
147
resp , _ := requestToServer (url , app , chromeUA , acceptWebP )
148
+ defer resp .Body .Close ()
142
149
assert .Equal (t , http .StatusInternalServerError , resp .StatusCode )
143
150
144
151
}
@@ -154,11 +161,13 @@ func TestConvertProxyModeWork(t *testing.T) {
154
161
url := "https://webp.sh/images/cover.jpg"
155
162
156
163
resp , data := requestToServer (url , app , chromeUA , acceptWebP )
164
+ defer resp .Body .Close ()
157
165
assert .Equal (t , http .StatusOK , resp .StatusCode )
158
166
assert .Equal (t , "image/webp" , getFileContentType (data ))
159
167
160
168
// test proxyMode with Safari
161
169
resp , data = requestToServer (url , app , safariUA , acceptLegacy )
170
+ defer resp .Body .Close ()
162
171
assert .Equal (t , http .StatusOK , resp .StatusCode )
163
172
assert .Equal (t , "image/jpeg" , getFileContentType (data ))
164
173
}
@@ -171,8 +180,9 @@ func TestConvertBigger(t *testing.T) {
171
180
app .Get ("/*" , convert )
172
181
173
182
url := "http://127.0.0.1:3333/big.jpg"
174
- response , data := requestToServer (url , app , chromeUA , acceptWebP )
175
- assert .Equal (t , "image/jpeg" , response .Header .Get ("content-type" ))
183
+ resp , data := requestToServer (url , app , chromeUA , acceptWebP )
184
+ defer resp .Body .Close ()
185
+ assert .Equal (t , "image/jpeg" , resp .Header .Get ("content-type" ))
176
186
assert .Equal (t , "image/jpeg" , getFileContentType (data ))
177
187
_ = os .RemoveAll (config .ExhaustPath )
178
188
}
0 commit comments