Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/web/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
originalURL.href,
initiatorType,
globalThis,
cacheState
cacheState,
'', // bodyType
response.status
)
}

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

Expand Down Expand Up @@ -1036,7 +1038,6 @@ function fetchFinale (fetchParams, response) {
// fetchParams’s request’s URL, fetchParams’s request’s initiator type, global, cacheState, bodyInfo,
// and responseStatus.
if (fetchParams.request.initiatorType != null) {
// TODO: update markresourcetiming
markResourceTiming(timingInfo, fetchParams.request.url.href, fetchParams.request.initiatorType, globalThis, cacheState, bodyInfo, responseStatus)
}
}
Expand Down
34 changes: 34 additions & 0 deletions test/fetch/issue-4105.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

const { once } = require('node:events')
const { createServer } = require('node:http')
const { test } = require('node:test')
const { fetch } = require('../..')
const { tspl } = require('@matteo.collina/tspl')
const { PerformanceObserver } = require('node:perf_hooks')

const isAtLeastv22 = process.versions.node.split('.').map(Number)[0] >= 22

// https://github.com/nodejs/undici/issues/4105
test('markResourceTiming responseStatus is set', { skip: !isAtLeastv22 }, async (t) => {
const { completed, deepEqual } = tspl(t, { plan: 1 })

const server = createServer((req, res) => {
res.statusCode = 200
res.end('Hello World')
}).listen(3000)

t.after(server.close.bind(server))
await once(server, 'listening')

new PerformanceObserver(items => {
items.getEntries().forEach(entry => {
deepEqual(entry.responseStatus, 200)
})
}).observe({ type: 'resource', buffered: true })

const response = await fetch('http://localhost:3000')
await response.text()

await completed
})
Loading