Skip to content

Commit

Permalink
Convert verb to uppercase
Browse files Browse the repository at this point in the history
In Google Chrome, `patch` specifically seems to be causing problems. I'd been Googling for about an hour and finally came across this SO post: https://stackoverflow.com/a/67744766/51021

Apparently, some verbs (`PATCH` in my case) ARE case-sensitive when comparing against a pre-flight `OPTIONS` check.

I think in order to be the most compatible with the `axios` module, and to make `PATCH` work during cross-origin requests, these verbs should be made uppercase (See `axios` source: [axios/lib/adapters/xhr.js#L32](https://github.com/axios/axios/blob/5ad6994/lib/adapters/xhr.js#L32))
  • Loading branch information
sirlancelot committed Aug 5, 2021
1 parent f963b6f commit 8ceecd7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default (function create(/** @type {Options} */ defaults) {
const fetchFunc = options.fetch || fetch;

return fetchFunc(url, {
method: _method || options.method,
method: (_method || options.method || 'get').toUpperCase(),
body: data,
headers: deepMerge(options.headers, customHeaders, true),
credentials: options.withCredentials ? 'include' : 'same-origin'
Expand Down
8 changes: 4 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('redaxios', () => {
expect(window.fetch).toHaveBeenCalledWith(
'http://foo/bar',
jasmine.objectContaining({
method: 'get',
method: 'GET',
headers: {},
body: undefined
})
Expand All @@ -112,7 +112,7 @@ describe('redaxios', () => {
expect(window.fetch).toHaveBeenCalledWith(
'/foo/bar',
jasmine.objectContaining({
method: 'get',
method: 'GET',
headers: {},
body: undefined
})
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('redaxios', () => {
expect(fetchMock).toHaveBeenCalledWith(
'/foo',
jasmine.objectContaining({
method: 'post',
method: 'POST',
headers: {
'content-type': 'application/json'
},
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('redaxios', () => {
expect(fetchMock).toHaveBeenCalledWith(
'/foo',
jasmine.objectContaining({
method: 'post',
method: 'POST',
headers: {
'content-type': 'multipart/form-data'
},
Expand Down

0 comments on commit 8ceecd7

Please sign in to comment.