Skip to content

Commit

Permalink
feat: handle redirects from the server (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-engel authored Feb 7, 2023
1 parent b49fd04 commit 6b054f0
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 140 deletions.
10 changes: 10 additions & 0 deletions lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ export default class CIORequest {
let body = Buffer.concat(chunks).toString('utf-8');
let json = null;

if ([301, 302, 307, 308].includes(res.statusCode ?? 0)) {
let newURI = res.headers.location;

if (newURI == null) {
return reject(new Error(`Received a ${res.statusCode} status, but no Location header was present`));
}

return this.handler({ uri: newURI, body, method, headers }).then(resolve).catch(reject);
}

try {
if (body && body.length) {
json = JSON.parse(body);
Expand Down
38 changes: 22 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions test/request-app-api.ts

This file was deleted.

Loading

0 comments on commit 6b054f0

Please sign in to comment.