Skip to content

Commit 004b3ac

Browse files
authored
fix: don't uppercase unknown methods (node-fetch#1542)
* fix: don't uppercase unknown methods
1 parent c33e393 commit 004b3ac

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/request.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export default class Request extends Body {
6161
}
6262

6363
let method = init.method || input.method || 'GET';
64-
method = method.toUpperCase();
64+
if (/^(delete|get|head|options|post|put)$/i.test(method)) {
65+
method = method.toUpperCase();
66+
}
6567

6668
if ('data' in init) {
6769
doBadDataWarn();

test/request.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ describe('Request', () => {
151151
expect(request.headers.get('a')).to.equal('1');
152152
});
153153

154+
it('should uppercase DELETE, GET, HEAD, OPTIONS, POST and PUT methods', () => {
155+
const url = base;
156+
for (const method of ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']) {
157+
const request = new Request(url, {
158+
method: method.toLowerCase()
159+
});
160+
expect(request.method).to.equal(method);
161+
}
162+
});
163+
164+
it('should not uppercase unknown methods and patch', () => {
165+
const url = base;
166+
for (const method of ['patch', 'chicken']) {
167+
const request = new Request(url, {method});
168+
expect(request.method).to.equal(method);
169+
}
170+
});
171+
154172
it('should support arrayBuffer() method', () => {
155173
const url = base;
156174
const request = new Request(url, {

0 commit comments

Comments
 (0)