fix: don't uppercase unknown methods (#1542)

* fix: don't uppercase unknown methods
This commit is contained in:
Alex Kondratyuk 2022-04-28 12:33:26 +03:00 committed by GitHub
parent c33e393c47
commit 004b3ac832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -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();

View File

@ -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, {