Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't uppercase unknown methods #1542

Merged
merged 3 commits into from Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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