Skip to content

Commit

Permalink
fix: issue when response status was not propageted for http proxy han…
Browse files Browse the repository at this point in the history
…dler
  • Loading branch information
vlad-tkachenko committed Nov 11, 2023
1 parent b28b30b commit c351814
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/handlers/HttpProxyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ export class HttpProxyHandler {

this.logInfo(`[${requestId}] [HttpProxyHandler] Processing HTTP/HTTPS proxy request with method ${method} to ${target}${url}`);

const requestHeadersToSend = RequestUtils.prepareProxyHeaders(
req.headers,
this.configuration.proxyRequestHeaders,
this.upstream.proxyRequestHeaders,
// istanbul ignore next
proxyConfiguration?.proxyRequestHeaders,
);

const isKeepAliveRequest = req.headers.connection.toLowerCase() === 'keep-alive';
const options: RequestOptions = {
method,
host,
port,

headers: RequestUtils.prepareProxyHeaders(
req.headers,
this.configuration.proxyRequestHeaders,
this.upstream.proxyRequestHeaders,
// istanbul ignore next
proxyConfiguration?.proxyRequestHeaders,
),
headers: requestHeadersToSend,
path: RequestUtils.concatPath(initialPath, url),
timeout: this.configuration.proxyRequestTimeout,
};
Expand All @@ -70,6 +72,13 @@ export class HttpProxyHandler {
});

client.on('response', (response: IncomingMessage) => {
if (isKeepAliveRequest) {
client.setTimeout(0);
}

// map status code
res.statusCode = response.statusCode;

const headersToSet = RequestUtils.prepareProxyHeaders(
response.headers,
this.configuration.responseHeaders,
Expand Down
18 changes: 18 additions & 0 deletions test/HttpProxy.success.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ export class HttpProxySuccessSuite {
deepEqual(result.data, testData);
}

@test()
async echoRequestWithKeepAliveConnection(): Promise<void> {
await this.initProxy();

const testData = [];
for (let i = 0; i < 1000 * 1000; i++) {
testData.push('Iteration - ' + i);
}

const result = await axios.post(`${this.proxyUrl}/echo`, testData, {
maxBodyLength: 50 * 1024 * 1024, // 50 mb
headers: {
'Connection': 'keep-alive'
}
});
deepEqual(result.data, testData);
}

@test()
async customPath(): Promise<void> {
await this.after();
Expand Down

0 comments on commit c351814

Please sign in to comment.