Browse Source

Move all code for options.body in one place

http2
Vsevolod Strukchinsky 10 years ago
parent
commit
3c06cca002
  1. 8
      index.js

8
index.js

@ -61,6 +61,10 @@ function got(url, opts, cb) {
}
if (body) {
if (typeof body !== 'string' && !Buffer.isBuffer(body) && !isStream.readable(body)) {
throw new GotError('options.body must be a ReadableStream, string or Buffer');
}
opts.method = opts.method || 'POST';
if (!opts.headers['content-length'] && !opts.headers['transfer-encoding'] && !isStream.readable(body)) {
@ -86,10 +90,6 @@ function got(url, opts, cb) {
throw new GotError('got can not be used as stream when options.json is used');
}
if (body && !(typeof body === 'string' || Buffer.isBuffer(body) || isStream.readable(body))) {
throw new GotError('options.body must be a ReadableStream, string or Buffer');
}
function get(url, opts, cb) {
var parsedUrl = typeof url === 'string' ? urlLib.parse(prependHttp(url)) : url;
var fn = parsedUrl.protocol === 'https:' ? https : http;

Loading…
Cancel
Save