@@ -52,6 +52,7 @@ func TestServerHeaders(t *testing.T) {
5252
5353 // test for chrome
5454 response , _ := requestToServer (url , app , chromeUA , acceptWebP )
55+ defer response .Body .Close ()
5556 ratio := response .Header .Get ("X-Compression-Rate" )
5657 etag := response .Header .Get ("Etag" )
5758
@@ -60,7 +61,8 @@ func TestServerHeaders(t *testing.T) {
6061
6162 // test for safari
6263 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")
6466 etag = response .Header .Get ("Etag" )
6567
6668 assert .NotEqual (t , "" , etag )
@@ -96,14 +98,16 @@ func TestConvert(t *testing.T) {
9698
9799 // test Chrome
98100 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 ()
100103 contentType := getFileContentType (data )
101104 assert .Equal (t , respType , contentType )
102105 }
103106
104107 // test Safari
105108 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 ()
107111 contentType := getFileContentType (data )
108112 assert .Equal (t , respType , contentType )
109113 }
@@ -119,12 +123,14 @@ func TestConvertNotAllowed(t *testing.T) {
119123
120124 // not allowed, but we have the file, this should return File extension not allowed
121125 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 ()
123128 assert .Contains (t , string (data ), "File extension not allowed" )
124129
125130 // not allowed, random file
126131 url = url + "hagdgd"
127- _ , data = requestToServer (url , app , chromeUA , acceptWebP )
132+ resp , data = requestToServer (url , app , chromeUA , acceptWebP )
133+ defer resp .Body .Close ()
128134 assert .Contains (t , string (data ), "File extension not allowed" )
129135
130136}
@@ -139,6 +145,7 @@ func TestConvertProxyModeBad(t *testing.T) {
139145 // this is local random image, should be 500
140146 url := "http://127.0.0.1:3333/webp_8888server.bmp"
141147 resp , _ := requestToServer (url , app , chromeUA , acceptWebP )
148+ defer resp .Body .Close ()
142149 assert .Equal (t , http .StatusInternalServerError , resp .StatusCode )
143150
144151}
@@ -154,11 +161,13 @@ func TestConvertProxyModeWork(t *testing.T) {
154161 url := "https://webp.sh/images/cover.jpg"
155162
156163 resp , data := requestToServer (url , app , chromeUA , acceptWebP )
164+ defer resp .Body .Close ()
157165 assert .Equal (t , http .StatusOK , resp .StatusCode )
158166 assert .Equal (t , "image/webp" , getFileContentType (data ))
159167
160168 // test proxyMode with Safari
161169 resp , data = requestToServer (url , app , safariUA , acceptLegacy )
170+ defer resp .Body .Close ()
162171 assert .Equal (t , http .StatusOK , resp .StatusCode )
163172 assert .Equal (t , "image/jpeg" , getFileContentType (data ))
164173}
@@ -171,8 +180,9 @@ func TestConvertBigger(t *testing.T) {
171180 app .Get ("/*" , convert )
172181
173182 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" ))
176186 assert .Equal (t , "image/jpeg" , getFileContentType (data ))
177187 _ = os .RemoveAll (config .ExhaustPath )
178188}
0 commit comments