This repository was archived by the owner on Mar 11, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,16 +70,17 @@ export function makeHttpRequestData(
7070 responseSize ,
7171 latency ;
7272 // Format request properties
73- if ( req . url ) {
74- requestUrl = req . url ;
75- const url = new URL ( requestUrl ) ;
76- protocol = url . protocol ;
77- }
73+ if ( req . url ) requestUrl = req . url ;
7874 // OriginalURL overwrites inferred url
79- if ( 'originalUrl' in req && req . originalUrl ) {
80- requestUrl = req . originalUrl ;
81- const url = new URL ( requestUrl ) ;
82- protocol = url . protocol ;
75+ if ( 'originalUrl' in req && req . originalUrl ) requestUrl = req . originalUrl ;
76+ // Format protocol from valid URL
77+ if ( requestUrl ) {
78+ try {
79+ const url = new URL ( requestUrl ) ;
80+ protocol = url . protocol ;
81+ } catch ( e ) {
82+ // Library should not panic
83+ }
8384 }
8485 req . method ? ( requestMethod = req . method ) : null ;
8586 if ( req . headers && req . headers [ 'user-agent' ] ) {
Original file line number Diff line number Diff line change @@ -33,6 +33,16 @@ describe('http-request', () => {
3333 assert . strictEqual ( cloudReq . requestUrl , 'http://google.com/' ) ;
3434 assert . strictEqual ( cloudReq . requestMethod , 'GET' ) ;
3535 } ) ;
36+ it ( 'should not panic on invalid URL' , ( ) => {
37+ const req = {
38+ method : 'GET' ,
39+ originalUrl : 'invalid/url/' ,
40+ } as ServerRequest ;
41+ const cloudReq = makeHttpRequestData ( req ) ;
42+ assert . strictEqual ( cloudReq . protocol , undefined ) ;
43+ assert . strictEqual ( cloudReq . requestUrl , 'invalid/url/' ) ;
44+ assert . strictEqual ( cloudReq . requestMethod , 'GET' ) ;
45+ } ) ;
3646 it ( 'should infer as many request values as possible' , ( ) => {
3747 const req = {
3848 method : 'GET' ,
You can’t perform that action at this time.
0 commit comments