Skip to content

Commit 0ba30ce

Browse files
authored
fix 4105 (#4117)
* fix 4105 * skip < node v22
1 parent 794b342 commit 0ba30ce

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

lib/web/fetch/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
309309
originalURL.href,
310310
initiatorType,
311311
globalThis,
312-
cacheState
312+
cacheState,
313+
'', // bodyType
314+
response.status
313315
)
314316
}
315317

@@ -994,7 +996,7 @@ function fetchFinale (fetchParams, response) {
994996
// 3. Set fetchParams’s controller’s report timing steps to the following steps given a global object global:
995997
fetchParams.controller.reportTimingSteps = () => {
996998
// 1. If fetchParams’s request’s URL’s scheme is not an HTTP(S) scheme, then return.
997-
if (fetchParams.request.url.protocol !== 'https:') {
999+
if (!urlIsHttpHttpsScheme(fetchParams.request.url)) {
9981000
return
9991001
}
10001002

@@ -1036,7 +1038,6 @@ function fetchFinale (fetchParams, response) {
10361038
// fetchParams’s request’s URL, fetchParams’s request’s initiator type, global, cacheState, bodyInfo,
10371039
// and responseStatus.
10381040
if (fetchParams.request.initiatorType != null) {
1039-
// TODO: update markresourcetiming
10401041
markResourceTiming(timingInfo, fetchParams.request.url.href, fetchParams.request.initiatorType, globalThis, cacheState, bodyInfo, responseStatus)
10411042
}
10421043
}

test/fetch/issue-4105.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
3+
const { once } = require('node:events')
4+
const { createServer } = require('node:http')
5+
const { test } = require('node:test')
6+
const { fetch } = require('../..')
7+
const { tspl } = require('@matteo.collina/tspl')
8+
const { PerformanceObserver } = require('node:perf_hooks')
9+
10+
const isAtLeastv22 = process.versions.node.split('.').map(Number)[0] >= 22
11+
12+
// https://github.com/nodejs/undici/issues/4105
13+
test('markResourceTiming responseStatus is set', { skip: !isAtLeastv22 }, async (t) => {
14+
const { completed, deepEqual } = tspl(t, { plan: 1 })
15+
16+
const server = createServer((req, res) => {
17+
res.statusCode = 200
18+
res.end('Hello World')
19+
}).listen(3000)
20+
21+
t.after(server.close.bind(server))
22+
await once(server, 'listening')
23+
24+
new PerformanceObserver(items => {
25+
items.getEntries().forEach(entry => {
26+
deepEqual(entry.responseStatus, 200)
27+
})
28+
}).observe({ type: 'resource', buffered: true })
29+
30+
const response = await fetch('http://localhost:3000')
31+
await response.text()
32+
33+
await completed
34+
})

0 commit comments

Comments
 (0)