Skip to content

Commit

Permalink
fix: fix issues with http requests (#480)
Browse files Browse the repository at this point in the history
* Fix port in http request

* Add post data to http request if present

* Convert base64 to text if necessary
  • Loading branch information
sprmn authored Sep 19, 2022
1 parent 96ff42b commit 85c8921
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/behavior-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ export class BehaviorRouter {
res.setHeader(key as string, value);
}
}

res.end(response.body);

if (response.bodyEncoding === 'base64') {
res.end(Buffer.from(response.body, 'base64').toString('utf-8'));
} else {
res.end(response.body);
}
} catch (err) {
this.handleError(err, res);
return;
Expand Down
6 changes: 4 additions & 2 deletions src/services/origin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class Origin {
method: request.method,
protocol: baseUrl.protocol,
hostname: baseUrl.hostname,
port: baseUrl.port || (baseUrl.protocol === 'https:') ? 443 : 80,
port: baseUrl.port || (baseUrl.protocol === 'https:' ? 443 : 80),
path: uri.path,
headers: {
...headers,
Expand All @@ -144,7 +144,9 @@ export class Origin {
});
res.on('error', (err: Error) => reject(err));
});

if (request.body && request.body.data) {
req.write(request.body.data);
}
req.end();
});
}
Expand Down

0 comments on commit 85c8921

Please sign in to comment.