Sindre Sorhus 10 years ago
parent
commit
082f4fd1d9
  1. 6
      index.js
  2. 3
      test/test-stream.js

6
index.js

@ -12,7 +12,7 @@ var timedOut = require('timed-out');
var prependHttp = require('prepend-http');
var lowercaseKeys = require('lowercase-keys');
var isRedirect = require('is-redirect');
var pinkiePromise = require('pinkie-promise');
var PinkiePromise = require('pinkie-promise');
var unzipResponse = require('unzip-response');
var createErrorClass = require('create-error-class');
@ -102,7 +102,7 @@ function asCallback(opts, cb) {
}
function asPromise(opts) {
return new pinkiePromise(function (resolve, reject) {
return new PinkiePromise(function (resolve, reject) {
asCallback(opts, function (err, data, response) {
response.body = data;
@ -180,6 +180,7 @@ function normalizeArguments(url, opts) {
}, lowercaseKeys(opts.headers));
var query = opts.query;
if (query) {
if (typeof query !== 'string') {
opts.query = querystring.stringify(query);
@ -194,6 +195,7 @@ function normalizeArguments(url, opts) {
}
var body = opts.body;
if (body) {
if (typeof body !== 'string' && !Buffer.isBuffer(body) && !isStream.readable(body)) {
throw new Error('options.body must be a ReadableStream, string or Buffer');

3
test/test-stream.js

@ -1,5 +1,4 @@
'use strict';
var test = require('tap').test;
var got = require('../');
var server = require('./server.js');
@ -69,7 +68,7 @@ test('request event', function (t) {
test('redirect event', function (t) {
got.stream(s.url + '/redirect')
.on('redirect', function (res, opts) {
.on('redirect', function (res) {
t.equal(res.headers.location, s.url);
t.end();
});

Loading…
Cancel
Save