@@ -202,12 +202,16 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
202202 }
203203
204204 try {
205+ const { size } = await FileSystem . getStatisticsAsync ( localFilePath ) ;
205206 const entryStream : FileSystemReadStream = FileSystem . createReadStream ( localFilePath ) ;
206207 const result : IWebClientStreamResponse | false = await this . _makeHttpStreamRequestAsync ( {
207208 terminal,
208209 relUrl : `${ this . _cacheKeyPrefix } ${ cacheId } ` ,
209210 method : this . _uploadMethod ,
210211 body : entryStream ,
212+ headers : {
213+ 'Content-Length' : `${ size } `
214+ } ,
211215 warningText : 'Could not write cache entry' ,
212216 // maxAttempts is 1 because the file read stream is consumed after the first attempt
213217 // and cannot be replayed. Downloads use MAX_HTTP_CACHE_ATTEMPTS since each retry
@@ -353,6 +357,7 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
353357 relUrl : string ;
354358 method : 'GET' | UploadMethod ;
355359 body : Readable | undefined ;
360+ headers ?: Record < string , string > ;
356361 warningText : string ;
357362 maxAttempts : number ;
358363 credentialOptions ?: CredentialsOptions ;
@@ -383,12 +388,22 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
383388 relUrl : string ;
384389 method : 'GET' | UploadMethod ;
385390 body : Buffer | Readable | undefined ;
391+ headers ?: Record < string , string > ;
386392 warningText : string ;
387393 maxAttempts : number ;
388394 credentialOptions ?: CredentialsOptions ;
389395 stream : boolean ;
390396 } ) : Promise < IWebClientResponse | IWebClientStreamResponse | false > {
391- const { terminal, relUrl, method, body, warningText, credentialOptions, stream } = options ;
397+ const {
398+ terminal,
399+ relUrl,
400+ method,
401+ body,
402+ headers : requestHeaders ,
403+ warningText,
404+ credentialOptions,
405+ stream
406+ } = options ;
392407 const safeCredentialOptions : CredentialsOptions = credentialOptions ?? CredentialsOptions . Optional ;
393408 const credentials : string | undefined = await this . _tryGetCredentialsAsync ( safeCredentialOptions ) ;
394409 const url : string = new URL ( relUrl , this . _url ) . href ;
@@ -404,6 +419,12 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
404419 }
405420 }
406421
422+ if ( requestHeaders ) {
423+ for ( const [ key , value ] of Object . entries ( requestHeaders ) ) {
424+ headers [ key ] = value ;
425+ }
426+ }
427+
407428 const bodyLengthDesc : string = Buffer . isBuffer ( body ) ? `${ body . length } bytes` : 'unknown length' ;
408429
409430 terminal . writeDebugLine ( `[http-build-cache] request: ${ method } ${ url } ${ bodyLengthDesc } ` ) ;
0 commit comments