Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fetch] 5.1.0 regressed ability to intercept headers #1392

Closed
panva opened this issue May 1, 2022 · 3 comments · Fixed by #1393
Closed

[fetch] 5.1.0 regressed ability to intercept headers #1392

panva opened this issue May 1, 2022 · 3 comments · Fixed by #1393
Labels
bug Something isn't working

Comments

@panva
Copy link
Member

panva commented May 1, 2022

Bug Description

Intercepting upon individual headers when using fetch is broken in 5.1.0, worked fine in 5.0.0

#1309 and possibly lack of test coverage for this is imho the likely suspect

Reproducible By

import * as undici from 'undici'
import * as assert from 'node:assert'

const mockAgent = new undici.MockAgent()
mockAgent.disableNetConnect()
undici.setGlobalDispatcher(mockAgent)
const pool = mockAgent.get('https://example.com')
pool.intercept({
  path: '/foo',
  method: 'GET',
  headers: {
    accept: 'application/json'
  }
}).reply(200, { ok: 1 })

const response = await undici.fetch('https://example.com/foo', {
  headers: {
    accept: 'application/json'
  }
})

assert.deepStrictEqual(await response.json(), { ok: 1 })

Expected Behavior

fetch gets matched intercepted

Logs & Screenshots

TypeError: fetch failed
  cause: MockNotMatchedError: Mock dispatch not matched for headers '["accept","application/json","accept-language","*","sec-fetch-mode","cors","user-agent","undici","accept-encoding","br, gzip, deflate"]': subsequent request to origin https://example.com was not allowed (net.connect disabled)

Environment

Node 18.0.0

Additional context

Matching headers with a function works as expected.

@panva panva added the bug Something isn't working label May 1, 2022
@panva
Copy link
Member Author

panva commented May 1, 2022

cc @RafaelGSS

@mcollina
Copy link
Member

mcollina commented May 1, 2022

@KhafraDev could you take a look?

@KhafraDev
Copy link
Member

KhafraDev commented May 1, 2022

I'll look into it 👍

I don't think this is caused by one of my changes though, I never really used/touched the matching section.

edit: I found the bug, it was caused by the recent changes to the Headers structure in fetch. I should have a PR relatively soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants