Skip to content

Commit 5dd2b51

Browse files
authored
Merge pull request #13 from andybee/fix-http-regression
Fix http endpoint regression
2 parents 844595c + 55beeb3 commit 5dd2b51

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class Client_AuroraDataMySQL extends Client_MySQL { // eslint-disable-line camel
6666
throw new Error(`Failed to load aws-sdk rdsdataservice client, did you forget to install it as a dependency? (${err.message})`);
6767
}
6868

69-
const https = require('https');
69+
const https = this.config.connection.sdkConfig && String(this.config.connection.sdkConfig.endpoint).startsWith('http:')
70+
? require('http')
71+
: require('https');
7072

7173
const agent = new https.Agent({
7274
keepAlive: true

tests/test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ describe('SDK configuration tests', () => {
101101
}
102102
});
103103
});
104+
105+
test('Uses HTTP agent when called with an HTTP endpoint', () => {
106+
require('knex')({
107+
client: require('..'),
108+
connection: {
109+
database: constants.DATABASE,
110+
resourceArn: constants.AURORA_CLUSTER_ARN,
111+
secretArn: constants.SECRET_ARN,
112+
sdkConfig: {
113+
endpoint: 'http://localhost:8080'
114+
}
115+
}
116+
});
117+
118+
expect(RDSDataService).toHaveBeenCalledTimes(1);
119+
expect(RDSDataService).toHaveBeenCalledWith({
120+
endpoint: 'http://localhost:8080',
121+
httpOptions: {
122+
agent: expect.objectContaining({
123+
protocol: 'http:'
124+
})
125+
}
126+
});
127+
});
104128
});
105129

106130
test('Destroy functionality', async () => {

0 commit comments

Comments
 (0)