Browse Source

Use camelCase names

http2
Kevin Martensson 10 years ago
parent
commit
403fefa01a
  1. 22
      index.js
  2. 8
      test/test-post.js
  3. 6
      test/test-redirects.js

22
index.js

@ -8,19 +8,19 @@ var objectAssign = require('object-assign');
var agent = require('infinity-agent');
var duplexify = require('duplexify');
var isStream = require('is-stream');
var read = require('read-all-stream');
var timeout = require('timed-out');
var readAllStream = require('read-all-stream');
var timedOut = require('timed-out');
var prependHttp = require('prepend-http');
var lowercaseKeys = require('lowercase-keys');
var status = require('statuses');
var NestedError = require('nested-error-stacks');
var statuses = require('statuses');
var NestedErrorStacks = require('nested-error-stacks');
function GotError(message, nested) {
NestedError.call(this, message, nested);
NestedErrorStacks.call(this, message, nested);
objectAssign(this, nested, {nested: this.nested});
}
util.inherits(GotError, NestedError);
util.inherits(GotError, NestedErrorStacks);
GotError.prototype.name = 'GotError';
function got(url, opts, cb) {
@ -86,7 +86,7 @@ function got(url, opts, cb) {
}
// redirect
if (status.redirect[statusCode] && 'location' in res.headers) {
if (statuses.redirect[statusCode] && 'location' in res.headers) {
res.resume(); // Discard response
if (++redirectCount > 10) {
@ -105,8 +105,8 @@ function got(url, opts, cb) {
}
if (statusCode < 200 || statusCode > 299) {
read(res, encoding, function (err, data) {
err = new GotError(url + ' response code is ' + statusCode + ' (' + status[statusCode] + ')', err);
readAllStream(res, encoding, function (err, data) {
err = new GotError(url + ' response code is ' + statusCode + ' (' + statuses[statusCode] + ')', err);
err.code = statusCode;
if (data && json) {
@ -128,7 +128,7 @@ function got(url, opts, cb) {
return;
}
read(res, encoding, function (err, data) {
readAllStream(res, encoding, function (err, data) {
if (err) {
err = new GotError('Reading ' + url + ' response failed', err);
} else if (json) {
@ -146,7 +146,7 @@ function got(url, opts, cb) {
});
if (opts.timeout) {
timeout(req, opts.timeout);
timedOut(req, opts.timeout);
}
if (!proxy) {

8
test/test-post.js

@ -1,6 +1,6 @@
'use strict';
var tape = require('tape');
var from = require('from2-array');
var from2Array = require('from2-array');
var got = require('../');
var server = require('./server.js');
var s = server.createServer();
@ -27,7 +27,7 @@ tape('setup', function (t) {
tape('GET can have body', function (t) {
t.plan(3);
var stream = from(['wow']);
var stream = from2Array(['wow']);
stream.on('end', function () {
t.ok(true); // Ensure, that stream was dumped
});
@ -49,7 +49,7 @@ tape('send data from options with post request', function (t) {
t.equal(data, 'wow');
});
got(s.url, {body: from(['wow'])}, function (err, data) {
got(s.url, {body: from2Array(['wow'])}, function (err, data) {
t.equal(data, 'wow');
});
});
@ -62,7 +62,7 @@ tape('works with empty post response', function (t) {
});
tape('return readable stream', function (t) {
got.post(s.url, {body: from(['wow'])})
got.post(s.url, {body: from2Array(['wow'])})
.on('data', function (data) {
t.equal(data.toString(), 'wow');
t.end();

6
test/test-redirects.js

@ -6,21 +6,21 @@ var s = server.createServer();
s.on('/finite', function (req, res) {
res.writeHead(302, {
location : s.url + '/'
location: s.url + '/'
});
res.end();
});
s.on('/endless', function (req, res) {
res.writeHead(302, {
location : s.url + '/endless'
location: s.url + '/endless'
});
res.end();
});
s.on('/relative', function (req, res) {
res.writeHead(302, {
location : '/'
location: '/'
});
res.end();
});

Loading…
Cancel
Save