Skip to content

Commit

Permalink
fix: check response for timinginfo allow flag (#2477)
Browse files Browse the repository at this point in the history
* fix: check response for timinginfo allow flag

* Update test/fetch/resource-timing.js

---------

Co-authored-by: Khafra <maitken033380023@gmail.com>
  • Loading branch information
ToshB and KhafraDev committed Nov 29, 2023
1 parent c5d73ca commit 19c69a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
}

// 8. If response’s timing allow passed flag is not set, then:
if (!timingInfo.timingAllowPassed) {
if (!response.timingAllowPassed) {
// 1. Set timingInfo to a the result of creating an opaque timing info for timingInfo.
timingInfo = createOpaqueTimingInfo({
startTime: timingInfo.startTime
Expand Down
24 changes: 24 additions & 0 deletions test/fetch/resource-timing.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,27 @@ test('should create a PerformanceResourceTiming after each fetch request', { ski

t.teardown(server.close.bind(server))
})

test('should include encodedBodySize in performance entry', { skip }, (t) => {
t.plan(4)
const obs = new PerformanceObserver(list => {
const [entry] = list.getEntries()
t.equal(entry.encodedBodySize, 2)
t.equal(entry.decodedBodySize, 2)
t.equal(entry.transferSize, 2 + 300)

obs.disconnect()
performance.clearResourceTimings()
})

obs.observe({ entryTypes: ['resource'] })

const server = createServer((req, res) => {
res.end('ok')
}).listen(0, async () => {
const body = await fetch(`http://localhost:${server.address().port}`)
t.strictSame('ok', await body.text())
})

t.teardown(server.close.bind(server))
})

0 comments on commit 19c69a0

Please sign in to comment.