@@ -2,7 +2,7 @@ import http from 'http';
22import { expect } from 'chai' ;
33import HttpConnection from '../../../../lib/connection/connections/HttpConnection' ;
44import ThriftHttpConnection from '../../../../lib/connection/connections/ThriftHttpConnection' ;
5-
5+ import IConnectionOptions from '../../../../lib/connection/contracts/IConnectionOptions' ;
66import ClientContextStub from '../../.stubs/ClientContextStub' ;
77
88describe ( 'HttpConnection.connect' , ( ) => {
@@ -127,4 +127,54 @@ describe('HttpConnection.connect', () => {
127127 ...extraHeaders ,
128128 } ) ;
129129 } ) ;
130+
131+ it ( 'should handle trailing slashes in host correctly' , async ( ) => {
132+ interface TestCase {
133+ input : {
134+ host : string ;
135+ path ?: string ;
136+ } ;
137+ expected : string ;
138+ }
139+
140+ const testCases : TestCase [ ] = [
141+ {
142+ input : { host : 'xyz.com/' , path : '/sql/v1' } ,
143+ expected : 'https://xyz.com:443/sql/v1' ,
144+ } ,
145+ {
146+ input : { host : 'xyz.com' , path : '/sql/v1' } ,
147+ expected : 'https://xyz.com:443/sql/v1' ,
148+ } ,
149+ {
150+ input : { host : 'xyz.com/' , path : undefined } ,
151+ expected : 'https://xyz.com:443/' ,
152+ } ,
153+ {
154+ input : { host : 'xyz.com' , path : 'sql/v1' } ,
155+ expected : 'https://xyz.com:443/sql/v1' ,
156+ } ,
157+ {
158+ input : { host : 'xyz.com/' , path : 'sql/v1' } ,
159+ expected : 'https://xyz.com:443/sql/v1' ,
160+ } ,
161+ {
162+ input : { host : 'xyz.com' , path : 'sql/v1/' } ,
163+ expected : 'https://xyz.com:443/sql/v1' ,
164+ } ,
165+ ] ;
166+
167+ for ( const testCase of testCases ) {
168+ const options : IConnectionOptions = {
169+ host : testCase . input . host ,
170+ port : 443 ,
171+ path : testCase . input . path ,
172+ https : true ,
173+ } ;
174+
175+ const connection = new HttpConnection ( options , new ClientContextStub ( ) ) ;
176+ const thriftConnection = await connection . getThriftConnection ( ) ;
177+ expect ( thriftConnection . url ) . to . be . equal ( testCase . expected ) ;
178+ }
179+ } ) ;
130180} ) ;
0 commit comments