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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/connection/connections/HttpConnection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import thrift from 'thrift';
import https from 'https';

import { IncomingMessage } from 'http';
import http, { IncomingMessage } from 'http';
import IThriftConnection from '../contracts/IThriftConnection';
import IConnectionProvider from '../contracts/IConnectionProvider';
import IConnectionOptions, { Options } from '../contracts/IConnectionOptions';
Expand All @@ -21,12 +21,13 @@ export default class HttpConnection implements IConnectionProvider, IThriftConne
private connection: any;

connect(options: IConnectionOptions, authProvider: IAuthentication): Promise<IThriftConnection> {
const Agent = options.options?.https ? https.Agent : http.Agent;
const httpTransport = new HttpTransport({
transport: thrift.TBufferedTransport,
protocol: thrift.TBinaryProtocol,
...options.options,
nodeOptions: {
agent: new https.Agent({
agent: new Agent({
keepAlive: true,
maxSockets: 5,
keepAliveMsecs: 10000,
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/connection/connections/HttpConnection.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const http = require('http');
const { expect } = require('chai');
const HttpConnection = require('../../../../').connections.HttpConnection;

Expand Down Expand Up @@ -161,4 +162,29 @@ describe('HttpConnection.connect', () => {
expect(Object.keys(connection.thrift.options.nodeOptions)).to.be.deep.eq(['agent']);
});
});

it('should use a http agent if https is not enabled', () => {
const connection = new HttpConnection();
const authenticator = authProviderMock();
const resultConnection = {
responseCallback() {},
};
connection.thrift = thriftMock(resultConnection);

return connection
.connect(
{
host: 'localhost',
port: 10001,
options: {
https: false,
path: '/hive',
},
},
authenticator,
)
.then(() => {
expect(connection.thrift.options.nodeOptions.agent).to.be.instanceOf(http.Agent);
});
});
});