From ece1e16864d4599a50c9e3d2c1279e04e47d4802 Mon Sep 17 00:00:00 2001 From: Alex Kondratyuk Date: Mon, 25 Apr 2022 15:02:15 +0300 Subject: [PATCH 1/3] fix: don't uppercase unknown methods --- src/request.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/request.js b/src/request.js index a4d1b2209..9b79ee59c 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(); From f9d830ae786436dd83ed2581052cc5f5ada587ad Mon Sep 17 00:00:00 2001 From: Alex Kondratyuk Date: Wed, 27 Apr 2022 23:23:43 +0300 Subject: [PATCH 2/3] add tests --- test/request.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/request.js b/test/request.js index b8ba107e9..380da0a54 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, { From 3a58b04c8076f8b492d83fc9eb5fabe3cf7fe99e Mon Sep 17 00:00:00 2001 From: Alex Kondratyuk Date: Thu, 28 Apr 2022 00:30:54 +0300 Subject: [PATCH 3/3] fix lint --- src/request.js | 2 +- test/request.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/request.js b/src/request.js index 9b79ee59c..a63f7e606 100644 --- a/src/request.js +++ b/src/request.js @@ -61,7 +61,7 @@ export default class Request extends Body { } let method = init.method || input.method || 'GET'; - if (/^(DELETE|GET|HEAD|OPTIONS|POST|PUT)$/i.test(method)) { + if (/^(delete|get|head|options|post|put)$/i.test(method)) { method = method.toUpperCase(); } diff --git a/test/request.js b/test/request.js index 380da0a54..03cbe3cf1 100644 --- a/test/request.js +++ b/test/request.js @@ -155,7 +155,7 @@ describe('Request', () => { const url = base; for (const method of ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']) { const request = new Request(url, { - method: method.toLowerCase(), + method: method.toLowerCase() }); expect(request.method).to.equal(method); } @@ -163,8 +163,8 @@ describe('Request', () => { it('should not uppercase unknown methods and patch', () => { const url = base; - for (const method of ['patch', 'chicken',]) { - const request = new Request(url, { method }); + for (const method of ['patch', 'chicken']) { + const request = new Request(url, {method}); expect(request.method).to.equal(method); } });