@@ -27,6 +27,7 @@ import * as semver from 'semver';
2727
2828import { Http2Plugin , plugin } from '../src/' ;
2929import { IncomingHttpHeaders , ServerHttp2Stream } from 'http2' ;
30+ import { URL } from 'url' ;
3031
3132const VERSION = process . versions . node ;
3233
@@ -123,9 +124,8 @@ describe('Http2Plugin', () => {
123124 const serverPort = 8080 ;
124125 const serverPort2 = 8081 ;
125126 const host = `localhost:${ serverPort } ` ;
126- const host2 = `localhost:${ serverPort2 } ` ;
127127 const authority = `http://${ host } ` ;
128- const authority2 = `http://${ host2 } ` ;
128+ const authorityUrlObject = new URL ( '/' , `http://${ host } /` ) ;
129129
130130 const log = logger . logger ( ) ;
131131 const tracer = new CoreTracer ( ) ;
@@ -161,7 +161,7 @@ describe('Http2Plugin', () => {
161161 server2 . listen ( serverPort2 ) ;
162162
163163 client = http2 . connect ( authority ) ;
164- client2 = http2 . connect ( authority2 ) ;
164+ client2 = http2 . connect ( authorityUrlObject ) ;
165165 } ) ;
166166
167167 beforeEach ( ( ) => {
@@ -200,6 +200,24 @@ describe('Http2Plugin', () => {
200200 } ) ;
201201 } ) ;
202202
203+ it ( 'should succeed when the client is connected using the url.URL object (#640)' , async ( ) => {
204+ const statusCode = 200 ;
205+ const testPath = `/${ statusCode } ` ;
206+ const requestOptions = {
207+ ':method' : 'GET' ,
208+ ':path' : testPath ,
209+ } ;
210+
211+ assert . strictEqual ( spanVerifier . endedSpans . length , 0 ) ;
212+
213+ await http2Request . get ( client2 , requestOptions ) . then ( result => {
214+ assert . strictEqual ( result , statusCode . toString ( ) ) ;
215+ assert . strictEqual ( spanVerifier . endedSpans . length , 2 ) ;
216+ const span = spanVerifier . endedSpans [ 1 ] ;
217+ assertSpanAttributes ( span , statusCode , 'GET' , host , testPath ) ;
218+ } ) ;
219+ } ) ;
220+
203221 const httpErrorCodes = [ 400 , 401 , 403 , 404 , 429 , 501 , 503 , 504 , 500 ] ;
204222
205223 httpErrorCodes . map ( errorCode => {
0 commit comments