Skip to content

Commit

Permalink
Improved proxy builder
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Mar 7, 2023
1 parent 528af17 commit 74ade1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 2 additions & 8 deletions src/server/helpers/build-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function buildResponse(state: Partial<ResponseState>): KrasAnswer {
const redirectUrl = state.redirectUrl;
const headers = state.headers || {};
const injector = state.injector || {};

setIfUndefined(headers, 'content-type', 'text/html');
setIfUndefined(injector, 'name', '(none)');

Expand All @@ -85,18 +86,11 @@ function buildResponse(state: Partial<ResponseState>): KrasAnswer {
}

export function fromNode(ans: NodeResponse, body: Buffer, injector?: KrasInjectorInfo) {
const headers: Headers = {};

Object.keys(ans.headers).forEach((name) => {
const value = ans.headers[name];
headers[name] = Array.isArray(value) ? value.join() : value;
});

return buildResponse({
statusCode: ans.statusCode,
statusText: ans.statusMessage,
url: ans.url || ans.request.href,
headers,
headers: ans.headers,
content: body,
injector,
});
Expand Down
4 changes: 2 additions & 2 deletions src/server/helpers/compare-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function pathEquals(a: string, b: string) {

if (i === b.indexOf('?')) {
if (i !== -1) {
a = a.substr(0, i);
b = b.substr(0, i);
a = a.substring(0, i);
b = b.substring(0, i);
}

return stringEquals(a, b);
Expand Down

0 comments on commit 74ade1e

Please sign in to comment.