File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -699,6 +699,7 @@ function parseHarRequest(
699699 timingEvents,
700700 tags : [ ] ,
701701 matchedRuleId : false ,
702+ httpVersion : parseHttpVersion ( request . httpVersion , request . headers ) ,
702703 protocol : request . url . split ( ':' ) [ 0 ] ,
703704 method : request . method ,
704705 url : request . url ,
@@ -717,6 +718,27 @@ function parseHarRequest(
717718 }
718719}
719720
721+ function parseHttpVersion (
722+ versionString : string | undefined ,
723+ headers : HarFormat . Header [ ]
724+ ) {
725+ if ( ! versionString ) {
726+ // Make a best guess:
727+ if ( headers . some ( ( { name } ) => name . startsWith ( ':' ) ) ) {
728+ return '2.0' ;
729+ } else {
730+ return '1.1' ;
731+ }
732+ }
733+
734+ const regexMatch = / ^ ( H T T P \/ ) ? ( [ \d \. ] + ) $ / i. exec ( versionString ) ;
735+ if ( regexMatch ) {
736+ return regexMatch [ 2 ] ;
737+ }
738+
739+ throw TypeError ( `Invalid HTTP version: ${ versionString } ` ) ;
740+ }
741+
720742function parseHarRequestContents ( data : RequestContentData ) : Buffer {
721743 if ( data . encoding && Buffer . isEncoding ( data . encoding ) ) {
722744 return Buffer . from ( data . text , data . encoding ) ;
You can’t perform that action at this time.
0 commit comments