Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function mergeRequestInit(
): RequestInit {
const headers = new Headers(first?.headers)
const other = new Headers(second?.headers)

for (const key of other.keys()) {
const value = other.get(key)
if (value != null) {
Expand All @@ -113,7 +113,7 @@ function getFetchParams(request: Request) {

const path = getPath(request.path, payload)
const query = getQuery(request.method, payload, request.queryParams)
const headers = getHeaders(request.init?.headers)
const headers = sendBody(request.method) ? getHeaders(request.init?.headers): new Headers(request.init?.headers)
const url = request.baseUrl + path + query

const init = {
Expand Down
10 changes: 7 additions & 3 deletions test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ describe('fetch', () => {
})

const expectedHeaders = {
authorization: 'Bearer token',
authorization: 'Bearer token'
}

const expectedHeadersWithBody = {
...expectedHeaders,
'content-type': 'application/json',
accept: 'application/json',
}
Expand Down Expand Up @@ -60,7 +64,7 @@ describe('fetch', () => {
expect(data.params).toEqual({ id: '1' })
expect(data.body).toEqual({ list: ['b', 'c'] })
expect(data.query).toEqual({})
expect(data.headers).toEqual(expectedHeaders)
expect(data.headers).toEqual(expectedHeadersWithBody)
})
})

Expand All @@ -80,7 +84,7 @@ describe('fetch', () => {
expect(data.params).toEqual({ id: '1' })
expect(data.body).toEqual({ list: ['b', 'c'] })
expect(data.query).toEqual({ scalar: 'a' })
expect(data.headers).toEqual(expectedHeaders)
expect(data.headers).toEqual(expectedHeadersWithBody)
})
})

Expand Down