mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Merge pull request #36733 from overleaf/dk-fetch-utils-unset-headers
[fetch-utils] Drop headers with unset values GitOrigin-RevId: 284b8551dfc3b15315a873a9256fbf9f35e4004b
This commit is contained in:
@@ -184,6 +184,52 @@ describe('fetch-utils', function () {
|
||||
expect(server.lastReq.headers['x-foo']).to.equal('bar')
|
||||
})
|
||||
|
||||
it('treats an unset Accept header as absent and applies the default', async function () {
|
||||
await fetchJson(url('/json/hello'), {
|
||||
headers: { Accept: undefined },
|
||||
})
|
||||
expect(server.lastReq.headers.accept).to.equal('application/json')
|
||||
})
|
||||
|
||||
it('omits headers with unset values rather than sending "undefined"', async function () {
|
||||
await fetchJson(url('/json/hello'), {
|
||||
headers: { 'x-some-value': undefined, 'x-other-value': null },
|
||||
})
|
||||
expect(server.lastReq.headers).to.not.have.property('x-some-value')
|
||||
expect(server.lastReq.headers).to.not.have.property('x-other-value')
|
||||
})
|
||||
|
||||
it('omits headers with unset values provided as an array of tuples', async function () {
|
||||
await fetchJson(url('/json/hello'), {
|
||||
headers: [
|
||||
['X-Foo', 'bar'],
|
||||
['X-Unset', undefined],
|
||||
],
|
||||
})
|
||||
expect(server.lastReq.headers['x-foo']).to.equal('bar')
|
||||
expect(server.lastReq.headers).to.not.have.property('x-unset')
|
||||
})
|
||||
|
||||
it('omits headers with unset values provided as a Map', async function () {
|
||||
await fetchJson(url('/json/hello'), {
|
||||
headers: new Map([
|
||||
['X-Foo', 'bar'],
|
||||
['X-Unset', undefined],
|
||||
]),
|
||||
})
|
||||
expect(server.lastReq.headers['x-foo']).to.equal('bar')
|
||||
expect(server.lastReq.headers).to.not.have.property('x-unset')
|
||||
})
|
||||
|
||||
it('keeps headers provided as a global Headers instance', async function () {
|
||||
// Not an instance of node-fetch's Headers: it exposes no own
|
||||
// enumerable properties to iterate over.
|
||||
await fetchJson(url('/json/hello'), {
|
||||
headers: new globalThis.Headers({ 'X-Foo': 'bar' }),
|
||||
})
|
||||
expect(server.lastReq.headers['x-foo']).to.equal('bar')
|
||||
})
|
||||
|
||||
it('sets a Content-Type header of application/json when sending a JSON body', async function () {
|
||||
await fetchJson(url('/json/add'), {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user