Socket
Socket
Sign inDemoInstall

superagent

Package Overview
Dependencies
Maintainers
10
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superagent - npm Package Compare versions

Comparing version 4.0.0-alpha.1 to 4.0.0-beta.5

dump.js

62

docs/index.md

@@ -11,3 +11,3 @@

.set('Accept', 'application/json')
.then(function(res) {
.then(res => {
alert('yay got ' + JSON.stringify(res.body));

@@ -18,3 +18,3 @@ });

The following [test documentation](docs/test.html) was generated with [Mocha's](http://mochajs.org/) "doc" reporter, and directly reflects the test suite. This provides an additional source of documentation.
The following [test documentation](docs/test.html) was generated with [Mocha's](https://mochajs.org/) "doc" reporter, and directly reflects the test suite. This provides an additional source of documentation.

@@ -27,6 +27,6 @@ ## Request basics

.get('/search')
.then(function(res) {
.then(res => {
// res.body, res.headers, res.status
})
.catch(function(err) {
.catch(err => {
// err.message, err.response

@@ -39,3 +39,3 @@ });

Old-style callbacks are also supported. *Instead of* `.then()` you can call `.end()`:
Old-style callbacks are also supported, but not recommended. *Instead of* `.then()` you can call `.end()`:

@@ -49,8 +49,8 @@ request('GET', '/search').end(function(err, res){

request
.get('http://example.com/search')
.then(function(res) {
.get('https://example.com/search')
.then(res => {
});
The __Node__ client supports making requests to [Unix Domain Sockets](http://en.wikipedia.org/wiki/Unix_domain_socket):
The __Node__ client supports making requests to [Unix Domain Sockets](https://en.wikipedia.org/wiki/Unix_domain_socket):

@@ -69,3 +69,3 @@ // pattern: https?+unix://SOCKET_PATH/REQUEST_PATH

.head('/favicon.ico')
.then(function(res) {
.then(res => {

@@ -78,3 +78,3 @@ });

request('/search', function(err, res){
request('/search', (err, res) => {

@@ -109,3 +109,3 @@ });

.query({ order: 'desc' })
.then(function(res) {
.then(res => {

@@ -119,3 +119,3 @@ });

.query({ query: 'Manny', range: '1..5', order: 'desc' })
.then(function(res) {
.then(res => {

@@ -129,3 +129,3 @@ });

.query('search=Manny&range=1..5')
.then(function(res) {
.then(res => {

@@ -140,3 +140,3 @@ });

.query('range=1..5')
.then(function(res) {
.then(res => {

@@ -152,3 +152,3 @@ });

.query({ email: 'joe@smith.com' })
.then(function(res) {
.then(res => {

@@ -231,4 +231,4 @@ });

//going forward, all requests with a Content-type of
//'application/xml' will be automatically serialized
// going forward, all requests with a Content-type of
// 'application/xml' will be automatically serialized
```

@@ -242,3 +242,3 @@ If you want to send the payload in a custom format, you can replace

.send({foo: 'bar'})
.serialize(function serializer(obj) {
.serialize(obj => {
return 'string generated from obj';

@@ -254,3 +254,3 @@ });

request
.get('http://example.com/search')
.get('https://example.com/search')
.retry(2) // or:

@@ -304,5 +304,3 @@ .retry(2, callback)

.query('search=Manny')
.sortQuery(function(a, b){
return a.length - b.length;
})
.sortQuery((a, b) => a.length - b.length)
.then(callback)

@@ -402,3 +400,3 @@ ```

.responseType('blob')
.end(function (error, res) {
.then(res => {
// res.body will be a browser native Blob type here

@@ -464,7 +462,7 @@ });

* `req.timeout({deadline:ms})` or `req.timeout(ms)` (where `ms` is a number of milliseconds > 0) sets a deadline for the entire request (including all redirects) to complete. If the response isn't fully downloaded within that time, the request will be aborted.
* `req.timeout({deadline:ms})` or `req.timeout(ms)` (where `ms` is a number of milliseconds > 0) sets a deadline for the entire request (including all uploads, redirects, server processing time) to complete. If the response isn't fully downloaded within that time, the request will be aborted.
* `req.timeout({response:ms})` sets maximum time to wait for the first byte to arrive from the server, but it does not limit how long the entire download can take. Response timeout should be a few seconds longer than just the time it takes server to respond, because it also includes time to make DNS lookup, TCP/IP and TLS connections.
* `req.timeout({response:ms})` sets maximum time to wait for the first byte to arrive from the server, but it does not limit how long the entire download can take. Response timeout should be at least few seconds longer than just the time it takes the server to respond, because it also includes time to make DNS lookup, TCP/IP and TLS connections, and time to upload request data.
You should use both `deadline` and `response` timeouts. This way you can use a short response timeout to detect unresponsive networks quickly, and a long deadline to give time for downloads on slow, but reliable, networks.
You should use both `deadline` and `response` timeouts. This way you can use a short response timeout to detect unresponsive networks quickly, and a long deadline to give time for downloads on slow, but reliable, networks. Note that both of these timers limit how long *uploads* of attached files are allowed to take. Use long timeouts if you're uploading files.

@@ -630,5 +628,5 @@ request

request
.get('http://api.example.com:4001/')
.get('https://api.example.com:4001/')
.withCredentials()
.then(function(res) {
.then(res => {
assert.equal(200, res.status);

@@ -645,3 +643,3 @@ assert.equal('tobi', res.text);

.attach('image', 'path/to/tobi.png')
.then(function(res) {
.then(res => {

@@ -656,3 +654,3 @@ });

.on('error', handle)
.then(function(res) {
.then(res => {

@@ -697,3 +695,3 @@ });

})
.end()
.then()

@@ -723,2 +721,2 @@ ## Promise and Generator support

[Electron](http://electron.atom.io/) developers report if you would prefer to use the browser version of SuperAgent instead of the Node version, you can `require('superagent/superagent')`. Your requests will now show up in the Chrome developer tools Network tab. Note this environment is not covered by automated test suite and not officially supported.
[Electron](https://electron.atom.io/) developers report if you would prefer to use the browser version of SuperAgent instead of the Node version, you can `require('superagent/superagent')`. Your requests will now show up in the Chrome developer tools Network tab. Note this environment is not covered by automated test suite and not officially supported.

@@ -5,6 +5,9 @@ # 4.0.0

* Node.js v4 has reached it's end of life, so we no longer support it. It's v6+ or later.
* Node.js v4 has reached it's end of life, so we no longer support it. It's v6+ or later. We recommend Node.js 10.
* We now use ES6 in the browser code, too.
* If you're using Browserify or Webpack to package code for Internet Explorer, you will also have to use Babel.
* The pre-built node_modules/superagent.js is still ES5-compatible.
* `.end(…)` returns `undefined` instead of the request. If you need the request object after calling `.end()` (and you probably don't), save it in a variable and call `request.end(…)`. Consider not using `.end()` at all, and migrating to promises by calling `.then()` instead.
* In Node, responses with unknown MIME type are buffered by default. To get old behavior, if you use custom *unbuffered* parsers, add `.buffer(false)` to requests or set `superagent.buffer[yourMimeType] = false`.
* Invalid uses of `.pipe()` throw.

@@ -20,2 +23,3 @@ ## Minor changes

* Allow default buffer settings based on response-type (shrey)
* `response.buffered` is more accurate.

@@ -22,0 +26,0 @@ # 3.8.3 (2018-04-29)

@@ -676,3 +676,3 @@ /**

return this._end();
this._end();
};

@@ -776,3 +776,2 @@

xhr.send(typeof data !== 'undefined' ? data : null);
return this;
};

@@ -779,0 +778,0 @@

@@ -18,3 +18,2 @@ 'use strict';

const unzip = require('./unzip').unzip;
const extend = require('extend');
const mime = require('mime');

@@ -30,2 +29,8 @@ const https = require('https');

const CookieJar = require('cookiejar');
let http2;
try {
http2 = require('./http2wrapper');
console.warn('superagent: Enable experimental feature http2');
} catch (_) {
}

@@ -86,2 +91,3 @@ function request(method, url) {

'https:': https,
'http2:': http2,
};

@@ -150,2 +156,3 @@

if ('string' != typeof url) url = format(url);
this._enableHttp2 = !!process.env.HTTP2_TEST; // internal only
this._agent = false;

@@ -176,2 +183,39 @@ this._formData = null;

/**
* Enable or Disable http2.
*
* Enable http2.
*
* ``` js
* request.get('http://localhost/')
* .http2()
* .end(callback);
*
* request.get('http://localhost/')
* .http2(true)
* .end(callback);
* ```
*
* Disable http2.
*
* ``` js
* request = request.http2();
* request.get('http://localhost/')
* .http2(false)
* .end(callback);
* ```
*
* @param {Boolean} enable
* @return {Request} for chaining
* @api public
*/
Request.prototype.http2 = function(bool){
if (exports.protocols['http2:'] === undefined){
throw new Error('superagent: does not support http2');
}
this._enableHttp2 = bool === undefined ? true : bool;
return this;
}
/**
* Queue the given `file` as an attachment to the specified `field`,

@@ -327,3 +371,3 @@ * with optional `options` (or filename).

} else {
extend(this.qs, val);
Object.assign(this.qs, val);
}

@@ -513,3 +557,3 @@ return this;

const encoder = string => new Buffer(string).toString('base64');
const encoder = string => new Buffer.from(string).toString('base64');

@@ -659,3 +703,3 @@ return this._auth(user, pass, options, encoder);

// initiate request
const mod = exports.protocols[url.protocol];
const mod = this._enableHttp2 ? exports.protocols['http2:'].setProtocol(url.protocol) : exports.protocols[url.protocol];

@@ -706,6 +750,6 @@ // request

if (this.cookies) {
if(this.header.hasOwnProperty('cookie')) {
if(this._header.hasOwnProperty('cookie')) {
// merge
const tmpJar = new CookieJar.CookieJar();
tmpJar.setCookies(this.header.cookie.split(';'));
tmpJar.setCookies(this._header.cookie.split(';'));
tmpJar.setCookies(this.cookies.split(';'));

@@ -801,2 +845,7 @@ req.setHeader('Cookie',tmpJar.getCookies(CookieJar.CookieAccessInfo.All).toValueString());

response.files = files;
if (this._endCalled) {
response.pipe = function() {
throw Error("end() has already been called, so it's too late to start piping");
}
}
this.emit('response', response);

@@ -811,4 +860,4 @@ return response;

if (this._endCalled) {
console.warn(
'Warning: .end() was called twice. This is not supported in superagent'
throw Error(
'.end() was called twice. This is not supported in superagent'
);

@@ -821,3 +870,3 @@ }

return this._end();
this._end();
};

@@ -830,3 +879,2 @@

const req = this.req;
let buffer = this._buffer;
const method = this.method;

@@ -843,3 +891,3 @@

if (contentType) contentType = contentType.split(';')[0];
let serialize = exports.serialize[contentType];
let serialize = this._serializer || exports.serialize[contentType];
if (!serialize && isJSON(contentType)) {

@@ -874,3 +922,2 @@ serialize = exports.serialize['application/json'];

const redirect = isRedirect(res.statusCode);
let parser = this._parser;
const responseType = this._responseType;

@@ -896,2 +943,3 @@

let buffer = this._buffer;
if (buffer === undefined && mime in exports.buffer){

@@ -901,2 +949,10 @@ buffer = !!exports.buffer[mime];

let parser = this._parser;
if (undefined === buffer) {
if (parser) {
console.warn("A custom superagent parser has been set, but buffering strategy for the parser hasn't been configured. Call `req.buffer(true or false)` or set `superagent.buffer[mime] = true or false`");
buffer = true;
}
}
if (!parser) {

@@ -925,2 +981,5 @@ if (responseType) {

parser = exports.parse.text;
} else if (undefined === buffer) {
parser = exports.parse.image; // It's actually a generic Buffer
buffer = true;
}

@@ -934,2 +993,3 @@ }

this._resBuffered = buffer;
let parserHandlesEnd = false;

@@ -1081,4 +1141,2 @@ if (buffer) {

}
return this;
};

@@ -1085,0 +1143,0 @@

@@ -39,3 +39,3 @@ 'use strict';

this.files = res.files || {};
this.buffered = 'string' == typeof this.text;
this.buffered = req._resBuffered;
this.header = this.headers = res.headers;

@@ -42,0 +42,0 @@ this._setStatusProperties(res.statusCode);

@@ -62,5 +62,5 @@ 'use strict';

if ('data' == type || 'end' == type) {
stream.on(type, fn);
stream.on(type, fn.bind(res));
} else if ('error' == type) {
stream.on(type, fn);
stream.on(type, fn.bind(res));
_on.call(res, type, fn);

@@ -67,0 +67,0 @@ } else {

{
"name": "superagent",
"version": "4.0.0-alpha.1",
"version": "4.0.0-beta.5",
"description": "elegant & feature rich browser / node HTTP with a fluent API",
"scripts": {
"prepare": "make all",
"test": "make test"
"test": "make test",
"test-http2": "make test-node-http2"
},

@@ -28,5 +29,4 @@ "keywords": [

"component-emitter": "^1.2.0",
"cookiejar": "^2.1.0",
"debug": "^3.1.0",
"extend": "^3.0.0",
"cookiejar": "^2.1.2",
"debug": "^4.0.0",
"form-data": "^2.3.2",

@@ -37,3 +37,3 @@ "formidable": "^1.2.0",

"qs": "^6.5.1",
"readable-stream": "^2.3.5"
"readable-stream": "^3.0.3"
},

@@ -51,3 +51,3 @@ "devDependencies": {

"express-session": "^1.15.6",
"marked": "^0.3.19",
"marked": "^0.5.0",
"mocha": "^3.5.3",

@@ -57,3 +57,3 @@ "multer": "^1.3.0",

"should-http": "^0.1.1",
"zuul": "^3.11.1"
"zuul": "^3.12.0"
},

@@ -60,0 +60,0 @@ "browser": {

@@ -5,3 +5,3 @@ # SuperAgent [![Build Status](https://travis-ci.org/visionmedia/superagent.svg?branch=master)](https://travis-ci.org/visionmedia/superagent)

SuperAgent is a small progressive __client-side__ HTTP request library, and __Node.js__ module with the same API, sporting many high-level HTTP client features. View the [docs](http://visionmedia.github.io/superagent/).
SuperAgent is a small progressive __client-side__ HTTP request library, and __Node.js__ module with the same API, sporting many high-level HTTP client features. View the [docs](https://visionmedia.github.io/superagent/).

@@ -67,6 +67,5 @@ ![super agent](http://f.cl.ly/items/3d282n3A0h0Z0K2w0q2a/Screenshot.png)

* [superagent-cache](https://github.com/jpodwys/superagent-cache) - A global SuperAgent patch with built-in, flexible caching
* [superagent-cache-plugin](https://github.com/jpodwys/superagent-cache-plugin) - A SuperAgent plugin with built-in, flexible caching
* [superagent-cache-plugin](https://github.com/jpodwys/superagent-cache-plugin) - A SuperAgent plugin with built-in, flexible caching
* [superagent-jsonapify](https://github.com/alex94puchades/superagent-jsonapify) - A lightweight [json-api](http://jsonapi.org/format/) client addon for superagent
* [superagent-serializer](https://github.com/zzarcon/superagent-serializer) - Converts server payload into different cases
* [superagent-use](https://github.com/koenpunt/superagent-use) - A client addon to apply plugins to all requests.
* [superagent-httpbackend](https://www.npmjs.com/package/superagent-httpbackend) - stub out requests using AngularJS' $httpBackend syntax

@@ -85,4 +84,8 @@ * [superagent-throttle](https://github.com/leviwheatcroft/superagent-throttle) - queues and intelligently throttles requests

* [3.x to 4.x](https://github.com/visionmedia/superagent/releases/tag/v4.0.0-alpha.1):
- Ensure you're running Node 6 or later. We've dropped support for Node 4.
- We've started using ES6 and for compatibility with Internet Explorer you may need to use Babel.
- We suggest migrating from `.end()` callbacks to `.then()` or `await`.
* [2.x to 3.x](https://github.com/visionmedia/superagent/releases/tag/v3.0.0):
- Ensure you're running Node 4 or later. We dropped support for Node 0.x.
- Ensure you're running Node 4 or later. We've dropped support for Node 0.x.
- Test code that calls `.send()` multiple times. Invalid calls to `.send()` will now throw instead of sending garbage.

@@ -94,3 +97,3 @@ * [1.x to 2.x](https://github.com/visionmedia/superagent/releases/tag/v2.0.0):

* 0.x to 1.x:
- Use `.end(function(err, res){})`. 1-argument version is no longer supported.
- Instead of 1-argument callback `.end(function(res){})` use `.then(res => {})`.

@@ -97,0 +100,0 @@ ## Running node tests

@@ -1802,3 +1802,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.superagent = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

return this._end();
this._end();
};

@@ -1905,3 +1905,2 @@

xhr.send(typeof data !== 'undefined' ? data : null);
return this;
};

@@ -1908,0 +1907,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc