File tree Expand file tree Collapse file tree
handwritten/error-reporting
test/unit/request-extractors Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,10 +81,15 @@ export function hapiRequestInformationExtractor(req?: hapi.Request) {
8181 return returnObject ;
8282 }
8383
84- returnObject
85- . setMethod ( req ! . method )
86- // TODO: Address the type conflict that requires a cast to string
87- . setUrl ( req ! . url as { } as string )
84+ let urlString : string ;
85+ if ( is . string ( req ! . url ) ) {
86+ urlString = req ! . url as { } as string ;
87+ } else {
88+ urlString = req ! . url . pathname ;
89+ }
90+
91+ returnObject . setMethod ( req ! . method )
92+ . setUrl ( urlString )
8893 . setUserAgent ( req ! . headers [ 'user-agent' ] )
8994 . setReferrer ( req ! . headers . referrer )
9095 . setStatusCode ( attemptToExtractStatusCode ( req ! ) )
Original file line number Diff line number Diff line change 1515 */
1616
1717import * as hapi from 'hapi' ;
18+ import { URL } from 'url' ;
1819
1920import { hapiRequestInformationExtractor } from '../../../src/request-extractors/hapi' ;
2021import { Fuzzer } from '../../../utils/fuzzer' ;
@@ -120,5 +121,16 @@ describe('hapiRequestInformationExtractor behaviour', () => {
120121 ANOTHER_PARTIAL_REQ_DERIVATION_VALUE as { } as hapi . Request ) ,
121122 ANOTHER_PARTIAL_REQ_EXPECTED_VALUE ) ;
122123 } ) ;
124+ it ( 'Should deal with hapi v16+ URL objects' , ( ) => {
125+ const PATH = '/foo/bar' ;
126+ const REQUEST = {
127+ ...FULL_REQ_DERIVATION_VALUE ,
128+ url : new URL ( `https://www.SUPER-TEST.com${ PATH } ` )
129+ } ;
130+ const EXPECTED = { ...FULL_REQ_EXPECTED_VALUE , url : PATH } ;
131+ deepStrictEqual (
132+ hapiRequestInformationExtractor ( REQUEST as { } as hapi . Request ) ,
133+ EXPECTED ) ;
134+ } ) ;
123135 } ) ;
124136} ) ;
You can’t perform that action at this time.
0 commit comments