superagent
Advanced tools
Comparing version 2.2.0 to 2.3.0
# SuperAgent | ||
Super Agent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs. It also works with Node.js! | ||
SuperAgent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs. It also works with Node.js! | ||
@@ -49,3 +49,3 @@ request | ||
__DELETE__, __HEAD__, __POST__, __PUT__ and other __HTTP__ verbs may also be used, simply change the method name: | ||
__DELETE__, __HEAD__, __PATCH__, __POST__, and __PUT__ requests can also be used, simply change the method name: | ||
@@ -203,3 +203,3 @@ request | ||
Superagent will automatically serialize JSON and forms. If you want to send the payload in a custom format, you can replace the built-in serialization with `.serialize()` method. | ||
SuperAgent will automatically serialize JSON and forms. If you want to send the payload in a custom format, you can replace the built-in serialization with `.serialize()` method. | ||
@@ -232,3 +232,3 @@ ## Setting Accept | ||
Super Agent will parse known response-body data for you, currently supporting `application/x-www-form-urlencoded`, `application/json`, and `multipart/form-data`. | ||
SuperAgent will parse known response-body data for you, currently supporting `application/x-www-form-urlencoded`, `application/json`, and `multipart/form-data`. | ||
@@ -371,3 +371,3 @@ You can set a custom parser (that takes precedence over built-in parsers) with the `.buffer(true).parse(fn)` method. If response buffering is not enabled (`.buffer(false)`) then the `response` event will be emitted without waiting for the body parser to finish, so `response.body` won't be available. | ||
Super Agent is also great for _building_ multipart requests for which it provides methods `.attach()` and `.field()`. | ||
SuperAgent is also great for _building_ multipart requests for which it provides methods `.attach()` and `.field()`. | ||
@@ -461,5 +461,5 @@ ### Attaching files | ||
Superagent's request is a "thenable" object that's compatible with JavaScript promises and `async`/`await` syntax. | ||
SuperAgent's request is a "thenable" object that's compatible with JavaScript promises and `async`/`await` syntax. | ||
Libraries like [co](https://github.com/tj/co) or a web framework like [koa](https://github.com/koajs/koa) can `yield` on any superagent method: | ||
Libraries like [co](https://github.com/tj/co) or a web framework like [koa](https://github.com/koajs/koa) can `yield` on any SuperAgent method: | ||
@@ -470,3 +470,3 @@ var res = yield request | ||
Note that superagent expects the global `Promise` object to be present. You'll need a polyfill to use promises in Internet Explorer or Node.js 0.10. | ||
Note that SuperAgent expects the global `Promise` object to be present. You'll need a polyfill to use promises in Internet Explorer or Node.js 0.10. | ||
@@ -476,3 +476,3 @@ | ||
Superagent has two implementations: one for web browsers (using XHR) and one for Node.JS (using core http module). By default Browserify and WebPack will pick the browser version. | ||
SuperAgent has two implementations: one for web browsers (using XHR) and one for Node.JS (using core http module). By default Browserify and WebPack will pick the browser version. | ||
@@ -483,2 +483,2 @@ If want to use WebPack to compile code for Node.JS, you *must* specify [node target](webpack.github.io/docs/configuration.html#target) in its configuration. | ||
[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](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. |
@@ -0,1 +1,10 @@ | ||
# 2.3.0 | ||
* Enabled `.field()` to handle objects (Affan Shahid) | ||
* Added authentication with client certificates (terusus) | ||
* Added `.catch()` for more Promise-like interface (Maxim Samoilov, Kornel Lesiński) | ||
* Silenced errors from incomplete gzip streams for compatibility with web browsers (Kornel Lesiński) | ||
* Fixed `event.direction` in uploads (Kornel Lesiński) | ||
* Fixed returned value of overwritten response object's `on()` method (Juan Dopazo) | ||
# 2.2.0 | ||
@@ -2,0 +11,0 @@ |
@@ -776,20 +776,20 @@ /** | ||
// progress | ||
var handleProgress = function(e){ | ||
var handleProgress = function(direction, e) { | ||
if (e.total > 0) { | ||
e.percent = e.loaded / e.total * 100; | ||
} | ||
e.direction = 'download'; | ||
e.direction = direction; | ||
self.emit('progress', e); | ||
}; | ||
} | ||
if (this.hasListeners('progress')) { | ||
xhr.onprogress = handleProgress; | ||
} | ||
try { | ||
if (xhr.upload && this.hasListeners('progress')) { | ||
xhr.upload.onprogress = handleProgress; | ||
try { | ||
xhr.onprogress = handleProgress.bind(null, 'download'); | ||
if (xhr.upload) { | ||
xhr.upload.onprogress = handleProgress.bind(null, 'upload'); | ||
} | ||
} catch(e) { | ||
// Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. | ||
// Reported here: | ||
// https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context | ||
} | ||
} catch(e) { | ||
// Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. | ||
// Reported here: | ||
// https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context | ||
} | ||
@@ -796,0 +796,0 @@ |
@@ -9,3 +9,3 @@ | ||
var parse = require('url').parse; | ||
var request = require('./index'); | ||
var request = require('../..'); | ||
var methods = require('methods'); | ||
@@ -27,3 +27,7 @@ | ||
if (!(this instanceof Agent)) return new Agent(options); | ||
if (options) this._ca = options.ca; | ||
if (options) { | ||
this._ca = options.ca; | ||
this._key = options.key; | ||
this._cert = options.cert; | ||
} | ||
this.jar = new CookieJar; | ||
@@ -75,2 +79,4 @@ } | ||
req.ca(this._ca); | ||
req.key(this._key); | ||
req.cert(this._cert); | ||
@@ -77,0 +83,0 @@ req.on('response', this._saveCookies.bind(this)); |
@@ -493,2 +493,28 @@ | ||
/** | ||
* Set the client certificate key option for https request. | ||
* | ||
* @param {Buffer | String} cert | ||
* @return {Request} for chaining | ||
* @api public | ||
*/ | ||
Request.prototype.key = function(cert){ | ||
this._key = cert; | ||
return this; | ||
}; | ||
/** | ||
* Set the client certificate option for https request. | ||
* | ||
* @param {Buffer | String} cert | ||
* @return {Request} for chaining | ||
* @api public | ||
*/ | ||
Request.prototype.cert = function(cert){ | ||
this._cert = cert; | ||
return this; | ||
}; | ||
/** | ||
* Return an http[s] request. | ||
@@ -518,2 +544,4 @@ * | ||
options.ca = this._ca; | ||
options.key = this._key; | ||
options.cert = this._cert; | ||
options.agent = this._agent; | ||
@@ -520,0 +548,0 @@ |
@@ -86,2 +86,6 @@ | ||
unzip.on('error', function(err){ | ||
if (err && err.code === 'Z_BUF_ERROR') { // unexpected end of file is ignored by browsers and curl | ||
stream.emit('end'); | ||
return; | ||
} | ||
stream.emit('error', err); | ||
@@ -123,2 +127,3 @@ }); | ||
} | ||
return this; | ||
}; | ||
@@ -125,0 +130,0 @@ }; |
@@ -80,2 +80,6 @@ /** | ||
exports.catch = function(cb) { | ||
return this.then(undefined, cb); | ||
}; | ||
/** | ||
@@ -170,4 +174,4 @@ * Allow for extension | ||
/** | ||
* Write the field `name` and `val` for "multipart/form-data" | ||
* request bodies. | ||
* Write the field `name` and `val`, or multiple fields with one object | ||
* for "multipart/form-data" request bodies. | ||
* | ||
@@ -178,5 +182,9 @@ * ``` js | ||
* .end(callback); | ||
* | ||
* request.post('/upload') | ||
* .field({ foo: 'bar', baz: 'qux' }) | ||
* .end(callback); | ||
* ``` | ||
* | ||
* @param {String} name | ||
* @param {String|Object} name | ||
* @param {String|Blob|File|Buffer|fs.ReadStream} val | ||
@@ -187,2 +195,19 @@ * @return {Request} for chaining | ||
exports.field = function(name, val) { | ||
// name should be either a string or an object. | ||
if (null === name || undefined === name) { | ||
throw new Error('.field(name, val) name can not be empty'); | ||
} | ||
if (isObject(name)) { | ||
for (var key in name) { | ||
this.field(key, name[key]); | ||
} | ||
return this; | ||
} | ||
// val should be defined now | ||
if (null === val || undefined === val) { | ||
throw new Error('.field(name, val) val can not be empty'); | ||
} | ||
this._getFormData().append(name, val); | ||
@@ -189,0 +214,0 @@ return this; |
{ | ||
"name": "superagent", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "elegant & feature rich browser / node HTTP with a fluent API", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -21,3 +21,3 @@ # SuperAgent | ||
Works with [browserify](https://github.com/substack/node-browserify) and should work with [webpack](https://github.com/visionmedia/superagent/wiki/Superagent-for-Webpack) | ||
Works with [browserify](https://github.com/substack/node-browserify) and should work with [webpack](https://github.com/visionmedia/superagent/wiki/SuperAgent-for-Webpack) | ||
@@ -50,3 +50,3 @@ ```js | ||
Superagent is easily extended via plugins. | ||
SuperAgent is easily extended via plugins. | ||
@@ -73,14 +73,13 @@ ```js | ||
* [superagent-mocker](https://github.com/shuvalov-anton/superagent-mocker) — simulate REST API | ||
* [superagent-cache](https://github.com/jpodwys/superagent-cache) - superagent with built-in, flexible caching | ||
* [superagent-cache](https://github.com/jpodwys/superagent-cache) - SuperAgent with built-in, flexible caching (compatible with SuperAgent `1.x`) | ||
* [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-promise-plugin](https://github.com/jomaxx/superagent-promise-plugin) - Shims req.end to return a promise when executed with no callback. | ||
* [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 | ||
* [superagent-throttle](https://github.com/leviwheatcroft/superagent-throttle) - queues and intelligently throttles requests | ||
* [superagent-charset](https://github.com/magicdawn/superagent-charset) - add charset support for node's superagent | ||
* [superagent-charset](https://github.com/magicdawn/superagent-charset) - add charset support for node's SuperAgent | ||
Please prefix your plugin with `superagent-*` so that it can easily be found by others. | ||
For superagent extensions such as couchdb and oauth visit the [wiki](https://github.com/visionmedia/superagent/wiki). | ||
For SuperAgent extensions such as couchdb and oauth visit the [wiki](https://github.com/visionmedia/superagent/wiki). | ||
@@ -125,3 +124,3 @@ ## Running node tests | ||
**npm (for browserify)** is handled via the `package.json` `browser` field which allows users to install superagent via npm, reference it from their browser code with `require('superagent')`, and then build their own application bundle via `browserify`, which will use `lib/client.js` as the superagent entrypoint. | ||
**npm (for browserify)** is handled via the `package.json` `browser` field which allows users to install SuperAgent via npm, reference it from their browser code with `require('superagent')`, and then build their own application bundle via `browserify`, which will use `lib/client.js` as the SuperAgent entrypoint. | ||
@@ -128,0 +127,0 @@ **bower** is configured via the `bower.json` file. Bower installs files directly from git/github without any transformation. |
@@ -96,2 +96,6 @@ (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 e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
exports.catch = function(cb) { | ||
return this.then(undefined, cb); | ||
}; | ||
/** | ||
@@ -186,4 +190,4 @@ * Allow for extension | ||
/** | ||
* Write the field `name` and `val` for "multipart/form-data" | ||
* request bodies. | ||
* Write the field `name` and `val`, or multiple fields with one object | ||
* for "multipart/form-data" request bodies. | ||
* | ||
@@ -194,5 +198,9 @@ * ``` js | ||
* .end(callback); | ||
* | ||
* request.post('/upload') | ||
* .field({ foo: 'bar', baz: 'qux' }) | ||
* .end(callback); | ||
* ``` | ||
* | ||
* @param {String} name | ||
* @param {String|Object} name | ||
* @param {String|Blob|File|Buffer|fs.ReadStream} val | ||
@@ -203,2 +211,19 @@ * @return {Request} for chaining | ||
exports.field = function(name, val) { | ||
// name should be either a string or an object. | ||
if (null === name || undefined === name) { | ||
throw new Error('.field(name, val) name can not be empty'); | ||
} | ||
if (isObject(name)) { | ||
for (var key in name) { | ||
this.field(key, name[key]); | ||
} | ||
return this; | ||
} | ||
// val should be defined now | ||
if (null === val || undefined === val) { | ||
throw new Error('.field(name, val) val can not be empty'); | ||
} | ||
this._getFormData().append(name, val); | ||
@@ -1344,20 +1369,20 @@ return this; | ||
// progress | ||
var handleProgress = function(e){ | ||
var handleProgress = function(direction, e) { | ||
if (e.total > 0) { | ||
e.percent = e.loaded / e.total * 100; | ||
} | ||
e.direction = 'download'; | ||
e.direction = direction; | ||
self.emit('progress', e); | ||
}; | ||
} | ||
if (this.hasListeners('progress')) { | ||
xhr.onprogress = handleProgress; | ||
} | ||
try { | ||
if (xhr.upload && this.hasListeners('progress')) { | ||
xhr.upload.onprogress = handleProgress; | ||
try { | ||
xhr.onprogress = handleProgress.bind(null, 'download'); | ||
if (xhr.upload) { | ||
xhr.upload.onprogress = handleProgress.bind(null, 'upload'); | ||
} | ||
} catch(e) { | ||
// Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. | ||
// Reported here: | ||
// https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context | ||
} | ||
} catch(e) { | ||
// Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. | ||
// Reported here: | ||
// https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context | ||
} | ||
@@ -1364,0 +1389,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
221288
4065
130