@@ -311,6 +311,7 @@ export class GitpodPluginDeployer implements GitpodPluginService {
311
311
requestretry ( {
312
312
url,
313
313
method : 'GET' ,
314
+ headers : { 'Content-Type' : '*/*' } ,
314
315
// if we cannot establish connection in 5s then try again in 2s 5 times
315
316
// if we cannot read then timeout in 5s
316
317
maxAttempts : 5 ,
@@ -349,30 +350,35 @@ export class GitpodPluginDeployer implements GitpodPluginService {
349
350
}
350
351
const stat = await fs . stat ( FileUri . fsPath ( fileUri ) ) ;
351
352
352
- const upload = new Promise < void > ( ( resolve , reject ) =>
353
- fs . createReadStream ( FileUri . fsPath ( fileUri ) )
354
- . pipe ( request . put ( {
355
- url : targetUrl ,
356
- headers : {
357
- 'Content-Length' : stat . size
358
- }
359
- } , ( err , response ) => {
360
- if ( err ) {
361
- reject ( err ) ;
362
- return ;
363
- }
364
- if ( response && response . statusCode !== 200 ) {
365
- if ( response . statusCode === 400 ) {
366
- console . error ( "Bad Request: /plugin returned with code 400." , err ) ;
367
- }
368
- reject ( new Error ( response . statusMessage ) ) ;
369
- return ;
353
+ // read file content instead of pipe stream to survive redirect
354
+ const fileContent = fs . readFileSync ( FileUri . fsPath ( fileUri ) ) ;
355
+
356
+ const upload = new Promise < void > ( ( resolve , reject ) => {
357
+ request . put ( {
358
+ url : targetUrl ,
359
+ followAllRedirects : true ,
360
+ followOriginalHttpMethod : true ,
361
+ headers : {
362
+ 'Content-Type' : '*/*' ,
363
+ 'Content-Length' : stat . size
364
+ } ,
365
+ body : fileContent
366
+ } , ( err , response ) => {
367
+ if ( err ) {
368
+ reject ( err ) ;
369
+ return ;
370
+ }
371
+ if ( response && response . statusCode !== 200 ) {
372
+ if ( response . statusCode === 400 ) {
373
+ console . error ( "Bad Request: /plugin returned with code 400." , err ) ;
370
374
}
371
- resolve ( undefined ) ;
372
- } ) )
373
- . on ( 'error' , reject )
374
- . on ( 'close' , ( ) => resolve ( undefined ) )
375
- ) ;
375
+ reject ( new Error ( response . statusMessage + " - " + response . body ) ) ;
376
+ return ;
377
+ }
378
+ resolve ( undefined ) ;
379
+ } ) ;
380
+ } ) ;
381
+
376
382
try {
377
383
// first try to upload ...
378
384
await upload ;
0 commit comments