Skip to content

Commit

Permalink
fix: don't uppercase unknown methods (#1542)
Browse files Browse the repository at this point in the history
* fix: don't uppercase unknown methods
  • Loading branch information
lynxtaa committed Apr 28, 2022
1 parent c33e393 commit 004b3ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/request.js
Expand Up @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions test/request.js
Expand Up @@ -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, {
Expand Down

0 comments on commit 004b3ac

Please sign in to comment.