@@ -3,6 +3,7 @@ package client
3
3
import (
4
4
"archive/tar"
5
5
"bytes"
6
+ "compress/gzip"
6
7
"context"
7
8
"crypto/rand"
8
9
"crypto/rsa"
@@ -2196,6 +2197,49 @@ func testBuildHTTPSource(t *testing.T, sb integration.Sandbox) {
2196
2197
require .Equal (t , http .MethodHead , allReqs [1 ].Method )
2197
2198
require .Equal (t , "gzip" , allReqs [1 ].Header .Get ("Accept-Encoding" ))
2198
2199
2200
+ require .NoError (t , os .RemoveAll (filepath .Join (tmpdir , "foo" )))
2201
+
2202
+ // update the content at the url to be gzipped now, the final output
2203
+ // should remain the same
2204
+ modTime = time .Now ().Add (- 23 * time .Hour )
2205
+ var buf bytes.Buffer
2206
+ gw := gzip .NewWriter (& buf )
2207
+ _ , err = gw .Write (resp .Content )
2208
+ require .NoError (t , err )
2209
+ require .NoError (t , gw .Close ())
2210
+ gzipBytes := buf .Bytes ()
2211
+ respGzip := httpserver.Response {
2212
+ Etag : identity .NewID (),
2213
+ Content : gzipBytes ,
2214
+ LastModified : & modTime ,
2215
+ ContentEncoding : "gzip" ,
2216
+ }
2217
+ server .SetRoute ("/foo" , respGzip )
2218
+
2219
+ _ , err = c .Solve (sb .Context (), def , SolveOpt {
2220
+ Exports : []ExportEntry {
2221
+ {
2222
+ Type : ExporterLocal ,
2223
+ OutputDir : tmpdir ,
2224
+ },
2225
+ },
2226
+ }, nil )
2227
+ require .NoError (t , err )
2228
+
2229
+ require .Equal (t , server .Stats ("/foo" ).AllRequests , 4 )
2230
+ require .Equal (t , server .Stats ("/foo" ).CachedRequests , 1 )
2231
+
2232
+ dt , err = os .ReadFile (filepath .Join (tmpdir , "foo" ))
2233
+ require .NoError (t , err )
2234
+ require .Equal (t , resp .Content , dt )
2235
+
2236
+ allReqs = server .Stats ("/foo" ).Requests
2237
+ require .Equal (t , 4 , len (allReqs ))
2238
+ require .Equal (t , http .MethodHead , allReqs [2 ].Method )
2239
+ require .Equal (t , "gzip" , allReqs [2 ].Header .Get ("Accept-Encoding" ))
2240
+ require .Equal (t , http .MethodGet , allReqs [3 ].Method )
2241
+ require .Equal (t , "gzip" , allReqs [3 ].Header .Get ("Accept-Encoding" ))
2242
+
2199
2243
// test extra options
2200
2244
st = llb .HTTP (server .URL + "/foo" , llb .Filename ("bar" ), llb .Chmod (0741 ), llb .Chown (1000 , 1000 ))
2201
2245
@@ -2212,7 +2256,7 @@ func testBuildHTTPSource(t *testing.T, sb integration.Sandbox) {
2212
2256
}, nil )
2213
2257
require .NoError (t , err )
2214
2258
2215
- require .Equal (t , server .Stats ("/foo" ).AllRequests , 3 )
2259
+ require .Equal (t , server .Stats ("/foo" ).AllRequests , 5 )
2216
2260
require .Equal (t , server .Stats ("/foo" ).CachedRequests , 1 )
2217
2261
2218
2262
dt , err = os .ReadFile (filepath .Join (tmpdir , "bar" ))
0 commit comments