Skip to content

Commit ee06994

Browse files
committed
Add more complete protocol splitting
1 parent 138da56 commit ee06994

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

packages/tracing-internal/src/browser/request.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,23 @@ function addHTTPTimings(span: Span): void {
189189
* @param nextHopProtocol PerformanceResourceTiming.nextHopProtocol
190190
*/
191191
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+
}
194209
return { name, version };
195210
}
196211

0 commit comments

Comments
 (0)