Browse Source

convert method to uppercase in options

Closes #164
http2
Vsevolod Strukchinsky 9 years ago
parent
commit
f9ef29a3fc
  1. 6
      index.js
  2. 5
      test/post.js

6
index.js

@ -243,6 +243,8 @@ function normalizeArguments(url, opts) {
opts.method = opts.method || 'GET';
opts.method = opts.method.toUpperCase();
if (opts.hostname === 'unix') {
const matches = /(.+)\:(.+)/.exec(opts.path);
@ -286,7 +288,7 @@ const helpers = [
];
helpers.forEach(el => {
got[el] = (url, opts) => got(url, Object.assign({}, opts, {method: el.toUpperCase()}));
got[el] = (url, opts) => got(url, Object.assign({}, opts, {method: el}));
});
got.stream = function (url, opts) {
@ -295,7 +297,7 @@ got.stream = function (url, opts) {
helpers.forEach(el => {
got.stream[el] = function (url, opts) {
return got.stream(url, Object.assign({}, opts, {method: el.toUpperCase()}));
return got.stream(url, Object.assign({}, opts, {method: el}));
};
});

5
test/post.js

@ -109,6 +109,11 @@ test('content-type header is not overriden when object in options.body', async t
t.is(body['content-type'], 'doge');
});
test('transforms method to uppercase', async t => {
const headers = (await got(s.url, {method: 'get'})).headers;
t.is(headers.method, 'GET');
});
test.after('cleanup', async () => {
await s.close();
});

Loading…
Cancel
Save