Skip to content

Commit

Permalink
Add more complete protocol splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
k-fish committed Jul 17, 2023
1 parent 138da56 commit ee06994
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/tracing-internal/src/browser/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,23 @@ function addHTTPTimings(span: Span): void {
* @param nextHopProtocol PerformanceResourceTiming.nextHopProtocol
*/
export function extractNetworkProtocol(nextHopProtocol: string): { name: string; version: string } {
const name = nextHopProtocol.split('/')[0].toLowerCase() || (nextHopProtocol.startsWith('h') && 'http') || 'unknown';
const version = nextHopProtocol.split('/')[1] || nextHopProtocol.split('h')[1] || 'unknown';
let name = 'unknown';
let version = 'unknown';
let _name = '';
for (const char of nextHopProtocol) {
// http/1.1 etc.
if (char === '/') {
[name, version] = nextHopProtocol.split('/');
break;
}
// h2, h3 etc.
if (!isNaN(Number(char))) {
name = _name === 'h' ? 'http' : _name;
version = nextHopProtocol.split(_name)[1];
break;
}
_name += char;
}
return { name, version };
}

Expand Down

0 comments on commit ee06994

Please sign in to comment.