Skip to content

Commit a869281

Browse files
Support HTTP redirect in plugin deployer
1 parent 90b4ba0 commit a869281

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

gitpod-extension/src/node/extensions/gitpod-plugin-deployer.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ export class GitpodPluginDeployer implements GitpodPluginService {
311311
requestretry({
312312
url,
313313
method: 'GET',
314+
headers: { 'Content-Type': '*/*' },
314315
// if we cannot establish connection in 5s then try again in 2s 5 times
315316
// if we cannot read then timeout in 5s
316317
maxAttempts: 5,
@@ -349,30 +350,35 @@ export class GitpodPluginDeployer implements GitpodPluginService {
349350
}
350351
const stat = await fs.stat(FileUri.fsPath(fileUri));
351352

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);
370374
}
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+
376382
try {
377383
// first try to upload ...
378384
await upload;

0 commit comments

Comments
 (0)