File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
packages/tracing-internal/src/browser Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -189,8 +189,23 @@ function addHTTPTimings(span: Span): void {
189
189
* @param nextHopProtocol PerformanceResourceTiming.nextHopProtocol
190
190
*/
191
191
export function extractNetworkProtocol ( nextHopProtocol : string ) : { name : string ; version : string } {
192
- const name = nextHopProtocol . split ( '/' ) [ 0 ] . toLowerCase ( ) || ( nextHopProtocol . startsWith ( 'h' ) && 'http' ) || 'unknown' ;
193
- const version = nextHopProtocol . split ( '/' ) [ 1 ] || nextHopProtocol . split ( 'h' ) [ 1 ] || 'unknown' ;
192
+ let name = 'unknown' ;
193
+ let version = 'unknown' ;
194
+ let _name = '' ;
195
+ for ( const char of nextHopProtocol ) {
196
+ // http/1.1 etc.
197
+ if ( char === '/' ) {
198
+ [ name , version ] = nextHopProtocol . split ( '/' ) ;
199
+ break ;
200
+ }
201
+ // h2, h3 etc.
202
+ if ( ! isNaN ( Number ( char ) ) ) {
203
+ name = _name === 'h' ? 'http' : _name ;
204
+ version = nextHopProtocol . split ( _name ) [ 1 ] ;
205
+ break ;
206
+ }
207
+ _name += char ;
208
+ }
194
209
return { name, version } ;
195
210
}
196
211
You can’t perform that action at this time.
0 commit comments