Skip to content

Commit 85249ca

Browse files
improve url handling
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
1 parent 5cec293 commit 85249ca

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

lib/connection/connections/HttpConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default class HttpConnection implements IConnectionProvider {
9898

9999
this.connection = new ThriftHttpConnection(
100100
{
101-
url: `${options.https ? 'https' : 'http'}://${options.host.replace(/\/$/, '')}:${options.port}${options.path ? ('/' + options.path.replace(/\/$/, '')) : '/'}`,
101+
url: `${options.https ? 'https' : 'http'}://${options.host.replace(/\/$/, '')}:${options.port}${options.path ?? '/'}`,
102102
transport: thrift.TBufferedTransport,
103103
protocol: thrift.TBinaryProtocol,
104104
getRetryPolicy: () => this.getRetryPolicy(),

tests/unit/connection/connections/HttpConnection.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('HttpConnection.connect', () => {
128128
});
129129
});
130130

131-
it('should handle trailing slashes in host and path correctly', async () => {
131+
it('should handle trailing slashes in host correctly', async () => {
132132
interface TestCase {
133133
input: {
134134
host: string;
@@ -139,19 +139,15 @@ describe('HttpConnection.connect', () => {
139139

140140
const testCases: TestCase[] = [
141141
{
142-
input: { host: 'xyz.com/', path: '/sql/v1/' },
142+
input: { host: 'xyz.com/', path: '/sql/v1' },
143143
expected: 'https://xyz.com:443/sql/v1'
144144
},
145145
{
146-
input: { host: 'xyz.com', path: 'sql/v1' },
146+
input: { host: 'xyz.com', path: '/sql/v1' },
147147
expected: 'https://xyz.com:443/sql/v1'
148148
},
149149
{
150-
input: { host: 'xyz.com/', path: 'sql/v1' },
151-
expected: 'https://xyz.com:443/sql/v1'
152-
},
153-
{
154-
input: { host: 'xyz.com', path: undefined },
150+
input: { host: 'xyz.com/', path: undefined },
155151
expected: 'https://xyz.com:443/'
156152
}
157153
];

0 commit comments

Comments
 (0)