Skip to content

Commit

Permalink
fix a small oversight in request class
Browse files Browse the repository at this point in the history
lowercase method name does not trigger type error properly (#362)
  • Loading branch information
bitinn authored Nov 19, 2017
1 parent 6192398 commit 3345b65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class Request {
}

let method = init.method || input.method || 'GET';
method = method.toUpperCase();

if ((init.body != null || input instanceof Request && input.body !== null) &&
(method === 'GET' || method === 'HEAD')) {
Expand All @@ -58,7 +59,7 @@ export default class Request {
});

// fetch spec options
this.method = method.toUpperCase();
this.method = method;
this.redirect = init.redirect || input.redirect || 'follow';
this.headers = new Headers(init.headers || input.headers || {});

Expand Down
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,10 @@ describe('node-fetch', () => {
.to.throw(TypeError);
expect(() => new Request('.', { body: 'a', method: 'HEAD' }))
.to.throw(TypeError);
expect(() => new Request('.', { body: 'a', method: 'get' }))
.to.throw(TypeError);
expect(() => new Request('.', { body: 'a', method: 'head' }))
.to.throw(TypeError);
});

it('should support empty options in Response constructor', function() {
Expand Down

0 comments on commit 3345b65

Please sign in to comment.