diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4e2052883..6d231e87d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ Thank you for considering to contribute to `node-fetch` 💖 -Please note that this project is released with a [Contributor Code of Conduct][./CODE_OF_CONDUCT.md]. +Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating you agree to abide by its terms. ## Setup diff --git a/README.md b/README.md index 6b27b2a06..37fd608f1 100644 --- a/README.md +++ b/README.md @@ -669,7 +669,7 @@ See [options](#fetch-options) for exact meaning of these extensions. _(spec-compliant)_ - `input` A string representing a URL, or another `Request` (which will be cloned) -- `options` [Options][#fetch-options] for the HTTP(S) request +- `options` [Options](#fetch-options) for the HTTP(S) request Constructs a new `Request` object. The constructor is identical to that in the [browser](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request). diff --git a/src/request.js b/src/request.js index a4d1b2209..a63f7e606 100644 --- a/src/request.js +++ b/src/request.js @@ -61,7 +61,9 @@ export default class Request extends Body { } let method = init.method || input.method || 'GET'; - method = method.toUpperCase(); + if (/^(delete|get|head|options|post|put)$/i.test(method)) { + method = method.toUpperCase(); + } if ('data' in init) { doBadDataWarn(); diff --git a/test/request.js b/test/request.js index b8ba107e9..03cbe3cf1 100644 --- a/test/request.js +++ b/test/request.js @@ -151,6 +151,24 @@ describe('Request', () => { expect(request.headers.get('a')).to.equal('1'); }); + it('should uppercase DELETE, GET, HEAD, OPTIONS, POST and PUT methods', () => { + const url = base; + for (const method of ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']) { + const request = new Request(url, { + method: method.toLowerCase() + }); + expect(request.method).to.equal(method); + } + }); + + it('should not uppercase unknown methods and patch', () => { + const url = base; + for (const method of ['patch', 'chicken']) { + const request = new Request(url, {method}); + expect(request.method).to.equal(method); + } + }); + it('should support arrayBuffer() method', () => { const url = base; const request = new Request(url, {