Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const RECONNECT_ID_HEADER = 'x-reconnect-id';

const OUTGOING = '[OUTGOING]';
const INCOMING = '[INCOMING]';
const HTTPLOG = '[HTTP]';

class ConfigParser {
setRetries() {
Expand Down Expand Up @@ -253,4 +254,5 @@ module.exports = {
kUpstreamRestart,
PROXY_LOCKED,
PROXY_RESTART,
HTTPLOG
};
13 changes: 11 additions & 2 deletions lib/core/Proxy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const WebSocket = require('ws');
const { config, kCleanup, kAddNewContext } = require('../config/constants');
const { config, kCleanup, kAddNewContext, HTTPLOG } = require('../config/constants');
const logger = require('../util/loggerFactory');
const Context = require('./Context');
const {
Expand Down Expand Up @@ -63,13 +63,22 @@ class Proxy {
method: request.method,
headers: request.headers,
};
logger.info(`${HTTPLOG} Received http request ${options}`);
const proxyReq = http.request(options, (proxyResponse) => {
response.writeHead(proxyResponse.statusCode, proxyResponse.headers);
proxyResponse.pipe(response, {
end: true,
});
});

proxyReq.on('error', (error)=>{
logger.error(`${request.url} received error ${error}`);
});
proxyReq.on('timeout', ()=>{
logger.info(`${request.url} timed out`);
});
proxyReq.on('drain', ()=>{
logger.info(`${request.url} drained out`);
});
request.pipe(proxyReq, {
end: true,
});
Expand Down
7 changes: 4 additions & 3 deletions test/core/proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Proxy = require('../../lib/core/Proxy');
const Context = require('../../lib/core/Context');
const { describe, it, before, after } = require('mocha');
const { expect } = require('chai');
const { spy, stub } = require('sinon');
const { spy } = require('sinon');
const { kAddNewContext } = require('../../lib/config/constants');
const http = require('http');

Expand Down Expand Up @@ -37,9 +37,10 @@ describe('Proxy', () => {
});

it('should handle request', () => {
const requestStub = stub(http, 'request');
const requestSpy = spy(http, 'request');
this.proxy.requestHandler(this.request, this.response);
expect(requestStub.calledOnce).to.be.equal(true);
expect(requestSpy.calledOnce).to.be.equal(true);
requestSpy.restore();
});

it('should set connection id', () => {
Expand Down