mirror of
https://github.com/maxswa/osrs-json-hiscores.git
synced 2025-10-15 10:19:04 +00:00
1.0.1
This commit is contained in:
16
node_modules/superagent/.travis.yml
generated
vendored
Normal file
16
node_modules/superagent/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "8"
|
||||
- "6"
|
||||
- "4"
|
||||
|
||||
env:
|
||||
global:
|
||||
- SAUCE_USERNAME='shtylman-superagent'
|
||||
- SAUCE_ACCESS_KEY='39a45464-cb1d-4b8d-aa1f-83c7c04fa673'
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- node_js: "8"
|
||||
env: BROWSER=1
|
||||
14
node_modules/superagent/.zuul.yml
generated
vendored
Normal file
14
node_modules/superagent/.zuul.yml
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
ui: mocha-bdd
|
||||
server: ./test/support/server.js
|
||||
tunnel_host: http://focusaurus.com
|
||||
browsers:
|
||||
- name: chrome
|
||||
version: latest
|
||||
- name: firefox
|
||||
version: latest
|
||||
- name: safari
|
||||
version: latest
|
||||
- name: iphone
|
||||
version: latest
|
||||
- name: ie
|
||||
version: 9..latest
|
||||
7
node_modules/superagent/Contributing.md
generated
vendored
Normal file
7
node_modules/superagent/Contributing.md
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
When submitting a PR, your chance of acceptance increases if you do the following:
|
||||
|
||||
* Code style is consistent with existing in the file.
|
||||
* Tests are passing (client and server).
|
||||
* You add a test for the failing issue you are fixing.
|
||||
* Code changes are focused on the area of discussion.
|
||||
* Do not rebuild the distribution files or increment version numbers.
|
||||
719
node_modules/superagent/History.md
generated
vendored
Normal file
719
node_modules/superagent/History.md
generated
vendored
Normal file
@@ -0,0 +1,719 @@
|
||||
|
||||
# 3.8.3 (2018-04-29)
|
||||
|
||||
* Add flags for 201 & 422 responses (Nikhil Fadnis)
|
||||
* Emit progress event while uploading Node `Buffer` via send method (Sergey Akhalkov)
|
||||
* Fixed setting correct cookies for redirects (Damien Clark)
|
||||
* Replace .catch with ['catch'] for IE9 Support (Miguel Stevens)
|
||||
|
||||
# 3.8.2 (2017-12-09)
|
||||
|
||||
* Fixed handling of exceptions thrown from callbacks
|
||||
* Stricter matching of `+json` MIME types.
|
||||
|
||||
# 3.8.1 (2017-11-08)
|
||||
|
||||
* Clear authorization header on cross-domain redirect
|
||||
|
||||
# 3.8.0
|
||||
|
||||
* Added support for "globally" defined headers and event handlers via `superagent.agent()`. It now remembers default settings for all its requests.
|
||||
* Added optional callback to `.retry()` (Alexander Murphy)
|
||||
* Unified auth args handling in node/browser (Edmundo Alvarez)
|
||||
* Fixed error handling in zlib pipes (Kornel)
|
||||
* Documented that 3xx status codes are errors (Mickey Reiss)
|
||||
|
||||
# 3.7.0 (2017-10-17)
|
||||
|
||||
* Limit maximum response size. Prevents zip bombs (Kornel)
|
||||
* Catch and pass along errors in `.ok()` callback (Jeremy Ruppel)
|
||||
* Fixed parsing of XHR headers without a newline (nsf)
|
||||
|
||||
# 3.6.2 (2017-10-02)
|
||||
|
||||
* Upgrade MIME type dependency to a newer, secure version
|
||||
* Recognize PDF MIME as binary
|
||||
* Fix for error in subsequent require() calls (Steven de Salas)
|
||||
|
||||
# 3.6.0 (2017-08-20)
|
||||
|
||||
* Support disabling TCP_NODELAY option (#1240) (xiamengyu)
|
||||
* Send payload in query string for GET and HEAD shorthand API (Peter Lyons)
|
||||
* Support passphrase with pfx certificate (Paul Westerdale (ABRS Limited))
|
||||
* Documentation improvements (Peter Lyons)
|
||||
* Fixed duplicated query string params (#1200) (Kornel)
|
||||
|
||||
# 3.5.1 (2017-03-18)
|
||||
|
||||
* Allow crossDomain errors to be retried (#1194) (Michael Olson)
|
||||
* Read responseType property from the correct object (Julien Dupouy)
|
||||
* Check for ownProperty before adding header (Lucas Vieira)
|
||||
|
||||
# 3.5.0 (2017-02-23)
|
||||
|
||||
* Add errno to distinguish between request timeout and body download timeout (#1184) (Kornel Lesiński)
|
||||
* Warn about bogus timeout options (#1185) (Kornel Lesiński)
|
||||
|
||||
# 3.4.4 (2017-02-17)
|
||||
|
||||
* Treat videos like images (Kornel Lesiński)
|
||||
* Avoid renaming module (Kornel Lesiński)
|
||||
|
||||
# 3.4.3 (2017-02-14)
|
||||
|
||||
* Fixed being able to define own parsers when their mime type starts with `text/` (Damien Clark)
|
||||
* `withCredentials(false)` (Andy Woods)
|
||||
* Use `formData.on` instead of `.once` (Kornel Lesiński)
|
||||
* Ignore `attach("file",null)` (Kornel Lesiński)
|
||||
|
||||
# 3.4.1 (2017-01-29)
|
||||
|
||||
* Allow `retry()` and `retry(0)` (Alexander Pope)
|
||||
* Allow optional body/data in DELETE requests (Alpha Shuro)
|
||||
* Fixed query string on retried requests (Kornel Lesiński)
|
||||
|
||||
# 3.4.0 (2017-01-25)
|
||||
|
||||
* New `.retry(n)` method and `err.retries` (Alexander Pope)
|
||||
* Docs for HTTPS request (Jun Wan Goh)
|
||||
|
||||
# 3.3.1 (2016-12-17)
|
||||
|
||||
* Fixed "double callback bug" warning on timeouts of gzipped responses
|
||||
|
||||
# 3.3.0 (2016-12-14)
|
||||
|
||||
* Added `.ok(callback)` that allows customizing which responses are errors (Kornel Lesiński)
|
||||
* Added `.responseType()` to Node version (Kornel Lesiński)
|
||||
* Added `.parse()` to browser version (jakepearson)
|
||||
* Fixed parse error when using `responseType('blob')` (Kornel Lesiński)
|
||||
|
||||
# 3.2.0 (2016-12-11)
|
||||
|
||||
* Added `.timeout({response:ms})`, which allows limiting maximum response time independently from total download time (Kornel Lesiński)
|
||||
* Added warnings when `.end()` is called more than once (Kornel Lesiński)
|
||||
* Added `response.links` to browser version (Lukas Eipert)
|
||||
* `btoa` is no longer required in IE9 (Kornel Lesiński)
|
||||
* Fixed `.sortQuery()` on URLs without query strings (Kornel Lesiński)
|
||||
* Refactored common response code into `ResponseBase` (Lukas Eipert)
|
||||
|
||||
# 3.1.0 (2016-11-28)
|
||||
|
||||
* Added `.sortQuery()` (vicanso)
|
||||
* Added support for arrays and bools in `.field()` (Kornel Lesiński)
|
||||
* Made `superagent.Request` subclassable without need to patch all static methods (Kornel Lesiński)
|
||||
|
||||
# 3.0.0 (2016-11-19)
|
||||
|
||||
* Dropped support for Node 0.x. Please upgrade to at least Node 4.
|
||||
* Dropped support for componentjs (Damien Caselli)
|
||||
* Removed deprecated `.part()`/`superagent.Part` APIs.
|
||||
* Removed unreliable `.body` property on internal response object used by unbuffered parsers.
|
||||
Note: the normal `response.body` is unaffected.
|
||||
* Multiple `.send()` calls mixing `Buffer`/`Blob` and JSON data are not possible and will now throw instead of messing up the data.
|
||||
* Improved `.send()` data object type check (Fernando Mendes)
|
||||
* Added common prototype for Node and browser versions (Andreas Helmberger)
|
||||
* Added `http+unix:` schema to support Unix sockets (Yuki KAN)
|
||||
* Added full `attach` options parameter in the Node version (Lapo Luchini)
|
||||
* Added `pfx` TLS option with new `pfx()` method. (Reid Burke)
|
||||
* Internally changed `.on` to `.once` to prevent possible memory leaks (Matt Blair)
|
||||
* Made all errors reported as an event (Kornel Lesiński)
|
||||
|
||||
# 2.3.0 (2016-09-20)
|
||||
|
||||
* 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 (2016-08-13)
|
||||
|
||||
* Added `timedout` property to node Request instance (Alexander Pope)
|
||||
* Unified `null` querystring values in node and browser environments. (George Chung)
|
||||
|
||||
# 2.1.0 (2016-06-14)
|
||||
|
||||
* Refactored async parsers. Now the `end` callback waits for async parsers to finish (Kornel Lesiński)
|
||||
* Errors thrown in `.end()` callback don't cause the callback to be called twice (Kornel Lesiński)
|
||||
* Added `headers` to `toJSON()` (Tao)
|
||||
|
||||
# 2.0.0 (2016-05-29)
|
||||
|
||||
## Breaking changes
|
||||
|
||||
Breaking changes are in rarely used functionality, so we hope upgrade will be smooth for most users.
|
||||
|
||||
* Browser: The `.parse()` method has been renamed to `.serialize()` for consistency with NodeJS version.
|
||||
* Browser: Query string keys without a value used to be parsed as `'undefined'`, now their value is `''` (empty string) (shura, Kornel Lesiński).
|
||||
* NodeJS: The `redirect` event is called after new query string and headers have been set and is allowed to override the request URL (Kornel Lesiński)
|
||||
* `.then()` returns a real `Promise`. Note that use of superagent with promises now requires a global `Promise` object.
|
||||
If you target Internet Explorer or Node 0.10, you'll need `require('es6-promise').polyfill()` or similar.
|
||||
* Upgraded all dependencies (Peter Lyons)
|
||||
* Renamed properties documented as `@api private` to have `_prefixed` names (Kornel Lesiński)
|
||||
|
||||
## Probably not breaking changes:
|
||||
|
||||
* Extracted common functions to request-base (Peter Lyons)
|
||||
* Fixed race condition in pipe tests (Peter Lyons)
|
||||
* Handle `FormData` error events (scriptype)
|
||||
* Fixed wrong jsdoc of Request#attach (George Chung)
|
||||
* Updated and improved tests (Peter Lyons)
|
||||
* `request.head()` supports `.redirects(5)` call (Kornel Lesiński)
|
||||
* `response` event is also emitted when using `.pipe()`
|
||||
|
||||
# 1.8.2 (2016-03-20)
|
||||
|
||||
* Fixed handling of HTTP status 204 with content-encoding: gzip (Andrew Shelton)
|
||||
* Handling of FormData error events (scriptype)
|
||||
* Fixed parsing of `vnd+json` MIME types (Kornel Lesiński)
|
||||
* Aliased browser implementation of `.parse()` as `.serialize()` for forward compatibility
|
||||
|
||||
# 1.8.1 (2016-03-14)
|
||||
|
||||
* Fixed form-data incompatibility with IE9
|
||||
|
||||
# 1.8.0 (2016-03-09)
|
||||
|
||||
* Extracted common code into request-base class (Peter Lyons)
|
||||
* It does not affect the public API, but please let us know if you notice any plugins/subclasses breaking!
|
||||
* Added option `{type:'auto'}` to `auth` method, which enables browser-native auth types (Jungle, Askar Yusupov)
|
||||
* Added `responseType()` to set XHR `responseType` (chris)
|
||||
* Switched to form-data for browserify-compatible `FormData` (Peter Lyons)
|
||||
* Added `statusCode` to error response when JSON response is malformed (mattdell)
|
||||
* Prevented TCP port conflicts in all tests (Peter Lyons)
|
||||
* Updated form-data dependency
|
||||
|
||||
# 1.7.2 (2016-01-26)
|
||||
|
||||
* Fix case-sensitivity of header fields introduced by a4ddd6a. (Edward J. Jinotti)
|
||||
* bump extend dependency, as former version did not contain any license information (Lukas Eipert)
|
||||
|
||||
# 1.7.1 (2016-01-21)
|
||||
|
||||
* Fixed a conflict with express when using npm 3.x (Glenn)
|
||||
* Fixed redirects after a multipart/form-data POST request (cyclist2)
|
||||
|
||||
# 1.7.0 (2016-01-18)
|
||||
|
||||
* When attaching files, read default filename from the `File` object (JD Isaacks)
|
||||
* Add `direction` property to `progress` events (Joseph Dykstra)
|
||||
* Update component-emitter & formidable (Kornel Lesiński)
|
||||
* Don't re-encode query string needlessly (Ruben Verborgh)
|
||||
* ensure querystring is appended when doing `stream.pipe(request)` (Keith Grennan)
|
||||
* change set header function, not call `this.request()` until call `this.end()` (vicanso)
|
||||
* Add no-op `withCredentials` to Node API (markdalgleish)
|
||||
* fix `delete` breaking on ie8 (kenjiokabe)
|
||||
* Don't let request error override responses (Clay Reimann)
|
||||
* Increased number of tests shared between node and client (Kornel Lesiński)
|
||||
|
||||
# 1.6.0/1.6.1 (2015-12-09)
|
||||
|
||||
* avoid misleading CORS error message
|
||||
* added 'progress' event on file/form upload in Node (Olivier Lalonde)
|
||||
* return raw response if the response parsing fails (Rei Colina)
|
||||
* parse content-types ending with `+json` as JSON (Eiryyy)
|
||||
* fix to avoid throwing errors on aborted requests (gjurgens)
|
||||
* retain cookies on redirect when hosts match (Tom Conroy)
|
||||
* added Bower manifest (Johnny Freeman)
|
||||
* upgrade to latest cookiejar (Andy Burke)
|
||||
|
||||
# 1.5.0 (2015-11-30)
|
||||
|
||||
* encode array values as `key=1&key=2&key=3` etc... (aalpern, Davis Kim)
|
||||
* avoid the error which is omitted from 'socket hang up'
|
||||
* faster JSON parsing, handling of zlib errors (jbellenger)
|
||||
* fix IE11 sends 'undefined' string if data was undefined (Vadim Goncharov)
|
||||
* alias `del()` method as `delete()` (Aaron Krause)
|
||||
* revert Request#parse since it was actually Response#parse
|
||||
|
||||
# 1.4.0 (2015-09-14)
|
||||
|
||||
* add Request#parse method to client library
|
||||
* add missing statusCode in client response
|
||||
* don't apply JSON heuristics if a valid parser is found
|
||||
* fix detection of root object for webworkers
|
||||
|
||||
# 1.3.0 (2015-08-05)
|
||||
|
||||
* fix incorrect content-length of data set to buffer
|
||||
* serialize request data takes into account charsets
|
||||
* add basic promise support via a `then` function
|
||||
|
||||
# 1.2.0 (2015-04-13)
|
||||
|
||||
* add progress events to downlodas
|
||||
* make usable in webworkers
|
||||
* add support for 308 redirects
|
||||
* update node-form-data dependency
|
||||
* update to work in react native
|
||||
* update node-mime dependency
|
||||
|
||||
# 1.1.0 (2015-03-13)
|
||||
|
||||
* Fix responseType checks without xhr2 and ie9 tests (rase-)
|
||||
* errors have .status and .response fields if applicable (defunctzombie)
|
||||
* fix end callback called before saving cookies (rase-)
|
||||
|
||||
1.0.0 / 2015-03-08
|
||||
==================
|
||||
|
||||
* All non-200 responses are treated as errors now. (The callback is called with an error when the response has a status < 200 or >= 300 now. In previous versions this would not have raised an error and the client would have to check the `res` object. See [#283](https://github.com/visionmedia/superagent/issues/283).
|
||||
* keep timeouts intact across redirects (hopkinsth)
|
||||
* handle falsy json values (themaarten)
|
||||
* fire response events in browser version (Schoonology)
|
||||
* getXHR exported in client version (KidsKilla)
|
||||
* remove arity check on `.end()` callbacks (defunctzombie)
|
||||
* avoid setting content-type for host objects (rexxars)
|
||||
* don't index array strings in querystring (travisjeffery)
|
||||
* fix pipe() with redirects (cyrilis)
|
||||
* add xhr2 file download (vstirbu)
|
||||
* set default response type to text/plain if not specified (warrenseine)
|
||||
|
||||
0.21.0 / 2014-11-11
|
||||
==================
|
||||
|
||||
* Trim text before parsing json (gjohnson)
|
||||
* Update tests to express 4 (gaastonsr)
|
||||
* Prevent double callback when error is thrown (pgn-vole)
|
||||
* Fix missing clearTimeout (nickdima)
|
||||
* Update debug (TooTallNate)
|
||||
|
||||
0.20.0 / 2014-10-02
|
||||
==================
|
||||
|
||||
* Add toJSON() to request and response instances. (yields)
|
||||
* Prevent HEAD requests from getting parsed. (gjohnson)
|
||||
* Update debug. (TooTallNate)
|
||||
|
||||
0.19.1 / 2014-09-24
|
||||
==================
|
||||
|
||||
* Fix basic auth issue when password is falsey value. (gjohnson)
|
||||
|
||||
0.19.0 / 2014-09-24
|
||||
==================
|
||||
|
||||
* Add unset() to browser. (shesek)
|
||||
* Prefer XHR over ActiveX. (omeid)
|
||||
* Catch parse errors. (jacwright)
|
||||
* Update qs dependency. (wercker)
|
||||
* Add use() to node. (Financial-Times)
|
||||
* Add response text to errors. (yields)
|
||||
* Don't send empty cookie headers. (undoZen)
|
||||
* Don't parse empty response bodies. (DveMac)
|
||||
* Use hostname when setting cookie host. (prasunsultania)
|
||||
|
||||
0.18.2 / 2014-07-12
|
||||
==================
|
||||
|
||||
* Handle parser errors. (kof)
|
||||
* Ensure not to use default parsers when there is a user defined one. (kof)
|
||||
|
||||
0.18.1 / 2014-07-05
|
||||
==================
|
||||
|
||||
* Upgrade cookiejar dependency (juanpin)
|
||||
* Support image mime types (nebulade)
|
||||
* Make .agent chainable (kof)
|
||||
* Upgrade debug (TooTallNate)
|
||||
* Fix docs (aheckmann)
|
||||
|
||||
0.18.0 / 2014-04-29
|
||||
===================
|
||||
|
||||
* Use "form-data" module for the multipart/form-data implementation. (TooTallNate)
|
||||
* Add basic `field()` and `attach()` functions for HTML5 FormData. (TooTallNate)
|
||||
* Deprecate `part()`. (TooTallNate)
|
||||
* Set default user-agent header. (bevacqua)
|
||||
* Add `unset()` method for removing headers. (bevacqua)
|
||||
* Update cookiejar. (missinglink)
|
||||
* Fix response error formatting. (shesek)
|
||||
|
||||
0.17.0 / 2014-03-06
|
||||
===================
|
||||
|
||||
* supply uri malformed error to the callback (yields)
|
||||
* add request event (yields)
|
||||
* allow simple auth (yields)
|
||||
* add request event (yields)
|
||||
* switch to component/reduce (visionmedia)
|
||||
* fix part content-disposition (mscdex)
|
||||
* add browser testing via zuul (defunctzombie)
|
||||
* adds request.use() (johntron)
|
||||
|
||||
0.16.0 / 2014-01-07
|
||||
==================
|
||||
|
||||
* remove support for 0.6 (superjoe30)
|
||||
* fix CORS withCredentials (wejendorp)
|
||||
* add "test" script (superjoe30)
|
||||
* add request .accept() method (nickl-)
|
||||
* add xml to mime types mappings (nickl-)
|
||||
* fix parse body error on HEAD requests (gjohnson)
|
||||
* fix documentation typos (matteofigus)
|
||||
* fix content-type + charset (bengourley)
|
||||
* fix null values on query parameters (cristiandouce)
|
||||
|
||||
0.15.7 / 2013-10-19
|
||||
==================
|
||||
|
||||
* pin should.js to 1.3.0 due to breaking change in 2.0.x
|
||||
* fix browserify regression
|
||||
|
||||
0.15.5 / 2013-10-09
|
||||
==================
|
||||
|
||||
* add browser field to support browserify
|
||||
* fix .field() value number support
|
||||
|
||||
0.15.4 / 2013-07-09
|
||||
==================
|
||||
|
||||
* node: add a Request#agent() function to set the http Agent to use
|
||||
|
||||
0.15.3 / 2013-07-05
|
||||
==================
|
||||
|
||||
* fix .pipe() unzipping on more recent nodes. Closes #240
|
||||
* fix passing an empty object to .query() no longer appends "?"
|
||||
* fix formidable error handling
|
||||
* update formidable
|
||||
|
||||
0.15.2 / 2013-07-02
|
||||
==================
|
||||
|
||||
* fix: emit 'end' when piping.
|
||||
|
||||
0.15.1 / 2013-06-26
|
||||
==================
|
||||
|
||||
* add try/catch around parseLinks
|
||||
|
||||
0.15.0 / 2013-06-25
|
||||
==================
|
||||
|
||||
* make `Response#toError()` have a more meaningful `message`
|
||||
|
||||
0.14.9 / 2013-06-15
|
||||
==================
|
||||
|
||||
* add debug()s to the node client
|
||||
* add .abort() method to node client
|
||||
|
||||
0.14.8 / 2013-06-13
|
||||
==================
|
||||
|
||||
* set .agent = false always
|
||||
* remove X-Requested-With. Closes #189
|
||||
|
||||
0.14.7 / 2013-06-06
|
||||
==================
|
||||
|
||||
* fix unzip error handling
|
||||
|
||||
0.14.6 / 2013-05-23
|
||||
==================
|
||||
|
||||
* fix HEAD unzip bug
|
||||
|
||||
0.14.5 / 2013-05-23
|
||||
==================
|
||||
|
||||
* add flag to ensure the callback is __never__ invoked twice
|
||||
|
||||
0.14.4 / 2013-05-22
|
||||
==================
|
||||
|
||||
* add superagent.js build output
|
||||
* update qs
|
||||
* update emitter-component
|
||||
* revert "add browser field to support browserify" see GH-221
|
||||
|
||||
0.14.3 / 2013-05-18
|
||||
==================
|
||||
|
||||
* add browser field to support browserify
|
||||
|
||||
0.14.2/ 2013-05-07
|
||||
==================
|
||||
|
||||
* add host object check to fix serialization of File/Blobs etc as json
|
||||
|
||||
0.14.1 / 2013-04-09
|
||||
==================
|
||||
|
||||
* update qs
|
||||
|
||||
0.14.0 / 2013-04-02
|
||||
==================
|
||||
|
||||
* add client-side basic auth
|
||||
* fix retaining of .set() header field case
|
||||
|
||||
0.13.0 / 2013-03-13
|
||||
==================
|
||||
|
||||
* add progress events to client
|
||||
* add simple example
|
||||
* add res.headers as alias of res.header for browser client
|
||||
* add res.get(field) to node/client
|
||||
|
||||
0.12.4 / 2013-02-11
|
||||
==================
|
||||
|
||||
* fix get content-type even if can't get other headers in firefox. fixes #181
|
||||
|
||||
0.12.3 / 2013-02-11
|
||||
==================
|
||||
|
||||
* add quick "progress" event support
|
||||
|
||||
0.12.2 / 2013-02-04
|
||||
==================
|
||||
|
||||
* add test to check if response acts as a readable stream
|
||||
* add ReadableStream in the Response prototype.
|
||||
* add test to assert correct redirection when the host changes in the location header.
|
||||
* add default Accept-Encoding. Closes #155
|
||||
* fix req.pipe() return value of original stream for node parity. Closes #171
|
||||
* remove the host header when cleaning headers to properly follow the redirection.
|
||||
|
||||
0.12.1 / 2013-01-10
|
||||
==================
|
||||
|
||||
* add x-domain error handling
|
||||
|
||||
0.12.0 / 2013-01-04
|
||||
==================
|
||||
|
||||
* add header persistence on redirects
|
||||
|
||||
0.11.0 / 2013-01-02
|
||||
==================
|
||||
|
||||
* add .error Error object. Closes #156
|
||||
* add forcing of res.text removal for FF HEAD responses. Closes #162
|
||||
* add reduce component usage. Closes #90
|
||||
* move better-assert dep to development deps
|
||||
|
||||
0.10.0 / 2012-11-14
|
||||
==================
|
||||
|
||||
* add req.timeout(ms) support for the client
|
||||
|
||||
0.9.10 / 2012-11-14
|
||||
==================
|
||||
|
||||
* fix client-side .query(str) support
|
||||
|
||||
0.9.9 / 2012-11-14
|
||||
==================
|
||||
|
||||
* add .parse(fn) support
|
||||
* fix socket hangup with dates in querystring. Closes #146
|
||||
* fix socket hangup "error" event when a callback of arity 2 is provided
|
||||
|
||||
0.9.8 / 2012-11-03
|
||||
==================
|
||||
|
||||
* add emission of error from `Request#callback()`
|
||||
* add a better fix for nodes weird socket hang up error
|
||||
* add PUT/POST/PATCH data support to client short-hand functions
|
||||
* add .license property to component.json
|
||||
* change client portion to build using component(1)
|
||||
* fix GET body support [guille]
|
||||
|
||||
0.9.7 / 2012-10-19
|
||||
==================
|
||||
|
||||
* fix `.buffer()` `res.text` when no parser matches
|
||||
|
||||
0.9.6 / 2012-10-17
|
||||
==================
|
||||
|
||||
* change: use `this` when `window` is undefined
|
||||
* update to new component spec [juliangruber]
|
||||
* fix emission of "data" events for compressed responses without encoding. Closes #125
|
||||
|
||||
0.9.5 / 2012-10-01
|
||||
==================
|
||||
|
||||
* add field name to .attach()
|
||||
* add text "parser"
|
||||
* refactor isObject()
|
||||
* remove wtf isFunction() helper
|
||||
|
||||
0.9.4 / 2012-09-20
|
||||
==================
|
||||
|
||||
* fix `Buffer` responses [TooTallNate]
|
||||
* fix `res.type` when a "type" param is present [TooTallNate]
|
||||
|
||||
0.9.3 / 2012-09-18
|
||||
==================
|
||||
|
||||
* remove __GET__ `.send()` == `.query()` special-case (__API__ change !!!)
|
||||
|
||||
0.9.2 / 2012-09-17
|
||||
==================
|
||||
|
||||
* add `.aborted` prop
|
||||
* add `.abort()`. Closes #115
|
||||
|
||||
0.9.1 / 2012-09-07
|
||||
==================
|
||||
|
||||
* add `.forbidden` response property
|
||||
* add component.json
|
||||
* change emitter-component to 0.0.5
|
||||
* fix client-side tests
|
||||
|
||||
0.9.0 / 2012-08-28
|
||||
==================
|
||||
|
||||
* add `.timeout(ms)`. Closes #17
|
||||
|
||||
0.8.2 / 2012-08-28
|
||||
==================
|
||||
|
||||
* fix pathname relative redirects. Closes #112
|
||||
|
||||
0.8.1 / 2012-08-21
|
||||
==================
|
||||
|
||||
* fix redirects when schema is specified
|
||||
|
||||
0.8.0 / 2012-08-19
|
||||
==================
|
||||
|
||||
* add `res.buffered` flag
|
||||
* add buffering of text/*, json and forms only by default. Closes #61
|
||||
* add `.buffer(false)` cancellation
|
||||
* add cookie jar support [hunterloftis]
|
||||
* add agent functionality [hunterloftis]
|
||||
|
||||
0.7.0 / 2012-08-03
|
||||
==================
|
||||
|
||||
* allow `query()` to be called after the internal `req` has been created [tootallnate]
|
||||
|
||||
0.6.0 / 2012-07-17
|
||||
==================
|
||||
|
||||
* add `res.send('foo=bar')` default of "application/x-www-form-urlencoded"
|
||||
|
||||
0.5.1 / 2012-07-16
|
||||
==================
|
||||
|
||||
* add "methods" dep
|
||||
* add `.end()` arity check to node callbacks
|
||||
* fix unzip support due to weird node internals
|
||||
|
||||
0.5.0 / 2012-06-16
|
||||
==================
|
||||
|
||||
* Added "Link" response header field parsing, exposing `res.links`
|
||||
|
||||
0.4.3 / 2012-06-15
|
||||
==================
|
||||
|
||||
* Added 303, 305 and 307 as redirect status codes [slaskis]
|
||||
* Fixed passing an object as the url
|
||||
|
||||
0.4.2 / 2012-06-02
|
||||
==================
|
||||
|
||||
* Added component support
|
||||
* Fixed redirect data
|
||||
|
||||
0.4.1 / 2012-04-13
|
||||
==================
|
||||
|
||||
* Added HTTP PATCH support
|
||||
* Fixed: GET / HEAD when following redirects. Closes #86
|
||||
* Fixed Content-Length detection for multibyte chars
|
||||
|
||||
0.4.0 / 2012-03-04
|
||||
==================
|
||||
|
||||
* Added `.head()` method [browser]. Closes #78
|
||||
* Added `make test-cov` support
|
||||
* Added multipart request support. Closes #11
|
||||
* Added all methods that node supports. Closes #71
|
||||
* Added "response" event providing a Response object. Closes #28
|
||||
* Added `.query(obj)`. Closes #59
|
||||
* Added `res.type` (browser). Closes #54
|
||||
* Changed: default `res.body` and `res.files` to {}
|
||||
* Fixed: port existing query-string fix (browser). Closes #57
|
||||
|
||||
0.3.0 / 2012-01-24
|
||||
==================
|
||||
|
||||
* Added deflate/gzip support [guillermo]
|
||||
* Added `res.type` (Content-Type void of params)
|
||||
* Added `res.statusCode` to mirror node
|
||||
* Added `res.headers` to mirror node
|
||||
* Changed: parsers take callbacks
|
||||
* Fixed optional schema support. Closes #49
|
||||
|
||||
0.2.0 / 2012-01-05
|
||||
==================
|
||||
|
||||
* Added url auth support
|
||||
* Added `.auth(username, password)`
|
||||
* Added basic auth support [node]. Closes #41
|
||||
* Added `make test-docs`
|
||||
* Added guillermo's EventEmitter. Closes #16
|
||||
* Removed `Request#data()` for SS, renamed to `send()`
|
||||
* Removed `Request#data()` from client, renamed to `send()`
|
||||
* Fixed array support. [browser]
|
||||
* Fixed array support. Closes #35 [node]
|
||||
* Fixed `EventEmitter#emit()`
|
||||
|
||||
0.1.3 / 2011-10-25
|
||||
==================
|
||||
|
||||
* Added error to callback
|
||||
* Bumped node dep for 0.5.x
|
||||
|
||||
0.1.2 / 2011-09-24
|
||||
==================
|
||||
|
||||
* Added markdown documentation
|
||||
* Added `request(url[, fn])` support to the client
|
||||
* Added `qs` dependency to package.json
|
||||
* Added options for `Request#pipe()`
|
||||
* Added support for `request(url, callback)`
|
||||
* Added `request(url)` as shortcut for `request.get(url)`
|
||||
* Added `Request#pipe(stream)`
|
||||
* Added inherit from `Stream`
|
||||
* Added multipart support
|
||||
* Added ssl support (node)
|
||||
* Removed Content-Length field from client
|
||||
* Fixed buffering, `setEncoding()` to utf8 [reported by stagas]
|
||||
* Fixed "end" event when piping
|
||||
|
||||
0.1.1 / 2011-08-20
|
||||
==================
|
||||
|
||||
* Added `res.redirect` flag (node)
|
||||
* Added redirect support (node)
|
||||
* Added `Request#redirects(n)` (node)
|
||||
* Added `.set(object)` header field support
|
||||
* Fixed `Content-Length` support
|
||||
|
||||
0.1.0 / 2011-08-09
|
||||
==================
|
||||
|
||||
* Added support for multiple calls to `.data()`
|
||||
* Added support for `.get(uri, obj)`
|
||||
* Added GET `.data()` querystring support
|
||||
* Added IE{6,7,8} support [alexyoung]
|
||||
|
||||
0.0.1 / 2011-08-05
|
||||
==================
|
||||
|
||||
* Initial commit
|
||||
|
||||
22
node_modules/superagent/LICENSE
generated
vendored
Normal file
22
node_modules/superagent/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014-2016 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
57
node_modules/superagent/Makefile
generated
vendored
Normal file
57
node_modules/superagent/Makefile
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
NODETESTS ?= test/*.js test/node/*.js
|
||||
BROWSERTESTS ?= test/*.js test/client/*.js
|
||||
REPORTER = spec
|
||||
|
||||
all: superagent.js
|
||||
|
||||
test:
|
||||
@if [ "x$(BROWSER)" = "x" ]; then make test-node; else make test-browser; fi
|
||||
|
||||
test-node:
|
||||
@NODE_ENV=test NODE_TLS_REJECT_UNAUTHORIZED=0 ./node_modules/.bin/mocha \
|
||||
--require should \
|
||||
--reporter $(REPORTER) \
|
||||
--timeout 5000 \
|
||||
--growl \
|
||||
$(NODETESTS)
|
||||
|
||||
test-cov: lib-cov
|
||||
SUPERAGENT_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html
|
||||
|
||||
test-browser:
|
||||
SAUCE_APPIUM_VERSION=1.7 ./node_modules/.bin/zuul -- $(BROWSERTESTS)
|
||||
|
||||
test-browser-local:
|
||||
./node_modules/.bin/zuul --no-coverage --local 4000 -- $(BROWSERTESTS)
|
||||
|
||||
lib-cov:
|
||||
jscoverage lib lib-cov
|
||||
|
||||
superagent.js: lib/node/*.js lib/node/parsers/*.js
|
||||
@./node_modules/.bin/browserify \
|
||||
--standalone superagent \
|
||||
--outfile superagent.js .
|
||||
|
||||
test-server:
|
||||
@node test/server
|
||||
|
||||
docs: index.html test-docs docs/index.md
|
||||
|
||||
index.html: docs/index.md docs/head.html docs/tail.html
|
||||
marked < $< \
|
||||
| cat docs/head.html - docs/tail.html \
|
||||
> $@
|
||||
|
||||
docclean:
|
||||
rm -f index.html docs/test.html
|
||||
|
||||
test-docs: docs/head.html docs/tail.html
|
||||
make test REPORTER=doc \
|
||||
| cat docs/head.html - docs/tail.html \
|
||||
> docs/test.html
|
||||
|
||||
clean:
|
||||
rm -fr superagent.js components
|
||||
|
||||
.PHONY: test-cov test docs test-docs clean test-browser-local
|
||||
137
node_modules/superagent/Readme.md
generated
vendored
Normal file
137
node_modules/superagent/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
# SuperAgent [](https://travis-ci.org/visionmedia/superagent)
|
||||
|
||||
[](https://saucelabs.com/u/shtylman-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/).
|
||||
|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
node:
|
||||
|
||||
```
|
||||
$ npm install superagent
|
||||
```
|
||||
|
||||
Works with [browserify](https://github.com/substack/node-browserify) and [webpack](https://github.com/visionmedia/superagent/wiki/SuperAgent-for-Webpack).
|
||||
|
||||
```js
|
||||
request
|
||||
.post('/api/pet')
|
||||
.send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
|
||||
.set('X-API-Key', 'foobar')
|
||||
.set('accept', 'json')
|
||||
.end((err, res) => {
|
||||
// Calling the end function will send the request
|
||||
});
|
||||
```
|
||||
|
||||
## Supported browsers and Node versions
|
||||
|
||||
Tested browsers:
|
||||
|
||||
- Latest Firefox, Chrome, Safari
|
||||
- Latest Android, iPhone
|
||||
- IE10 through latest. IE9 with polyfills. Even though IE9 is supported, a polyfill for `window.FormData` is required for `.field()`.
|
||||
|
||||
Node 4 or later is required.
|
||||
|
||||
## Plugins
|
||||
|
||||
SuperAgent is easily extended via plugins.
|
||||
|
||||
```js
|
||||
const nocache = require('superagent-no-cache');
|
||||
const request = require('superagent');
|
||||
const prefix = require('superagent-prefix')('/static');
|
||||
|
||||
request
|
||||
.get('/some-url')
|
||||
.query({ action: 'edit', city: 'London' }) // query string
|
||||
.use(prefix) // Prefixes *only* this request
|
||||
.use(nocache) // Prevents caching of *only* this request
|
||||
.end((err, res) => {
|
||||
// Do something
|
||||
});
|
||||
```
|
||||
|
||||
Existing plugins:
|
||||
* [superagent-no-cache](https://github.com/johntron/superagent-no-cache) - prevents caching by including Cache-Control header
|
||||
* [superagent-prefix](https://github.com/johntron/superagent-prefix) - prefixes absolute URLs (useful in test environment)
|
||||
* [superagent-suffix](https://github.com/timneutkens1/superagent-suffix) - suffix URLs with a given path
|
||||
* [superagent-mock](https://github.com/M6Web/superagent-mock) - simulate HTTP calls by returning data fixtures based on the requested URL
|
||||
* [superagent-mocker](https://github.com/shuvalov-anton/superagent-mocker) — simulate REST API
|
||||
* [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-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
|
||||
* [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-verbose-errors](https://github.com/jcoreio/superagent-verbose-errors) - include response body in error messages for failed requests
|
||||
|
||||
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).
|
||||
|
||||
## Upgrading from previous versions:
|
||||
|
||||
Our breaking changes are mostly in rarely used functionality and from stricter error handling.
|
||||
|
||||
* [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.
|
||||
- Test code that calls `.send()` multiple times. Invalid calls to `.send()` will now throw instead of sending garbage.
|
||||
* [1.x to 2.x](https://github.com/visionmedia/superagent/releases/tag/v2.0.0):
|
||||
- If you use `.parse()` in the *browser* version, rename it to `.serialize()`.
|
||||
- If you rely on `undefined` in query-string values being sent literally as the text "undefined", switch to checking for missing value instead. `?key=undefined` is now `?key` (without a value).
|
||||
- If you use `.then()` in Internet Explorer, ensure that you have a polyfill that adds a global `Promise` object.
|
||||
* 0.x to 1.x:
|
||||
- Use `.end(function(err, res){})`. 1-argument version is no longer supported.
|
||||
|
||||
## Running node tests
|
||||
|
||||
Install dependencies:
|
||||
|
||||
```shell
|
||||
$ npm install
|
||||
```
|
||||
Run em!
|
||||
|
||||
```shell
|
||||
$ make test
|
||||
```
|
||||
|
||||
## Running browser tests
|
||||
|
||||
Install dependencies:
|
||||
|
||||
```shell
|
||||
$ npm install
|
||||
```
|
||||
|
||||
Start the test runner:
|
||||
|
||||
```shell
|
||||
$ make test-browser-local
|
||||
```
|
||||
|
||||
Visit `http://localhost:4000/__zuul` in your browser.
|
||||
|
||||
Edit tests and refresh your browser. You do not have to restart the test runner.
|
||||
|
||||
|
||||
## Packaging Notes for Developers
|
||||
|
||||
**npm (for node)** is configured via the `package.json` file and the `.npmignore` file. Key metadata in the `package.json` file is the `version` field which should be changed according to semantic versioning and have a 1-1 correspondence with git tags. So for example, if you were to `git show v1.5.0:package.json | grep version`, you should see `"version": "1.5.0",` and this should hold true for every release. This can be handled via the `npm version` command. Be aware that when publishing, npm will presume the version being published should also be tagged in npm as `latest`, which is OK for normal incremental releases. For betas and minor/patch releases to older versions, be sure to include `--tag` appropriately to avoid an older release getting tagged as `latest`.
|
||||
|
||||
**npm (for browser standalone)** When we publish versions to npm, we run `make superagent.js` which generates the standalone `superagent.js` file via `browserify`, and this file is included in the package published to npm (but this file is never checked into the git repository). If users want to install via npm but serve a single `.js` file directly to the browser, the `node_modules/superagent/superagent.js` is a standalone browserified file ready to go for that purpose. It is not minified.
|
||||
|
||||
**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.
|
||||
|
||||
**bower** is configured via the `bower.json` file. Bower installs files directly from git/github without any transformation, so you *must* use Browserify or Webpack (or use npm).
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
7
node_modules/superagent/changelog.sh
generated
vendored
Normal file
7
node_modules/superagent/changelog.sh
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
VER=$(git tag -l v[0-9].[0-9]*.[0-9]* | tail -n 1)
|
||||
echo "# ($(date +%Y-%m-%d))"
|
||||
echo
|
||||
git log $VER...HEAD --no-merges --topo-order --format=' * %s (%an)'
|
||||
echo
|
||||
echo "# $VER"
|
||||
11
node_modules/superagent/docs/head.html
generated
vendored
Normal file
11
node_modules/superagent/docs/head.html
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>SuperAgent — elegant API for AJAX in Node and browsers</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/3.0.0/tocbot.css">
|
||||
<link rel="stylesheet" href="docs/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<ul id="menu"></ul>
|
||||
<div id="content">
|
||||
BIN
node_modules/superagent/docs/images/bg.png
generated
vendored
Normal file
BIN
node_modules/superagent/docs/images/bg.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
701
node_modules/superagent/docs/index.md
generated
vendored
Normal file
701
node_modules/superagent/docs/index.md
generated
vendored
Normal file
@@ -0,0 +1,701 @@
|
||||
|
||||
# SuperAgent
|
||||
|
||||
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!
|
||||
|
||||
request
|
||||
.post('/api/pet')
|
||||
.send({ name: 'Manny', species: 'cat' })
|
||||
.set('X-API-Key', 'foobar')
|
||||
.set('Accept', 'application/json')
|
||||
.then(function(res) {
|
||||
alert('yay got ' + JSON.stringify(res.body));
|
||||
});
|
||||
|
||||
## Test documentation
|
||||
|
||||
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.
|
||||
|
||||
## Request basics
|
||||
|
||||
A request can be initiated by invoking the appropriate method on the `request` object, then calling `.then()` (or `.end()` [or `await`](#promise-and-generator-support)) to send the request. For example a simple __GET__ request:
|
||||
|
||||
request
|
||||
.get('/search')
|
||||
.then(function(res) {
|
||||
// res.body, res.headers, res.status
|
||||
})
|
||||
.catch(function(err) {
|
||||
// err.message, err.response
|
||||
});
|
||||
|
||||
HTTP method may also be passed as a string:
|
||||
|
||||
request('GET', '/search').then(success, failure);
|
||||
|
||||
Old-style callbacks are also supported. *Instead of* `.then()` you can call `.end()`:
|
||||
|
||||
request('GET', '/search').end(function(err, res){
|
||||
if (res.ok) {}
|
||||
});
|
||||
|
||||
Absolute URLs can be used. In web browsers absolute URLs work only if the server implements [CORS](#cors).
|
||||
|
||||
request
|
||||
.get('http://example.com/search')
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
The __Node__ client supports making requests to [Unix Domain Sockets](http://en.wikipedia.org/wiki/Unix_domain_socket):
|
||||
|
||||
// pattern: https?+unix://SOCKET_PATH/REQUEST_PATH
|
||||
// Use `%2F` as `/` in SOCKET_PATH
|
||||
request
|
||||
.get('http+unix://%2Fabsolute%2Fpath%2Fto%2Funix.sock/search')
|
||||
.then(res => {
|
||||
|
||||
});
|
||||
|
||||
__DELETE__, __HEAD__, __PATCH__, __POST__, and __PUT__ requests can also be used, simply change the method name:
|
||||
|
||||
request
|
||||
.head('/favicon.ico')
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
__DELETE__ can be also called as `.del()` for compatibility with old IE where `delete` is a reserved word.
|
||||
|
||||
The HTTP method defaults to __GET__, so if you wish, the following is valid:
|
||||
|
||||
request('/search', function(err, res){
|
||||
|
||||
});
|
||||
|
||||
## Setting header fields
|
||||
|
||||
Setting header fields is simple, invoke `.set()` with a field name and value:
|
||||
|
||||
request
|
||||
.get('/search')
|
||||
.set('API-Key', 'foobar')
|
||||
.set('Accept', 'application/json')
|
||||
.then(callback);
|
||||
|
||||
You may also pass an object to set several fields in a single call:
|
||||
|
||||
request
|
||||
.get('/search')
|
||||
.set({ 'API-Key': 'foobar', Accept: 'application/json' })
|
||||
.then(callback);
|
||||
|
||||
## `GET` requests
|
||||
|
||||
The `.query()` method accepts objects, which when used with the __GET__ method will form a query-string. The following will produce the path `/search?query=Manny&range=1..5&order=desc`.
|
||||
|
||||
request
|
||||
.get('/search')
|
||||
.query({ query: 'Manny' })
|
||||
.query({ range: '1..5' })
|
||||
.query({ order: 'desc' })
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
Or as a single object:
|
||||
|
||||
request
|
||||
.get('/search')
|
||||
.query({ query: 'Manny', range: '1..5', order: 'desc' })
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
The `.query()` method accepts strings as well:
|
||||
|
||||
request
|
||||
.get('/querystring')
|
||||
.query('search=Manny&range=1..5')
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
Or joined:
|
||||
|
||||
request
|
||||
.get('/querystring')
|
||||
.query('search=Manny')
|
||||
.query('range=1..5')
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
## `HEAD` requests
|
||||
|
||||
You can also use the `.query()` method for HEAD requests. The following will produce the path `/users?email=joe@smith.com`.
|
||||
|
||||
request
|
||||
.head('/users')
|
||||
.query({ email: 'joe@smith.com' })
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
## `POST` / `PUT` requests
|
||||
|
||||
A typical JSON __POST__ request might look a little like the following, where we set the Content-Type header field appropriately, and "write" some data, in this case just a JSON string.
|
||||
|
||||
request.post('/user')
|
||||
.set('Content-Type', 'application/json')
|
||||
.send('{"name":"tj","pet":"tobi"}')
|
||||
.then(callback)
|
||||
|
||||
Since JSON is undoubtedly the most common, it's the _default_! The following example is equivalent to the previous.
|
||||
|
||||
request.post('/user')
|
||||
.send({ name: 'tj', pet: 'tobi' })
|
||||
.then(callback)
|
||||
|
||||
Or using multiple `.send()` calls:
|
||||
|
||||
request.post('/user')
|
||||
.send({ name: 'tj' })
|
||||
.send({ pet: 'tobi' })
|
||||
.then(callback)
|
||||
|
||||
By default sending strings will set the `Content-Type` to `application/x-www-form-urlencoded`,
|
||||
multiple calls will be concatenated with `&`, here resulting in `name=tj&pet=tobi`:
|
||||
|
||||
request.post('/user')
|
||||
.send('name=tj')
|
||||
.send('pet=tobi')
|
||||
.then(callback);
|
||||
|
||||
SuperAgent formats are extensible, however by default "json" and "form" are supported. To send the data as `application/x-www-form-urlencoded` simply invoke `.type()` with "form", where the default is "json". This request will __POST__ the body "name=tj&pet=tobi".
|
||||
|
||||
request.post('/user')
|
||||
.type('form')
|
||||
.send({ name: 'tj' })
|
||||
.send({ pet: 'tobi' })
|
||||
.then(callback)
|
||||
|
||||
Sending a [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData) object is also supported. The following example will __POST__ the content of the HTML form identified by id="myForm":
|
||||
|
||||
request.post('/user')
|
||||
.send(new FormData(document.getElementById('myForm')))
|
||||
.then(callback)
|
||||
|
||||
## Setting the `Content-Type`
|
||||
|
||||
The obvious solution is to use the `.set()` method:
|
||||
|
||||
request.post('/user')
|
||||
.set('Content-Type', 'application/json')
|
||||
|
||||
As a short-hand the `.type()` method is also available, accepting
|
||||
the canonicalized MIME type name complete with type/subtype, or
|
||||
simply the extension name such as "xml", "json", "png", etc:
|
||||
|
||||
request.post('/user')
|
||||
.type('application/json')
|
||||
|
||||
request.post('/user')
|
||||
.type('json')
|
||||
|
||||
request.post('/user')
|
||||
.type('png')
|
||||
|
||||
## Serializing request body
|
||||
|
||||
SuperAgent will automatically serialize JSON and forms.
|
||||
You can setup automatic serialization for other types as well:
|
||||
|
||||
```js
|
||||
request.serialize['application/xml'] = function (obj) {
|
||||
return 'string generated from obj';
|
||||
};
|
||||
|
||||
//going forward, all requests with a Content-type of
|
||||
//'application/xml' will be automatically serialized
|
||||
```
|
||||
If you want to send the payload in a custom format, you can replace
|
||||
the built-in serialization with the `.serialize()` method on a per-request basis:
|
||||
|
||||
```js
|
||||
request
|
||||
.post('/user')
|
||||
.send({foo: 'bar'})
|
||||
.serialize(function serializer(obj) {
|
||||
return 'string generated from obj';
|
||||
});
|
||||
```
|
||||
## Retrying requests
|
||||
|
||||
When given the `.retry()` method, SuperAgent will automatically retry requests, if they fail in a way that is transient or could be due to a flaky Internet connection.
|
||||
|
||||
This method has two optional arguments: number of retries (default 3) and a callback. It calls `callback(err, res)` before each retry. The callback may return `true`/`false` to control whether the request sould be retried (but the maximum number of retries is always applied).
|
||||
|
||||
request
|
||||
.get('http://example.com/search')
|
||||
.retry(2) // or:
|
||||
.retry(2, callback)
|
||||
.then(finished);
|
||||
|
||||
Use `.retry()` only with requests that are *idempotent* (i.e. multiple requests reaching the server won't cause undesirable side effects like duplicate purchases).
|
||||
|
||||
## Setting Accept
|
||||
|
||||
In a similar fashion to the `.type()` method it is also possible to set the `Accept` header via the short hand method `.accept()`. Which references `request.types` as well allowing you to specify either the full canonicalized MIME type name as `type/subtype`, or the extension suffix form as "xml", "json", "png", etc. for convenience:
|
||||
|
||||
request.get('/user')
|
||||
.accept('application/json')
|
||||
|
||||
request.get('/user')
|
||||
.accept('json')
|
||||
|
||||
request.post('/user')
|
||||
.accept('png')
|
||||
|
||||
### Facebook and Accept JSON
|
||||
|
||||
If you are calling Facebook's API, be sure to send an `Accept: application/json` header in your request. If you don't do this, Facebook will respond with `Content-Type: text/javascript; charset=UTF-8`, which SuperAgent will not parse and thus `res.body` will be undefined. You can do this with either `req.accept('json')` or `req.header('Accept', 'application/json')`. See [issue 1078](https://github.com/visionmedia/superagent/issues/1078) for details.
|
||||
|
||||
## Query strings
|
||||
|
||||
`req.query(obj)` is a method which may be used to build up a query-string. For example populating `?format=json&dest=/login` on a __POST__:
|
||||
|
||||
request
|
||||
.post('/')
|
||||
.query({ format: 'json' })
|
||||
.query({ dest: '/login' })
|
||||
.send({ post: 'data', here: 'wahoo' })
|
||||
.then(callback);
|
||||
|
||||
By default the query string is not assembled in any particular order. An asciibetically-sorted query string can be enabled with `req.sortQuery()`. You may also provide a custom sorting comparison function with `req.sortQuery(myComparisonFn)`. The comparison function should take 2 arguments and return a negative/zero/positive integer.
|
||||
|
||||
```js
|
||||
// default order
|
||||
request.get('/user')
|
||||
.query('name=Nick')
|
||||
.query('search=Manny')
|
||||
.sortQuery()
|
||||
.then(callback)
|
||||
|
||||
// customized sort function
|
||||
request.get('/user')
|
||||
.query('name=Nick')
|
||||
.query('search=Manny')
|
||||
.sortQuery(function(a, b){
|
||||
return a.length - b.length;
|
||||
})
|
||||
.then(callback)
|
||||
```
|
||||
|
||||
## TLS options
|
||||
|
||||
In Node.js SuperAgent supports methods to configure HTTPS requests:
|
||||
|
||||
- `.ca()`: Set the CA certificate(s) to trust
|
||||
- `.cert()`: Set the client certificate chain(s)
|
||||
- `.key()`: Set the client private key(s)
|
||||
- `.pfx()`: Set the client PFX or PKCS12 encoded private key and certificate chain
|
||||
|
||||
For more information, see Node.js [https.request docs](https://nodejs.org/api/https.html#https_https_request_options_callback).
|
||||
|
||||
```js
|
||||
var key = fs.readFileSync('key.pem'),
|
||||
cert = fs.readFileSync('cert.pem');
|
||||
|
||||
request
|
||||
.post('/client-auth')
|
||||
.key(key)
|
||||
.cert(cert)
|
||||
.then(callback);
|
||||
```
|
||||
|
||||
```js
|
||||
var ca = fs.readFileSync('ca.cert.pem');
|
||||
|
||||
request
|
||||
.post('https://localhost/private-ca-server')
|
||||
.ca(ca)
|
||||
.then(res => {});
|
||||
```
|
||||
|
||||
## Parsing response bodies
|
||||
|
||||
SuperAgent will parse known response-body data for you,
|
||||
currently supporting `application/x-www-form-urlencoded`,
|
||||
`application/json`, and `multipart/form-data`. You can setup
|
||||
automatic parsing for other response-body data as well:
|
||||
|
||||
```js
|
||||
//browser
|
||||
request.parse['application/xml'] = function (str) {
|
||||
return {'object': 'parsed from str'};
|
||||
};
|
||||
|
||||
//node
|
||||
request.parse['application/xml'] = function (res, cb) {
|
||||
//parse response text and set res.body here
|
||||
|
||||
cb(null, res);
|
||||
};
|
||||
|
||||
//going forward, responses of type 'application/xml'
|
||||
//will be parsed automatically
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### JSON / Urlencoded
|
||||
|
||||
The property `res.body` is the parsed object, for example if a request responded with the JSON string '{"user":{"name":"tobi"}}', `res.body.user.name` would be "tobi". Likewise the x-www-form-urlencoded value of "user[name]=tobi" would yield the same result. Only one level of nesting is supported. If you need more complex data, send JSON instead.
|
||||
|
||||
Arrays are sent by repeating the key. `.send({color: ['red','blue']})` sends `color=red&color=blue`. If you want the array keys to contain `[]` in their name, you must add it yourself, as SuperAgent doesn't add it automatically.
|
||||
|
||||
### Multipart
|
||||
|
||||
The Node client supports _multipart/form-data_ via the [Formidable](https://github.com/felixge/node-formidable) module. When parsing multipart responses, the object `res.files` is also available to you. Suppose for example a request responds with the following multipart body:
|
||||
|
||||
--whoop
|
||||
Content-Disposition: attachment; name="image"; filename="tobi.png"
|
||||
Content-Type: image/png
|
||||
|
||||
... data here ...
|
||||
--whoop
|
||||
Content-Disposition: form-data; name="name"
|
||||
Content-Type: text/plain
|
||||
|
||||
Tobi
|
||||
--whoop--
|
||||
|
||||
You would have the values `res.body.name` provided as "Tobi", and `res.files.image` as a `File` object containing the path on disk, filename, and other properties.
|
||||
|
||||
### Binary
|
||||
|
||||
In browsers, you may use `.responseType('blob')` to request handling of binary response bodies. This API is unnecessary when running in node.js. The supported argument values for this method are
|
||||
|
||||
- `'blob'` passed through to the XmlHTTPRequest `responseType` property
|
||||
- `'arraybuffer'` passed through to the XmlHTTPRequest `responseType` property
|
||||
|
||||
```js
|
||||
req.get('/binary.data')
|
||||
.responseType('blob')
|
||||
.end(function (error, res) {
|
||||
// res.body will be a browser native Blob type here
|
||||
});
|
||||
```
|
||||
|
||||
For more information, see the Mozilla Developer Network [xhr.responseType docs](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType).
|
||||
|
||||
## Response properties
|
||||
|
||||
Many helpful flags and properties are set on the `Response` object, ranging from the response text, parsed response body, header fields, status flags and more.
|
||||
|
||||
### Response text
|
||||
|
||||
The `res.text` property contains the unparsed response body string. This property is always present for the client API, and only when the mime type matches "text/*", "*/json", or "x-www-form-urlencoded" by default for node. The reasoning is to conserve memory, as buffering text of large bodies such as multipart files or images is extremely inefficient. To force buffering see the "Buffering responses" section.
|
||||
|
||||
### Response body
|
||||
|
||||
Much like SuperAgent can auto-serialize request data, it can also automatically parse it. When a parser is defined for the Content-Type, it is parsed, which by default includes "application/json" and "application/x-www-form-urlencoded". The parsed object is then available via `res.body`.
|
||||
|
||||
### Response header fields
|
||||
|
||||
The `res.header` contains an object of parsed header fields, lowercasing field names much like node does. For example `res.header['content-length']`.
|
||||
|
||||
### Response Content-Type
|
||||
|
||||
The Content-Type response header is special-cased, providing `res.type`, which is void of the charset (if any). For example the Content-Type of "text/html; charset=utf8" will provide "text/html" as `res.type`, and the `res.charset` property would then contain "utf8".
|
||||
|
||||
### Response status
|
||||
|
||||
The response status flags help determine if the request was a success, among other useful information, making SuperAgent ideal for interacting with RESTful web services. These flags are currently defined as:
|
||||
|
||||
var type = status / 100 | 0;
|
||||
|
||||
// status / class
|
||||
res.status = status;
|
||||
res.statusType = type;
|
||||
|
||||
// basics
|
||||
res.info = 1 == type;
|
||||
res.ok = 2 == type;
|
||||
res.clientError = 4 == type;
|
||||
res.serverError = 5 == type;
|
||||
res.error = 4 == type || 5 == type;
|
||||
|
||||
// sugar
|
||||
res.accepted = 202 == status;
|
||||
res.noContent = 204 == status || 1223 == status;
|
||||
res.badRequest = 400 == status;
|
||||
res.unauthorized = 401 == status;
|
||||
res.notAcceptable = 406 == status;
|
||||
res.notFound = 404 == status;
|
||||
res.forbidden = 403 == status;
|
||||
|
||||
## Aborting requests
|
||||
|
||||
To abort requests simply invoke the `req.abort()` method.
|
||||
|
||||
## Timeouts
|
||||
|
||||
Sometimes networks and servers get "stuck" and never respond after accepting a request. Set timeouts to avoid requests waiting forever.
|
||||
|
||||
* `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({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.
|
||||
|
||||
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.
|
||||
|
||||
request
|
||||
.get('/big-file?network=slow')
|
||||
.timeout({
|
||||
response: 5000, // Wait 5 seconds for the server to start sending,
|
||||
deadline: 60000, // but allow 1 minute for the file to finish loading.
|
||||
})
|
||||
.then(res => {
|
||||
/* responded in time */
|
||||
}, err => {
|
||||
if (err.timeout) { /* timed out! */ } else { /* other error */ }
|
||||
});
|
||||
|
||||
Timeout errors have a `.timeout` property.
|
||||
|
||||
## Authentication
|
||||
|
||||
In both Node and browsers auth available via the `.auth()` method:
|
||||
|
||||
request
|
||||
.get('http://local')
|
||||
.auth('tobi', 'learnboost')
|
||||
.then(callback);
|
||||
|
||||
|
||||
In the _Node_ client Basic auth can be in the URL as "user:pass":
|
||||
|
||||
request.get('http://tobi:learnboost@local').then(callback);
|
||||
|
||||
By default only `Basic` auth is used. In browser you can add `{type:'auto'}` to enable all methods built-in in the browser (Digest, NTLM, etc.):
|
||||
|
||||
request.auth('digest', 'secret', {type:'auto'})
|
||||
|
||||
## Following redirects
|
||||
|
||||
By default up to 5 redirects will be followed, however you may specify this with the `res.redirects(n)` method:
|
||||
|
||||
request
|
||||
.get('/some.png')
|
||||
.redirects(2)
|
||||
.then(callback);
|
||||
|
||||
## Agents for global state
|
||||
|
||||
### Saving cookies
|
||||
|
||||
In Node SuperAgent does not save cookies by default, but you can use the `.agent()` method to create a copy of SuperAgent that saves cookies. Each copy has a separate cookie jar.
|
||||
|
||||
const agent = request.agent();
|
||||
agent
|
||||
.post('/login')
|
||||
.then(() => {
|
||||
return agent.get('/cookied-page');
|
||||
});
|
||||
|
||||
In browsers cookies are managed automatically by the browser, so the `.agent()` does not isolate cookies.
|
||||
|
||||
### Default options for multiple requests
|
||||
|
||||
Regular request methods called on the agent will be used as defaults for all requests made by that agent.
|
||||
|
||||
const agent = request.agent()
|
||||
.use(plugin)
|
||||
.auth(shared);
|
||||
|
||||
await agent.get('/with-plugin-and-auth');
|
||||
await agent.get('/also-with-plugin-and-auth');
|
||||
|
||||
The complete list of methods that the agent can use to set defaults is: `use`, `on`, `once`, `set`, `query`, `type`, `accept`, `auth`, `withCredentials`, `sortQuery`, `retry`, `ok`, `redirects`, `timeout`, `buffer`, `serialize`, `parse`, `ca`, `key`, `pfx`, `cert`.
|
||||
|
||||
## Piping data
|
||||
|
||||
The Node client allows you to pipe data to and from the request. Please note that `.pipe()` is used **instead of** `.end()`/`.then()` methods.
|
||||
|
||||
For example piping a file's contents as the request:
|
||||
|
||||
const request = require('superagent');
|
||||
const fs = require('fs');
|
||||
|
||||
const stream = fs.createReadStream('path/to/my.json');
|
||||
const req = request.post('/somewhere');
|
||||
req.type('json');
|
||||
stream.pipe(req);
|
||||
|
||||
Note that when you pipe to a request, superagent sends the piped data with [chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding), which isn't supported by all servers (for instance, Python WSGI servers).
|
||||
|
||||
Or piping the response to a file:
|
||||
|
||||
const stream = fs.createWriteStream('path/to/my.json');
|
||||
const req = request.get('/some.json');
|
||||
req.pipe(stream);
|
||||
|
||||
It's not possible to mix pipes and callbacks or promises. Note that you should **NOT** attempt to pipe the result of `.end()` or the `Response` object:
|
||||
|
||||
// Don't do either of these:
|
||||
const stream = getAWritableStream();
|
||||
const req = request
|
||||
.get('/some.json')
|
||||
// BAD: this pipes garbage to the stream and fails in unexpected ways
|
||||
.end((err, this_does_not_work) => this_does_not_work.pipe(stream))
|
||||
const req = request
|
||||
.get('/some.json')
|
||||
.end()
|
||||
// BAD: this is also unsupported, .pipe calls .end for you.
|
||||
.pipe(nope_its_too_late);
|
||||
|
||||
In a [future version](https://github.com/visionmedia/superagent/issues/1188) of superagent, improper calls to `pipe()` will fail.
|
||||
|
||||
## Multipart requests
|
||||
|
||||
SuperAgent is also great for _building_ multipart requests for which it provides methods `.attach()` and `.field()`.
|
||||
|
||||
When you use `.field()` or `.attach()` you can't use `.send()` and you *must not* set `Content-Type` (the correct type will be set for you).
|
||||
|
||||
### Attaching files
|
||||
|
||||
To send a file use `.attach(name, [file], [options])`. You can attach multiple files by calling `.attach` multiple times. The arguments are:
|
||||
|
||||
* `name` — field name in the form.
|
||||
* `file` — either string with file path or `Blob`/`Buffer` object.
|
||||
* `options` — (optional) either string with custom file name or `{filename: string}` object. In Node also `{contentType: 'mime/type'}` is supported. In browser create a `Blob` with an appropriate type instead.
|
||||
|
||||
<br>
|
||||
|
||||
request
|
||||
.post('/upload')
|
||||
.attach('image1', 'path/to/felix.jpeg')
|
||||
.attach('image2', imageBuffer, 'luna.jpeg')
|
||||
.field('caption', 'My cats')
|
||||
.then(callback);
|
||||
|
||||
### Field values
|
||||
|
||||
Much like form fields in HTML, you can set field values with `.field(name, value)` and `.field({name: value})`. Suppose you want to upload a few images with your name and email, your request might look something like this:
|
||||
|
||||
request
|
||||
.post('/upload')
|
||||
.field('user[name]', 'Tobi')
|
||||
.field('user[email]', 'tobi@learnboost.com')
|
||||
.field('friends[]', ['loki', 'jane'])
|
||||
.attach('image', 'path/to/tobi.png')
|
||||
.then(callback);
|
||||
|
||||
## Compression
|
||||
|
||||
The node client supports compressed responses, best of all, you don't have to do anything! It just works.
|
||||
|
||||
## Buffering responses
|
||||
|
||||
To force buffering of response bodies as `res.text` you may invoke `req.buffer()`. To undo the default of buffering for text responses such as "text/plain", "text/html" etc you may invoke `req.buffer(false)`.
|
||||
|
||||
When buffered the `res.buffered` flag is provided, you may use this to handle both buffered and unbuffered responses in the same callback.
|
||||
|
||||
## CORS
|
||||
|
||||
For security reasons, browsers will block cross-origin requests unless the server opts-in using CORS headers. Browsers will also make extra __OPTIONS__ requests to check what HTTP headers and methods are allowed by the server. [Read more about CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS).
|
||||
|
||||
The `.withCredentials()` method enables the ability to send cookies from the origin, however only when `Access-Control-Allow-Origin` is _not_ a wildcard ("*"), and `Access-Control-Allow-Credentials` is "true".
|
||||
|
||||
request
|
||||
.get('http://api.example.com:4001/')
|
||||
.withCredentials()
|
||||
.then(function(res) {
|
||||
assert.equal(200, res.status);
|
||||
assert.equal('tobi', res.text);
|
||||
})
|
||||
|
||||
## Error handling
|
||||
|
||||
Your callback function will always be passed two arguments: error and response. If no error occurred, the first argument will be null:
|
||||
|
||||
request
|
||||
.post('/upload')
|
||||
.attach('image', 'path/to/tobi.png')
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
An "error" event is also emitted, with you can listen for:
|
||||
|
||||
request
|
||||
.post('/upload')
|
||||
.attach('image', 'path/to/tobi.png')
|
||||
.on('error', handle)
|
||||
.then(function(res) {
|
||||
|
||||
});
|
||||
|
||||
Note that **superagent considers 4xx and 5xx responses (as well as unhandled 3xx responses) errors by default**. For example, if you get a `304 Not modified`, `403 Forbidden` or `500 Internal server error` response, this status information will be available via `err.status`. Errors from such responses also contain an `err.response` field with all of the properties mentioned in "[Response properties](#response-properties)". The library behaves in this way to handle the common case of wanting success responses and treating HTTP error status codes as errors while still allowing for custom logic around specific error conditions.
|
||||
|
||||
Network failures, timeouts, and other errors that produce no response will contain no `err.status` or `err.response` fields.
|
||||
|
||||
If you wish to handle 404 or other HTTP error responses, you can query the `err.status` property. When an HTTP error occurs (4xx or 5xx response) the `res.error` property is an `Error` object, this allows you to perform checks such as:
|
||||
|
||||
if (err && err.status === 404) {
|
||||
alert('oh no ' + res.body.message);
|
||||
}
|
||||
else if (err) {
|
||||
// all other error types we handle generically
|
||||
}
|
||||
|
||||
Alternatively, you can use the `.ok(callback)` method to decide whether a response is an error or not. The callback to the `ok` function gets a response and returns `true` if the response should be interpreted as success.
|
||||
|
||||
request.get('/404')
|
||||
.ok(res => res.status < 500)
|
||||
.then(response => {
|
||||
// reads 404 page as a successful response
|
||||
})
|
||||
|
||||
## Progress tracking
|
||||
|
||||
SuperAgent fires `progress` events on upload and download of large files.
|
||||
|
||||
request.post(url)
|
||||
.attach('field_name', file)
|
||||
.on('progress', event => {
|
||||
/* the event is:
|
||||
{
|
||||
direction: "upload" or "download"
|
||||
percent: 0 to 100 // may be missing if file size is unknown
|
||||
total: // total file size, may be missing
|
||||
loaded: // bytes downloaded or uploaded so far
|
||||
} */
|
||||
})
|
||||
.end()
|
||||
|
||||
## Promise and Generator support
|
||||
|
||||
SuperAgent's request is a "thenable" object that's compatible with JavaScript promises and `async`/`await` syntax.
|
||||
|
||||
If you're using promises, **do not** call `.end()` or `.pipe()`. Any use of `.then()` or `await` disables all other ways of using the request.
|
||||
|
||||
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:
|
||||
|
||||
const req = request
|
||||
.get('http://local')
|
||||
.auth('tobi', 'learnboost');
|
||||
const res = yield req;
|
||||
|
||||
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.
|
||||
|
||||
## Browser and node versions
|
||||
|
||||
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.
|
||||
|
||||
If want to use WebPack to compile code for Node.JS, you *must* specify [node target](https://webpack.github.io/docs/configuration.html#target) in its configuration.
|
||||
|
||||
### Using browser version in electron
|
||||
|
||||
[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.
|
||||
87
node_modules/superagent/docs/style.css
generated
vendored
Normal file
87
node_modules/superagent/docs/style.css
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
body {
|
||||
padding: 40px 80px;
|
||||
font: 14px/1.5 "Helvetica Neue", Helvetica, sans-serif;
|
||||
background: #181818 url(images/bg.png);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#content {
|
||||
margin: 0 auto;
|
||||
padding: 10px 40px;
|
||||
text-align: left;
|
||||
background: white;
|
||||
width: 50%;
|
||||
-webkit-border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
-webkit-box-shadow: 0 2px 5px 0 black;
|
||||
}
|
||||
|
||||
#menu {
|
||||
font-size: 13px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
position: fixed;
|
||||
top: 15px;
|
||||
left: 15px;
|
||||
}
|
||||
|
||||
#menu ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#menu li {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#menu a {
|
||||
color: rgba(255,255,255,.5);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#menu a:hover {
|
||||
color: white;
|
||||
}
|
||||
|
||||
#menu .active a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: monaco, monospace, sans-serif;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
p code {
|
||||
border: 1px solid #ECEA75;
|
||||
padding: 1px 3px;
|
||||
-webkit-border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
background: #FDFCD1;
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 20px 25px;
|
||||
border: 1px solid #ddd;
|
||||
-webkit-box-shadow: inset 0 0 5px #eee;
|
||||
-moz-box-shadow: inset 0 0 5px #eee;
|
||||
box-shadow: inset 0 0 5px #eee;
|
||||
}
|
||||
|
||||
code .comment { color: #ddd }
|
||||
code .init { color: #2F6FAD }
|
||||
code .string { color: #5890AD }
|
||||
code .keyword { color: #8A6343 }
|
||||
code .number { color: #2F6FAD }
|
||||
|
||||
/* override tocbot style to avoid vertical white line in table of content */
|
||||
.toc-link::before {
|
||||
content: initial;
|
||||
}
|
||||
36
node_modules/superagent/docs/tail.html
generated
vendored
Normal file
36
node_modules/superagent/docs/tail.html
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
</div>
|
||||
<a href="http://github.com/visionmedia/superagent"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||
<script>
|
||||
$('code').each(function(){
|
||||
$(this).html(highlight($(this).text()));
|
||||
});
|
||||
|
||||
function highlight(js) {
|
||||
return js
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/('.*?')/gm, '<span class="string">$1</span>')
|
||||
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
|
||||
.replace(/(\d+)/gm, '<span class="number">$1</span>')
|
||||
.replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
|
||||
.replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')
|
||||
}
|
||||
</script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/3.0.0/tocbot.js"></script>
|
||||
<script>
|
||||
// Only use tocbot for main docs, not test docs
|
||||
if (document.querySelector('#superagent')) {
|
||||
tocbot.init({
|
||||
// Where to render the table of contents.
|
||||
tocSelector: '#menu',
|
||||
// Where to grab the headings to build the table of contents.
|
||||
contentSelector: '#content',
|
||||
// Which headings to grab inside of the contentSelector element.
|
||||
headingSelector: 'h2',
|
||||
smoothScroll: false
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
2082
node_modules/superagent/docs/test.html
generated
vendored
Normal file
2082
node_modules/superagent/docs/test.html
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
20
node_modules/superagent/lib/agent-base.js
generated
vendored
Normal file
20
node_modules/superagent/lib/agent-base.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
function Agent() {
|
||||
this._defaults = [];
|
||||
}
|
||||
|
||||
["use", "on", "once", "set", "query", "type", "accept", "auth", "withCredentials", "sortQuery", "retry", "ok", "redirects",
|
||||
"timeout", "buffer", "serialize", "parse", "ca", "key", "pfx", "cert"].forEach(function(fn) {
|
||||
/** Default setting for all requests from this agent */
|
||||
Agent.prototype[fn] = function(/*varargs*/) {
|
||||
this._defaults.push({fn:fn, arguments:arguments});
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
Agent.prototype._setDefaults = function(req) {
|
||||
this._defaults.forEach(function(def) {
|
||||
req[def.fn].apply(req, def.arguments);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Agent;
|
||||
920
node_modules/superagent/lib/client.js
generated
vendored
Normal file
920
node_modules/superagent/lib/client.js
generated
vendored
Normal file
@@ -0,0 +1,920 @@
|
||||
/**
|
||||
* Root reference for iframes.
|
||||
*/
|
||||
|
||||
var root;
|
||||
if (typeof window !== 'undefined') { // Browser window
|
||||
root = window;
|
||||
} else if (typeof self !== 'undefined') { // Web Worker
|
||||
root = self;
|
||||
} else { // Other environments
|
||||
console.warn("Using browser-only version of superagent in non-browser environment");
|
||||
root = this;
|
||||
}
|
||||
|
||||
var Emitter = require('component-emitter');
|
||||
var RequestBase = require('./request-base');
|
||||
var isObject = require('./is-object');
|
||||
var ResponseBase = require('./response-base');
|
||||
var Agent = require('./agent-base');
|
||||
|
||||
/**
|
||||
* Noop.
|
||||
*/
|
||||
|
||||
function noop(){};
|
||||
|
||||
/**
|
||||
* Expose `request`.
|
||||
*/
|
||||
|
||||
var request = exports = module.exports = function(method, url) {
|
||||
// callback
|
||||
if ('function' == typeof url) {
|
||||
return new exports.Request('GET', method).end(url);
|
||||
}
|
||||
|
||||
// url first
|
||||
if (1 == arguments.length) {
|
||||
return new exports.Request('GET', method);
|
||||
}
|
||||
|
||||
return new exports.Request(method, url);
|
||||
}
|
||||
|
||||
exports.Request = Request;
|
||||
|
||||
/**
|
||||
* Determine XHR.
|
||||
*/
|
||||
|
||||
request.getXHR = function () {
|
||||
if (root.XMLHttpRequest
|
||||
&& (!root.location || 'file:' != root.location.protocol
|
||||
|| !root.ActiveXObject)) {
|
||||
return new XMLHttpRequest;
|
||||
} else {
|
||||
try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {}
|
||||
try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {}
|
||||
try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
|
||||
try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
|
||||
}
|
||||
throw Error("Browser-only version of superagent could not find XHR");
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes leading and trailing whitespace, added to support IE.
|
||||
*
|
||||
* @param {String} s
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var trim = ''.trim
|
||||
? function(s) { return s.trim(); }
|
||||
: function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
||||
|
||||
/**
|
||||
* Serialize the given `obj`.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function serialize(obj) {
|
||||
if (!isObject(obj)) return obj;
|
||||
var pairs = [];
|
||||
for (var key in obj) {
|
||||
pushEncodedKeyValuePair(pairs, key, obj[key]);
|
||||
}
|
||||
return pairs.join('&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helps 'serialize' with serializing arrays.
|
||||
* Mutates the pairs array.
|
||||
*
|
||||
* @param {Array} pairs
|
||||
* @param {String} key
|
||||
* @param {Mixed} val
|
||||
*/
|
||||
|
||||
function pushEncodedKeyValuePair(pairs, key, val) {
|
||||
if (val != null) {
|
||||
if (Array.isArray(val)) {
|
||||
val.forEach(function(v) {
|
||||
pushEncodedKeyValuePair(pairs, key, v);
|
||||
});
|
||||
} else if (isObject(val)) {
|
||||
for(var subkey in val) {
|
||||
pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
|
||||
}
|
||||
} else {
|
||||
pairs.push(encodeURIComponent(key)
|
||||
+ '=' + encodeURIComponent(val));
|
||||
}
|
||||
} else if (val === null) {
|
||||
pairs.push(encodeURIComponent(key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose serialization method.
|
||||
*/
|
||||
|
||||
request.serializeObject = serialize;
|
||||
|
||||
/**
|
||||
* Parse the given x-www-form-urlencoded `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parseString(str) {
|
||||
var obj = {};
|
||||
var pairs = str.split('&');
|
||||
var pair;
|
||||
var pos;
|
||||
|
||||
for (var i = 0, len = pairs.length; i < len; ++i) {
|
||||
pair = pairs[i];
|
||||
pos = pair.indexOf('=');
|
||||
if (pos == -1) {
|
||||
obj[decodeURIComponent(pair)] = '';
|
||||
} else {
|
||||
obj[decodeURIComponent(pair.slice(0, pos))] =
|
||||
decodeURIComponent(pair.slice(pos + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose parser.
|
||||
*/
|
||||
|
||||
request.parseString = parseString;
|
||||
|
||||
/**
|
||||
* Default MIME type map.
|
||||
*
|
||||
* superagent.types.xml = 'application/xml';
|
||||
*
|
||||
*/
|
||||
|
||||
request.types = {
|
||||
html: 'text/html',
|
||||
json: 'application/json',
|
||||
xml: 'text/xml',
|
||||
urlencoded: 'application/x-www-form-urlencoded',
|
||||
'form': 'application/x-www-form-urlencoded',
|
||||
'form-data': 'application/x-www-form-urlencoded'
|
||||
};
|
||||
|
||||
/**
|
||||
* Default serialization map.
|
||||
*
|
||||
* superagent.serialize['application/xml'] = function(obj){
|
||||
* return 'generated xml here';
|
||||
* };
|
||||
*
|
||||
*/
|
||||
|
||||
request.serialize = {
|
||||
'application/x-www-form-urlencoded': serialize,
|
||||
'application/json': JSON.stringify
|
||||
};
|
||||
|
||||
/**
|
||||
* Default parsers.
|
||||
*
|
||||
* superagent.parse['application/xml'] = function(str){
|
||||
* return { object parsed from str };
|
||||
* };
|
||||
*
|
||||
*/
|
||||
|
||||
request.parse = {
|
||||
'application/x-www-form-urlencoded': parseString,
|
||||
'application/json': JSON.parse
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given header `str` into
|
||||
* an object containing the mapped fields.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parseHeader(str) {
|
||||
var lines = str.split(/\r?\n/);
|
||||
var fields = {};
|
||||
var index;
|
||||
var line;
|
||||
var field;
|
||||
var val;
|
||||
|
||||
for (var i = 0, len = lines.length; i < len; ++i) {
|
||||
line = lines[i];
|
||||
index = line.indexOf(':');
|
||||
if (index === -1) { // could be empty line, just skip it
|
||||
continue;
|
||||
}
|
||||
field = line.slice(0, index).toLowerCase();
|
||||
val = trim(line.slice(index + 1));
|
||||
fields[field] = val;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if `mime` is json or has +json structured syntax suffix.
|
||||
*
|
||||
* @param {String} mime
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function isJSON(mime) {
|
||||
// should match /json or +json
|
||||
// but not /json-seq
|
||||
return /[\/+]json($|[^-\w])/.test(mime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a new `Response` with the given `xhr`.
|
||||
*
|
||||
* - set flags (.ok, .error, etc)
|
||||
* - parse header
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* Aliasing `superagent` as `request` is nice:
|
||||
*
|
||||
* request = superagent;
|
||||
*
|
||||
* We can use the promise-like API, or pass callbacks:
|
||||
*
|
||||
* request.get('/').end(function(res){});
|
||||
* request.get('/', function(res){});
|
||||
*
|
||||
* Sending data can be chained:
|
||||
*
|
||||
* request
|
||||
* .post('/user')
|
||||
* .send({ name: 'tj' })
|
||||
* .end(function(res){});
|
||||
*
|
||||
* Or passed to `.send()`:
|
||||
*
|
||||
* request
|
||||
* .post('/user')
|
||||
* .send({ name: 'tj' }, function(res){});
|
||||
*
|
||||
* Or passed to `.post()`:
|
||||
*
|
||||
* request
|
||||
* .post('/user', { name: 'tj' })
|
||||
* .end(function(res){});
|
||||
*
|
||||
* Or further reduced to a single call for simple cases:
|
||||
*
|
||||
* request
|
||||
* .post('/user', { name: 'tj' }, function(res){});
|
||||
*
|
||||
* @param {XMLHTTPRequest} xhr
|
||||
* @param {Object} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function Response(req) {
|
||||
this.req = req;
|
||||
this.xhr = this.req.xhr;
|
||||
// responseText is accessible only if responseType is '' or 'text' and on older browsers
|
||||
this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined')
|
||||
? this.xhr.responseText
|
||||
: null;
|
||||
this.statusText = this.req.xhr.statusText;
|
||||
var status = this.xhr.status;
|
||||
// handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
||||
if (status === 1223) {
|
||||
status = 204;
|
||||
}
|
||||
this._setStatusProperties(status);
|
||||
this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
||||
// getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
||||
// getResponseHeader still works. so we get content-type even if getting
|
||||
// other headers fails.
|
||||
this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
||||
this._setHeaderProperties(this.header);
|
||||
|
||||
if (null === this.text && req._responseType) {
|
||||
this.body = this.xhr.response;
|
||||
} else {
|
||||
this.body = this.req.method != 'HEAD'
|
||||
? this._parseBody(this.text ? this.text : this.xhr.response)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
ResponseBase(Response.prototype);
|
||||
|
||||
/**
|
||||
* Parse the given body `str`.
|
||||
*
|
||||
* Used for auto-parsing of bodies. Parsers
|
||||
* are defined on the `superagent.parse` object.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Response.prototype._parseBody = function(str) {
|
||||
var parse = request.parse[this.type];
|
||||
if (this.req._parser) {
|
||||
return this.req._parser(this, str);
|
||||
}
|
||||
if (!parse && isJSON(this.type)) {
|
||||
parse = request.parse['application/json'];
|
||||
}
|
||||
return parse && str && (str.length || str instanceof Object)
|
||||
? parse(str)
|
||||
: null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return an `Error` representative of this response.
|
||||
*
|
||||
* @return {Error}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Response.prototype.toError = function(){
|
||||
var req = this.req;
|
||||
var method = req.method;
|
||||
var url = req.url;
|
||||
|
||||
var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')';
|
||||
var err = new Error(msg);
|
||||
err.status = this.status;
|
||||
err.method = method;
|
||||
err.url = url;
|
||||
|
||||
return err;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose `Response`.
|
||||
*/
|
||||
|
||||
request.Response = Response;
|
||||
|
||||
/**
|
||||
* Initialize a new `Request` with the given `method` and `url`.
|
||||
*
|
||||
* @param {String} method
|
||||
* @param {String} url
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Request(method, url) {
|
||||
var self = this;
|
||||
this._query = this._query || [];
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
this.header = {}; // preserves header name case
|
||||
this._header = {}; // coerces header names to lowercase
|
||||
this.on('end', function(){
|
||||
var err = null;
|
||||
var res = null;
|
||||
|
||||
try {
|
||||
res = new Response(self);
|
||||
} catch(e) {
|
||||
err = new Error('Parser is unable to parse the response');
|
||||
err.parse = true;
|
||||
err.original = e;
|
||||
// issue #675: return the raw response if the response parsing fails
|
||||
if (self.xhr) {
|
||||
// ie9 doesn't have 'response' property
|
||||
err.rawResponse = typeof self.xhr.responseType == 'undefined' ? self.xhr.responseText : self.xhr.response;
|
||||
// issue #876: return the http status code if the response parsing fails
|
||||
err.status = self.xhr.status ? self.xhr.status : null;
|
||||
err.statusCode = err.status; // backwards-compat only
|
||||
} else {
|
||||
err.rawResponse = null;
|
||||
err.status = null;
|
||||
}
|
||||
|
||||
return self.callback(err);
|
||||
}
|
||||
|
||||
self.emit('response', res);
|
||||
|
||||
var new_err;
|
||||
try {
|
||||
if (!self._isResponseOK(res)) {
|
||||
new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
||||
}
|
||||
} catch(custom_err) {
|
||||
new_err = custom_err; // ok() callback can throw
|
||||
}
|
||||
|
||||
// #1000 don't catch errors from the callback to avoid double calling it
|
||||
if (new_err) {
|
||||
new_err.original = err;
|
||||
new_err.response = res;
|
||||
new_err.status = res.status;
|
||||
self.callback(new_err, res);
|
||||
} else {
|
||||
self.callback(null, res);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixin `Emitter` and `RequestBase`.
|
||||
*/
|
||||
|
||||
Emitter(Request.prototype);
|
||||
RequestBase(Request.prototype);
|
||||
|
||||
/**
|
||||
* Set Content-Type to `type`, mapping values from `request.types`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* superagent.types.xml = 'application/xml';
|
||||
*
|
||||
* request.post('/')
|
||||
* .type('xml')
|
||||
* .send(xmlstring)
|
||||
* .end(callback);
|
||||
*
|
||||
* request.post('/')
|
||||
* .type('application/xml')
|
||||
* .send(xmlstring)
|
||||
* .end(callback);
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Request.prototype.type = function(type){
|
||||
this.set('Content-Type', request.types[type] || type);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set Accept to `type`, mapping values from `request.types`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* superagent.types.json = 'application/json';
|
||||
*
|
||||
* request.get('/agent')
|
||||
* .accept('json')
|
||||
* .end(callback);
|
||||
*
|
||||
* request.get('/agent')
|
||||
* .accept('application/json')
|
||||
* .end(callback);
|
||||
*
|
||||
* @param {String} accept
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Request.prototype.accept = function(type){
|
||||
this.set('Accept', request.types[type] || type);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set Authorization field value with `user` and `pass`.
|
||||
*
|
||||
* @param {String} user
|
||||
* @param {String} [pass] optional in case of using 'bearer' as type
|
||||
* @param {Object} options with 'type' property 'auto', 'basic' or 'bearer' (default 'basic')
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Request.prototype.auth = function(user, pass, options){
|
||||
if (1 === arguments.length) pass = '';
|
||||
if (typeof pass === 'object' && pass !== null) { // pass is optional and can be replaced with options
|
||||
options = pass;
|
||||
pass = '';
|
||||
}
|
||||
if (!options) {
|
||||
options = {
|
||||
type: 'function' === typeof btoa ? 'basic' : 'auto',
|
||||
};
|
||||
}
|
||||
|
||||
var encoder = function(string) {
|
||||
if ('function' === typeof btoa) {
|
||||
return btoa(string);
|
||||
}
|
||||
throw new Error('Cannot use basic auth, btoa is not a function');
|
||||
};
|
||||
|
||||
return this._auth(user, pass, options, encoder);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add query-string `val`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* request.get('/shoes')
|
||||
* .query('size=10')
|
||||
* .query({ color: 'blue' })
|
||||
*
|
||||
* @param {Object|String} val
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Request.prototype.query = function(val){
|
||||
if ('string' != typeof val) val = serialize(val);
|
||||
if (val) this._query.push(val);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Queue the given `file` as an attachment to the specified `field`,
|
||||
* with optional `options` (or filename).
|
||||
*
|
||||
* ``` js
|
||||
* request.post('/upload')
|
||||
* .attach('content', new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
||||
* .end(callback);
|
||||
* ```
|
||||
*
|
||||
* @param {String} field
|
||||
* @param {Blob|File} file
|
||||
* @param {String|Object} options
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Request.prototype.attach = function(field, file, options){
|
||||
if (file) {
|
||||
if (this._data) {
|
||||
throw Error("superagent can't mix .send() and .attach()");
|
||||
}
|
||||
|
||||
this._getFormData().append(field, file, options || file.name);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype._getFormData = function(){
|
||||
if (!this._formData) {
|
||||
this._formData = new root.FormData();
|
||||
}
|
||||
return this._formData;
|
||||
};
|
||||
|
||||
/**
|
||||
* Invoke the callback with `err` and `res`
|
||||
* and handle arity check.
|
||||
*
|
||||
* @param {Error} err
|
||||
* @param {Response} res
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Request.prototype.callback = function(err, res){
|
||||
if (this._shouldRetry(err, res)) {
|
||||
return this._retry();
|
||||
}
|
||||
|
||||
var fn = this._callback;
|
||||
this.clearTimeout();
|
||||
|
||||
if (err) {
|
||||
if (this._maxRetries) err.retries = this._retries - 1;
|
||||
this.emit('error', err);
|
||||
}
|
||||
|
||||
fn(err, res);
|
||||
};
|
||||
|
||||
/**
|
||||
* Invoke callback with x-domain error.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Request.prototype.crossDomainError = function(){
|
||||
var err = new Error('Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.');
|
||||
err.crossDomain = true;
|
||||
|
||||
err.status = this.status;
|
||||
err.method = this.method;
|
||||
err.url = this.url;
|
||||
|
||||
this.callback(err);
|
||||
};
|
||||
|
||||
// This only warns, because the request is still likely to work
|
||||
Request.prototype.buffer = Request.prototype.ca = Request.prototype.agent = function(){
|
||||
console.warn("This is not supported in browser version of superagent");
|
||||
return this;
|
||||
};
|
||||
|
||||
// This throws, because it can't send/receive data as expected
|
||||
Request.prototype.pipe = Request.prototype.write = function(){
|
||||
throw Error("Streaming is not supported in browser version of superagent");
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if `obj` is a host object,
|
||||
* we don't want to serialize these :)
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
Request.prototype._isHost = function _isHost(obj) {
|
||||
// Native objects stringify to [object File], [object Blob], [object FormData], etc.
|
||||
return obj && 'object' === typeof obj && !Array.isArray(obj) && Object.prototype.toString.call(obj) !== '[object Object]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate request, invoking callback `fn(res)`
|
||||
* with an instanceof `Response`.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Request.prototype.end = function(fn){
|
||||
if (this._endCalled) {
|
||||
console.warn("Warning: .end() was called twice. This is not supported in superagent");
|
||||
}
|
||||
this._endCalled = true;
|
||||
|
||||
// store callback
|
||||
this._callback = fn || noop;
|
||||
|
||||
// querystring
|
||||
this._finalizeQueryString();
|
||||
|
||||
return this._end();
|
||||
};
|
||||
|
||||
Request.prototype._end = function() {
|
||||
var self = this;
|
||||
var xhr = (this.xhr = request.getXHR());
|
||||
var data = this._formData || this._data;
|
||||
|
||||
this._setTimeouts();
|
||||
|
||||
// state change
|
||||
xhr.onreadystatechange = function(){
|
||||
var readyState = xhr.readyState;
|
||||
if (readyState >= 2 && self._responseTimeoutTimer) {
|
||||
clearTimeout(self._responseTimeoutTimer);
|
||||
}
|
||||
if (4 != readyState) {
|
||||
return;
|
||||
}
|
||||
|
||||
// In IE9, reads to any property (e.g. status) off of an aborted XHR will
|
||||
// result in the error "Could not complete the operation due to error c00c023f"
|
||||
var status;
|
||||
try { status = xhr.status } catch(e) { status = 0; }
|
||||
|
||||
if (!status) {
|
||||
if (self.timedout || self._aborted) return;
|
||||
return self.crossDomainError();
|
||||
}
|
||||
self.emit('end');
|
||||
};
|
||||
|
||||
// progress
|
||||
var handleProgress = function(direction, e) {
|
||||
if (e.total > 0) {
|
||||
e.percent = e.loaded / e.total * 100;
|
||||
}
|
||||
e.direction = direction;
|
||||
self.emit('progress', e);
|
||||
};
|
||||
if (this.hasListeners('progress')) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// initiate request
|
||||
try {
|
||||
if (this.username && this.password) {
|
||||
xhr.open(this.method, this.url, true, this.username, this.password);
|
||||
} else {
|
||||
xhr.open(this.method, this.url, true);
|
||||
}
|
||||
} catch (err) {
|
||||
// see #1149
|
||||
return this.callback(err);
|
||||
}
|
||||
|
||||
// CORS
|
||||
if (this._withCredentials) xhr.withCredentials = true;
|
||||
|
||||
// body
|
||||
if (!this._formData && 'GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !this._isHost(data)) {
|
||||
// serialize stuff
|
||||
var contentType = this._header['content-type'];
|
||||
var serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
||||
if (!serialize && isJSON(contentType)) {
|
||||
serialize = request.serialize['application/json'];
|
||||
}
|
||||
if (serialize) data = serialize(data);
|
||||
}
|
||||
|
||||
// set header fields
|
||||
for (var field in this.header) {
|
||||
if (null == this.header[field]) continue;
|
||||
|
||||
if (this.header.hasOwnProperty(field))
|
||||
xhr.setRequestHeader(field, this.header[field]);
|
||||
}
|
||||
|
||||
if (this._responseType) {
|
||||
xhr.responseType = this._responseType;
|
||||
}
|
||||
|
||||
// send stuff
|
||||
this.emit('request', this);
|
||||
|
||||
// IE11 xhr.send(undefined) sends 'undefined' string as POST payload (instead of nothing)
|
||||
// We need null here if data is undefined
|
||||
xhr.send(typeof data !== 'undefined' ? data : null);
|
||||
return this;
|
||||
};
|
||||
|
||||
request.agent = function() {
|
||||
return new Agent();
|
||||
};
|
||||
|
||||
["GET", "POST", "OPTIONS", "PATCH", "PUT", "DELETE"].forEach(function(method) {
|
||||
Agent.prototype[method.toLowerCase()] = function(url, fn) {
|
||||
var req = new request.Request(method, url);
|
||||
this._setDefaults(req);
|
||||
if (fn) {
|
||||
req.end(fn);
|
||||
}
|
||||
return req;
|
||||
};
|
||||
});
|
||||
|
||||
Agent.prototype.del = Agent.prototype['delete'];
|
||||
|
||||
/**
|
||||
* GET `url` with optional callback `fn(res)`.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Mixed|Function} [data] or fn
|
||||
* @param {Function} [fn]
|
||||
* @return {Request}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
request.get = function(url, data, fn) {
|
||||
var req = request('GET', url);
|
||||
if ('function' == typeof data) (fn = data), (data = null);
|
||||
if (data) req.query(data);
|
||||
if (fn) req.end(fn);
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* HEAD `url` with optional callback `fn(res)`.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Mixed|Function} [data] or fn
|
||||
* @param {Function} [fn]
|
||||
* @return {Request}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
request.head = function(url, data, fn) {
|
||||
var req = request('HEAD', url);
|
||||
if ('function' == typeof data) (fn = data), (data = null);
|
||||
if (data) req.query(data);
|
||||
if (fn) req.end(fn);
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* OPTIONS query to `url` with optional callback `fn(res)`.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Mixed|Function} [data] or fn
|
||||
* @param {Function} [fn]
|
||||
* @return {Request}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
request.options = function(url, data, fn) {
|
||||
var req = request('OPTIONS', url);
|
||||
if ('function' == typeof data) (fn = data), (data = null);
|
||||
if (data) req.send(data);
|
||||
if (fn) req.end(fn);
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* DELETE `url` with optional `data` and callback `fn(res)`.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Mixed} [data]
|
||||
* @param {Function} [fn]
|
||||
* @return {Request}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function del(url, data, fn) {
|
||||
var req = request('DELETE', url);
|
||||
if ('function' == typeof data) (fn = data), (data = null);
|
||||
if (data) req.send(data);
|
||||
if (fn) req.end(fn);
|
||||
return req;
|
||||
}
|
||||
|
||||
request['del'] = del;
|
||||
request['delete'] = del;
|
||||
|
||||
/**
|
||||
* PATCH `url` with optional `data` and callback `fn(res)`.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Mixed} [data]
|
||||
* @param {Function} [fn]
|
||||
* @return {Request}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
request.patch = function(url, data, fn) {
|
||||
var req = request('PATCH', url);
|
||||
if ('function' == typeof data) (fn = data), (data = null);
|
||||
if (data) req.send(data);
|
||||
if (fn) req.end(fn);
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* POST `url` with optional `data` and callback `fn(res)`.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Mixed} [data]
|
||||
* @param {Function} [fn]
|
||||
* @return {Request}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
request.post = function(url, data, fn) {
|
||||
var req = request('POST', url);
|
||||
if ('function' == typeof data) (fn = data), (data = null);
|
||||
if (data) req.send(data);
|
||||
if (fn) req.end(fn);
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* PUT `url` with optional `data` and callback `fn(res)`.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Mixed|Function} [data] or fn
|
||||
* @param {Function} [fn]
|
||||
* @return {Request}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
request.put = function(url, data, fn) {
|
||||
var req = request('PUT', url);
|
||||
if ('function' == typeof data) (fn = data), (data = null);
|
||||
if (data) req.send(data);
|
||||
if (fn) req.end(fn);
|
||||
return req;
|
||||
};
|
||||
15
node_modules/superagent/lib/is-object.js
generated
vendored
Normal file
15
node_modules/superagent/lib/is-object.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Check if `obj` is an object.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function isObject(obj) {
|
||||
return null !== obj && 'object' === typeof obj;
|
||||
}
|
||||
|
||||
module.exports = isObject;
|
||||
92
node_modules/superagent/lib/node/agent.js
generated
vendored
Normal file
92
node_modules/superagent/lib/node/agent.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const CookieJar = require('cookiejar').CookieJar;
|
||||
const CookieAccess = require('cookiejar').CookieAccessInfo;
|
||||
const parse = require('url').parse;
|
||||
const request = require('../..');
|
||||
const AgentBase = require('../agent-base');
|
||||
let methods = require('methods');
|
||||
|
||||
/**
|
||||
* Expose `Agent`.
|
||||
*/
|
||||
|
||||
module.exports = Agent;
|
||||
|
||||
/**
|
||||
* Initialize a new `Agent`.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Agent(options) {
|
||||
if (!(this instanceof Agent)) {
|
||||
return new Agent(options);
|
||||
}
|
||||
AgentBase.call(this);
|
||||
this.jar = new CookieJar();
|
||||
|
||||
if (options) {
|
||||
if (options.ca) {this.ca(options.ca);}
|
||||
if (options.key) {this.key(options.key);}
|
||||
if (options.pfx) {this.pfx(options.pfx);}
|
||||
if (options.cert) {this.cert(options.cert);}
|
||||
}
|
||||
}
|
||||
|
||||
Agent.prototype = Object.create(AgentBase.prototype);
|
||||
|
||||
/**
|
||||
* Save the cookies in the given `res` to
|
||||
* the agent's cookie jar for persistence.
|
||||
*
|
||||
* @param {Response} res
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Agent.prototype._saveCookies = function(res) {
|
||||
const cookies = res.headers['set-cookie'];
|
||||
if (cookies) this.jar.setCookies(cookies);
|
||||
};
|
||||
|
||||
/**
|
||||
* Attach cookies when available to the given `req`.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Agent.prototype._attachCookies = function(req) {
|
||||
const url = parse(req.url);
|
||||
const access = CookieAccess(
|
||||
url.hostname,
|
||||
url.pathname,
|
||||
'https:' == url.protocol
|
||||
);
|
||||
const cookies = this.jar.getCookies(access).toValueString();
|
||||
req.cookies = cookies;
|
||||
};
|
||||
|
||||
methods.forEach(name => {
|
||||
const method = name.toUpperCase();
|
||||
Agent.prototype[name] = function(url, fn) {
|
||||
const req = new request.Request(method, url);
|
||||
|
||||
req.on('response', this._saveCookies.bind(this));
|
||||
req.on('redirect', this._saveCookies.bind(this));
|
||||
req.on('redirect', this._attachCookies.bind(this, req));
|
||||
this._attachCookies(req);
|
||||
this._setDefaults(req);
|
||||
|
||||
if (fn) {
|
||||
req.end(fn);
|
||||
}
|
||||
return req;
|
||||
};
|
||||
});
|
||||
|
||||
Agent.prototype.del = Agent.prototype['delete'];
|
||||
1120
node_modules/superagent/lib/node/index.js
generated
vendored
Normal file
1120
node_modules/superagent/lib/node/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
node_modules/superagent/lib/node/parsers/image.js
generated
vendored
Normal file
12
node_modules/superagent/lib/node/parsers/image.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (res, fn) => {
|
||||
const data = []; // Binary data needs binary storage
|
||||
|
||||
res.on('data', chunk => {
|
||||
data.push(chunk);
|
||||
});
|
||||
res.on('end', () => {
|
||||
fn(null, Buffer.concat(data));
|
||||
});
|
||||
};
|
||||
10
node_modules/superagent/lib/node/parsers/index.js
generated
vendored
Normal file
10
node_modules/superagent/lib/node/parsers/index.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
exports['application/x-www-form-urlencoded'] = require('./urlencoded');
|
||||
exports['application/json'] = require('./json');
|
||||
exports.text = require('./text');
|
||||
|
||||
const binary = require('./image');
|
||||
exports['application/octet-stream'] = binary;
|
||||
exports['application/pdf'] = binary;
|
||||
exports.image = binary;
|
||||
22
node_modules/superagent/lib/node/parsers/json.js
generated
vendored
Normal file
22
node_modules/superagent/lib/node/parsers/json.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function parseJSON(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', chunk => {
|
||||
res.text += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
try {
|
||||
var body = res.text && JSON.parse(res.text);
|
||||
} catch (e) {
|
||||
var err = e;
|
||||
// issue #675: return the raw response if the response parsing fails
|
||||
err.rawResponse = res.text || null;
|
||||
// issue #876: return the http status code if the response parsing fails
|
||||
err.statusCode = res.statusCode;
|
||||
} finally {
|
||||
fn(err, body);
|
||||
}
|
||||
});
|
||||
};
|
||||
10
node_modules/superagent/lib/node/parsers/text.js
generated
vendored
Normal file
10
node_modules/superagent/lib/node/parsers/text.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', chunk => {
|
||||
res.text += chunk;
|
||||
});
|
||||
res.on('end', fn);
|
||||
};
|
||||
22
node_modules/superagent/lib/node/parsers/urlencoded.js
generated
vendored
Normal file
22
node_modules/superagent/lib/node/parsers/urlencoded.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const qs = require('qs');
|
||||
|
||||
module.exports = function(res, fn){
|
||||
res.text = '';
|
||||
res.setEncoding('ascii');
|
||||
res.on('data', chunk => {
|
||||
res.text += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
try {
|
||||
fn(null, qs.parse(res.text));
|
||||
} catch (err) {
|
||||
fn(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
123
node_modules/superagent/lib/node/response.js
generated
vendored
Normal file
123
node_modules/superagent/lib/node/response.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const util = require('util');
|
||||
const Stream = require('stream');
|
||||
const ResponseBase = require('../response-base');
|
||||
|
||||
/**
|
||||
* Expose `Response`.
|
||||
*/
|
||||
|
||||
module.exports = Response;
|
||||
|
||||
/**
|
||||
* Initialize a new `Response` with the given `xhr`.
|
||||
*
|
||||
* - set flags (.ok, .error, etc)
|
||||
* - parse header
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Object} options
|
||||
* @constructor
|
||||
* @extends {Stream}
|
||||
* @implements {ReadableStream}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function Response(req) {
|
||||
Stream.call(this);
|
||||
const res = (this.res = req.res);
|
||||
this.request = req;
|
||||
this.req = req.req;
|
||||
this.text = res.text;
|
||||
this.body = res.body !== undefined ? res.body : {};
|
||||
this.files = res.files || {};
|
||||
this.buffered = 'string' == typeof this.text;
|
||||
this.header = this.headers = res.headers;
|
||||
this._setStatusProperties(res.statusCode);
|
||||
this._setHeaderProperties(this.header);
|
||||
this.setEncoding = res.setEncoding.bind(res);
|
||||
res.on('data', this.emit.bind(this, 'data'));
|
||||
res.on('end', this.emit.bind(this, 'end'));
|
||||
res.on('close', this.emit.bind(this, 'close'));
|
||||
res.on('error', this.emit.bind(this, 'error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Stream`.
|
||||
*/
|
||||
|
||||
util.inherits(Response, Stream);
|
||||
ResponseBase(Response.prototype);
|
||||
|
||||
/**
|
||||
* Implements methods of a `ReadableStream`
|
||||
*/
|
||||
|
||||
Response.prototype.destroy = function(err){
|
||||
this.res.destroy(err);
|
||||
};
|
||||
|
||||
/**
|
||||
* Pause.
|
||||
*/
|
||||
|
||||
Response.prototype.pause = function(){
|
||||
this.res.pause();
|
||||
};
|
||||
|
||||
/**
|
||||
* Resume.
|
||||
*/
|
||||
|
||||
Response.prototype.resume = function(){
|
||||
this.res.resume();
|
||||
};
|
||||
|
||||
/**
|
||||
* Return an `Error` representative of this response.
|
||||
*
|
||||
* @return {Error}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Response.prototype.toError = function() {
|
||||
const req = this.req;
|
||||
const method = req.method;
|
||||
const path = req.path;
|
||||
|
||||
const msg = `cannot ${method} ${path} (${this.status})`;
|
||||
const err = new Error(msg);
|
||||
err.status = this.status;
|
||||
err.text = this.text;
|
||||
err.method = method;
|
||||
err.path = path;
|
||||
|
||||
return err;
|
||||
};
|
||||
|
||||
|
||||
Response.prototype.setStatusProperties = function(status){
|
||||
console.warn("In superagent 2.x setStatusProperties is a private method");
|
||||
return this._setStatusProperties(status);
|
||||
};
|
||||
|
||||
/**
|
||||
* To json.
|
||||
*
|
||||
* @return {Object}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Response.prototype.toJSON = function() {
|
||||
return {
|
||||
req: this.request.toJSON(),
|
||||
header: this.header,
|
||||
status: this.status,
|
||||
text: this.text,
|
||||
};
|
||||
};
|
||||
71
node_modules/superagent/lib/node/unzip.js
generated
vendored
Normal file
71
node_modules/superagent/lib/node/unzip.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const StringDecoder = require('string_decoder').StringDecoder;
|
||||
const Stream = require('stream');
|
||||
const zlib = require('zlib');
|
||||
|
||||
/**
|
||||
* Buffers response data events and re-emits when they're unzipped.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.unzip = (req, res) => {
|
||||
const unzip = zlib.createUnzip();
|
||||
const stream = new Stream();
|
||||
let decoder;
|
||||
|
||||
// make node responseOnEnd() happy
|
||||
stream.req = req;
|
||||
|
||||
unzip.on('error', 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);
|
||||
});
|
||||
|
||||
// pipe to unzip
|
||||
res.pipe(unzip);
|
||||
|
||||
// override `setEncoding` to capture encoding
|
||||
res.setEncoding = type => {
|
||||
decoder = new StringDecoder(type);
|
||||
};
|
||||
|
||||
// decode upon decompressing with captured encoding
|
||||
unzip.on('data', buf => {
|
||||
if (decoder) {
|
||||
const str = decoder.write(buf);
|
||||
if (str.length) stream.emit('data', str);
|
||||
} else {
|
||||
stream.emit('data', buf);
|
||||
}
|
||||
});
|
||||
|
||||
unzip.on('end', () => {
|
||||
stream.emit('end');
|
||||
});
|
||||
|
||||
// override `on` to capture data listeners
|
||||
const _on = res.on;
|
||||
res.on = function(type, fn) {
|
||||
if ('data' == type || 'end' == type) {
|
||||
stream.on(type, fn);
|
||||
} else if ('error' == type) {
|
||||
stream.on(type, fn);
|
||||
_on.call(res, type, fn);
|
||||
} else {
|
||||
_on.call(res, type, fn);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
};
|
||||
694
node_modules/superagent/lib/request-base.js
generated
vendored
Normal file
694
node_modules/superagent/lib/request-base.js
generated
vendored
Normal file
@@ -0,0 +1,694 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module of mixed-in functions shared between node and client code
|
||||
*/
|
||||
var isObject = require('./is-object');
|
||||
|
||||
/**
|
||||
* Expose `RequestBase`.
|
||||
*/
|
||||
|
||||
module.exports = RequestBase;
|
||||
|
||||
/**
|
||||
* Initialize a new `RequestBase`.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function RequestBase(obj) {
|
||||
if (obj) return mixin(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixin the prototype properties.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function mixin(obj) {
|
||||
for (var key in RequestBase.prototype) {
|
||||
obj[key] = RequestBase.prototype[key];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear previous timeout.
|
||||
*
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.clearTimeout = function _clearTimeout(){
|
||||
clearTimeout(this._timer);
|
||||
clearTimeout(this._responseTimeoutTimer);
|
||||
delete this._timer;
|
||||
delete this._responseTimeoutTimer;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Override default response body parser
|
||||
*
|
||||
* This function will be called to convert incoming data into request.body
|
||||
*
|
||||
* @param {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.parse = function parse(fn){
|
||||
this._parser = fn;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set format of binary response body.
|
||||
* In browser valid formats are 'blob' and 'arraybuffer',
|
||||
* which return Blob and ArrayBuffer, respectively.
|
||||
*
|
||||
* In Node all values result in Buffer.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* req.get('/')
|
||||
* .responseType('blob')
|
||||
* .end(callback);
|
||||
*
|
||||
* @param {String} val
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.responseType = function(val){
|
||||
this._responseType = val;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Override default request body serializer
|
||||
*
|
||||
* This function will be called to convert data set via .send or .attach into payload to send
|
||||
*
|
||||
* @param {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.serialize = function serialize(fn){
|
||||
this._serializer = fn;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set timeouts.
|
||||
*
|
||||
* - response timeout is time between sending request and receiving the first byte of the response. Includes DNS and connection time.
|
||||
* - deadline is the time from start of the request to receiving response body in full. If the deadline is too short large files may not load at all on slow connections.
|
||||
*
|
||||
* Value of 0 or false means no timeout.
|
||||
*
|
||||
* @param {Number|Object} ms or {response, deadline}
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.timeout = function timeout(options){
|
||||
if (!options || 'object' !== typeof options) {
|
||||
this._timeout = options;
|
||||
this._responseTimeout = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
for(var option in options) {
|
||||
switch(option) {
|
||||
case 'deadline':
|
||||
this._timeout = options.deadline;
|
||||
break;
|
||||
case 'response':
|
||||
this._responseTimeout = options.response;
|
||||
break;
|
||||
default:
|
||||
console.warn("Unknown timeout option", option);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set number of retry attempts on error.
|
||||
*
|
||||
* Failed requests will be retried 'count' times if timeout or err.code >= 500.
|
||||
*
|
||||
* @param {Number} count
|
||||
* @param {Function} [fn]
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.retry = function retry(count, fn){
|
||||
// Default to 1 if no count passed or true
|
||||
if (arguments.length === 0 || count === true) count = 1;
|
||||
if (count <= 0) count = 0;
|
||||
this._maxRetries = count;
|
||||
this._retries = 0;
|
||||
this._retryCallback = fn;
|
||||
return this;
|
||||
};
|
||||
|
||||
var ERROR_CODES = [
|
||||
'ECONNRESET',
|
||||
'ETIMEDOUT',
|
||||
'EADDRINFO',
|
||||
'ESOCKETTIMEDOUT'
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if a request should be retried.
|
||||
* (Borrowed from segmentio/superagent-retry)
|
||||
*
|
||||
* @param {Error} err
|
||||
* @param {Response} [res]
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
RequestBase.prototype._shouldRetry = function(err, res) {
|
||||
if (!this._maxRetries || this._retries++ >= this._maxRetries) {
|
||||
return false;
|
||||
}
|
||||
if (this._retryCallback) {
|
||||
try {
|
||||
var override = this._retryCallback(err, res);
|
||||
if (override === true) return true;
|
||||
if (override === false) return false;
|
||||
// undefined falls back to defaults
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
if (res && res.status && res.status >= 500 && res.status != 501) return true;
|
||||
if (err) {
|
||||
if (err.code && ~ERROR_CODES.indexOf(err.code)) return true;
|
||||
// Superagent timeout
|
||||
if (err.timeout && err.code == 'ECONNABORTED') return true;
|
||||
if (err.crossDomain) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retry request
|
||||
*
|
||||
* @return {Request} for chaining
|
||||
* @api private
|
||||
*/
|
||||
|
||||
RequestBase.prototype._retry = function() {
|
||||
|
||||
this.clearTimeout();
|
||||
|
||||
// node
|
||||
if (this.req) {
|
||||
this.req = null;
|
||||
this.req = this.request();
|
||||
}
|
||||
|
||||
this._aborted = false;
|
||||
this.timedout = false;
|
||||
|
||||
return this._end();
|
||||
};
|
||||
|
||||
/**
|
||||
* Promise support
|
||||
*
|
||||
* @param {Function} resolve
|
||||
* @param {Function} [reject]
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
RequestBase.prototype.then = function then(resolve, reject) {
|
||||
if (!this._fullfilledPromise) {
|
||||
var self = this;
|
||||
if (this._endCalled) {
|
||||
console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises");
|
||||
}
|
||||
this._fullfilledPromise = new Promise(function(innerResolve, innerReject) {
|
||||
self.end(function(err, res) {
|
||||
if (err) innerReject(err);
|
||||
else innerResolve(res);
|
||||
});
|
||||
});
|
||||
}
|
||||
return this._fullfilledPromise.then(resolve, reject);
|
||||
};
|
||||
|
||||
RequestBase.prototype['catch'] = function(cb) {
|
||||
return this.then(undefined, cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Allow for extension
|
||||
*/
|
||||
|
||||
RequestBase.prototype.use = function use(fn) {
|
||||
fn(this);
|
||||
return this;
|
||||
};
|
||||
|
||||
RequestBase.prototype.ok = function(cb) {
|
||||
if ('function' !== typeof cb) throw Error("Callback required");
|
||||
this._okCallback = cb;
|
||||
return this;
|
||||
};
|
||||
|
||||
RequestBase.prototype._isResponseOK = function(res) {
|
||||
if (!res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._okCallback) {
|
||||
return this._okCallback(res);
|
||||
}
|
||||
|
||||
return res.status >= 200 && res.status < 300;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get request header `field`.
|
||||
* Case-insensitive.
|
||||
*
|
||||
* @param {String} field
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.get = function(field){
|
||||
return this._header[field.toLowerCase()];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get case-insensitive header `field` value.
|
||||
* This is a deprecated internal API. Use `.get(field)` instead.
|
||||
*
|
||||
* (getHeader is no longer used internally by the superagent code base)
|
||||
*
|
||||
* @param {String} field
|
||||
* @return {String}
|
||||
* @api private
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
RequestBase.prototype.getHeader = RequestBase.prototype.get;
|
||||
|
||||
/**
|
||||
* Set header `field` to `val`, or multiple fields with one object.
|
||||
* Case-insensitive.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* req.get('/')
|
||||
* .set('Accept', 'application/json')
|
||||
* .set('X-API-Key', 'foobar')
|
||||
* .end(callback);
|
||||
*
|
||||
* req.get('/')
|
||||
* .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
||||
* .end(callback);
|
||||
*
|
||||
* @param {String|Object} field
|
||||
* @param {String} val
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.set = function(field, val){
|
||||
if (isObject(field)) {
|
||||
for (var key in field) {
|
||||
this.set(key, field[key]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
this._header[field.toLowerCase()] = val;
|
||||
this.header[field] = val;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove header `field`.
|
||||
* Case-insensitive.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* req.get('/')
|
||||
* .unset('User-Agent')
|
||||
* .end(callback);
|
||||
*
|
||||
* @param {String} field
|
||||
*/
|
||||
RequestBase.prototype.unset = function(field){
|
||||
delete this._header[field.toLowerCase()];
|
||||
delete this.header[field];
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Write the field `name` and `val`, or multiple fields with one object
|
||||
* for "multipart/form-data" request bodies.
|
||||
*
|
||||
* ``` js
|
||||
* request.post('/upload')
|
||||
* .field('foo', 'bar')
|
||||
* .end(callback);
|
||||
*
|
||||
* request.post('/upload')
|
||||
* .field({ foo: 'bar', baz: 'qux' })
|
||||
* .end(callback);
|
||||
* ```
|
||||
*
|
||||
* @param {String|Object} name
|
||||
* @param {String|Blob|File|Buffer|fs.ReadStream} val
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
RequestBase.prototype.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 (this._data) {
|
||||
console.error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");
|
||||
}
|
||||
|
||||
if (isObject(name)) {
|
||||
for (var key in name) {
|
||||
this.field(key, name[key]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
for (var i in val) {
|
||||
this.field(name, val[i]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// val should be defined now
|
||||
if (null === val || undefined === val) {
|
||||
throw new Error('.field(name, val) val can not be empty');
|
||||
}
|
||||
if ('boolean' === typeof val) {
|
||||
val = '' + val;
|
||||
}
|
||||
this._getFormData().append(name, val);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Abort the request, and clear potential timeout.
|
||||
*
|
||||
* @return {Request}
|
||||
* @api public
|
||||
*/
|
||||
RequestBase.prototype.abort = function(){
|
||||
if (this._aborted) {
|
||||
return this;
|
||||
}
|
||||
this._aborted = true;
|
||||
this.xhr && this.xhr.abort(); // browser
|
||||
this.req && this.req.abort(); // node
|
||||
this.clearTimeout();
|
||||
this.emit('abort');
|
||||
return this;
|
||||
};
|
||||
|
||||
RequestBase.prototype._auth = function(user, pass, options, base64Encoder) {
|
||||
switch (options.type) {
|
||||
case 'basic':
|
||||
this.set('Authorization', 'Basic ' + base64Encoder(user + ':' + pass));
|
||||
break;
|
||||
|
||||
case 'auto':
|
||||
this.username = user;
|
||||
this.password = pass;
|
||||
break;
|
||||
|
||||
case 'bearer': // usage would be .auth(accessToken, { type: 'bearer' })
|
||||
this.set('Authorization', 'Bearer ' + user);
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enable transmission of cookies with x-domain requests.
|
||||
*
|
||||
* Note that for this to work the origin must not be
|
||||
* using "Access-Control-Allow-Origin" with a wildcard,
|
||||
* and also must set "Access-Control-Allow-Credentials"
|
||||
* to "true".
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.withCredentials = function(on) {
|
||||
// This is browser-only functionality. Node side is no-op.
|
||||
if (on == undefined) on = true;
|
||||
this._withCredentials = on;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the max redirects to `n`. Does noting in browser XHR implementation.
|
||||
*
|
||||
* @param {Number} n
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.redirects = function(n){
|
||||
this._maxRedirects = n;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Maximum size of buffered response body, in bytes. Counts uncompressed size.
|
||||
* Default 200MB.
|
||||
*
|
||||
* @param {Number} n
|
||||
* @return {Request} for chaining
|
||||
*/
|
||||
RequestBase.prototype.maxResponseSize = function(n){
|
||||
if ('number' !== typeof n) {
|
||||
throw TypeError("Invalid argument");
|
||||
}
|
||||
this._maxResponseSize = n;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert to a plain javascript object (not JSON string) of scalar properties.
|
||||
* Note as this method is designed to return a useful non-this value,
|
||||
* it cannot be chained.
|
||||
*
|
||||
* @return {Object} describing method, url, and data of this request
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.toJSON = function() {
|
||||
return {
|
||||
method: this.method,
|
||||
url: this.url,
|
||||
data: this._data,
|
||||
headers: this._header,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Send `data` as the request body, defaulting the `.type()` to "json" when
|
||||
* an object is given.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // manual json
|
||||
* request.post('/user')
|
||||
* .type('json')
|
||||
* .send('{"name":"tj"}')
|
||||
* .end(callback)
|
||||
*
|
||||
* // auto json
|
||||
* request.post('/user')
|
||||
* .send({ name: 'tj' })
|
||||
* .end(callback)
|
||||
*
|
||||
* // manual x-www-form-urlencoded
|
||||
* request.post('/user')
|
||||
* .type('form')
|
||||
* .send('name=tj')
|
||||
* .end(callback)
|
||||
*
|
||||
* // auto x-www-form-urlencoded
|
||||
* request.post('/user')
|
||||
* .type('form')
|
||||
* .send({ name: 'tj' })
|
||||
* .end(callback)
|
||||
*
|
||||
* // defaults to x-www-form-urlencoded
|
||||
* request.post('/user')
|
||||
* .send('name=tobi')
|
||||
* .send('species=ferret')
|
||||
* .end(callback)
|
||||
*
|
||||
* @param {String|Object} data
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.send = function(data){
|
||||
var isObj = isObject(data);
|
||||
var type = this._header['content-type'];
|
||||
|
||||
if (this._formData) {
|
||||
console.error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");
|
||||
}
|
||||
|
||||
if (isObj && !this._data) {
|
||||
if (Array.isArray(data)) {
|
||||
this._data = [];
|
||||
} else if (!this._isHost(data)) {
|
||||
this._data = {};
|
||||
}
|
||||
} else if (data && this._data && this._isHost(this._data)) {
|
||||
throw Error("Can't merge these send calls");
|
||||
}
|
||||
|
||||
// merge
|
||||
if (isObj && isObject(this._data)) {
|
||||
for (var key in data) {
|
||||
this._data[key] = data[key];
|
||||
}
|
||||
} else if ('string' == typeof data) {
|
||||
// default to x-www-form-urlencoded
|
||||
if (!type) this.type('form');
|
||||
type = this._header['content-type'];
|
||||
if ('application/x-www-form-urlencoded' == type) {
|
||||
this._data = this._data
|
||||
? this._data + '&' + data
|
||||
: data;
|
||||
} else {
|
||||
this._data = (this._data || '') + data;
|
||||
}
|
||||
} else {
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
if (!isObj || this._isHost(data)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// default to json
|
||||
if (!type) this.type('json');
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sort `querystring` by the sort function
|
||||
*
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* // default order
|
||||
* request.get('/user')
|
||||
* .query('name=Nick')
|
||||
* .query('search=Manny')
|
||||
* .sortQuery()
|
||||
* .end(callback)
|
||||
*
|
||||
* // customized sort function
|
||||
* request.get('/user')
|
||||
* .query('name=Nick')
|
||||
* .query('search=Manny')
|
||||
* .sortQuery(function(a, b){
|
||||
* return a.length - b.length;
|
||||
* })
|
||||
* .end(callback)
|
||||
*
|
||||
*
|
||||
* @param {Function} sort
|
||||
* @return {Request} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
RequestBase.prototype.sortQuery = function(sort) {
|
||||
// _sort default to true but otherwise can be a function or boolean
|
||||
this._sort = typeof sort === 'undefined' ? true : sort;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compose querystring to append to req.url
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
RequestBase.prototype._finalizeQueryString = function(){
|
||||
var query = this._query.join('&');
|
||||
if (query) {
|
||||
this.url += (this.url.indexOf('?') >= 0 ? '&' : '?') + query;
|
||||
}
|
||||
this._query.length = 0; // Makes the call idempotent
|
||||
|
||||
if (this._sort) {
|
||||
var index = this.url.indexOf('?');
|
||||
if (index >= 0) {
|
||||
var queryArr = this.url.substring(index + 1).split('&');
|
||||
if ('function' === typeof this._sort) {
|
||||
queryArr.sort(this._sort);
|
||||
} else {
|
||||
queryArr.sort();
|
||||
}
|
||||
this.url = this.url.substring(0, index) + '?' + queryArr.join('&');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// For backwards compat only
|
||||
RequestBase.prototype._appendQueryString = function() {console.trace("Unsupported");}
|
||||
|
||||
/**
|
||||
* Invoke callback with timeout error.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
RequestBase.prototype._timeoutError = function(reason, timeout, errno){
|
||||
if (this._aborted) {
|
||||
return;
|
||||
}
|
||||
var err = new Error(reason + timeout + 'ms exceeded');
|
||||
err.timeout = timeout;
|
||||
err.code = 'ECONNABORTED';
|
||||
err.errno = errno;
|
||||
this.timedout = true;
|
||||
this.abort();
|
||||
this.callback(err);
|
||||
};
|
||||
|
||||
RequestBase.prototype._setTimeouts = function() {
|
||||
var self = this;
|
||||
|
||||
// deadline
|
||||
if (this._timeout && !this._timer) {
|
||||
this._timer = setTimeout(function(){
|
||||
self._timeoutError('Timeout of ', self._timeout, 'ETIME');
|
||||
}, this._timeout);
|
||||
}
|
||||
// response timeout
|
||||
if (this._responseTimeout && !this._responseTimeoutTimer) {
|
||||
this._responseTimeoutTimer = setTimeout(function(){
|
||||
self._timeoutError('Response timeout of ', self._responseTimeout, 'ETIMEDOUT');
|
||||
}, this._responseTimeout);
|
||||
}
|
||||
};
|
||||
136
node_modules/superagent/lib/response-base.js
generated
vendored
Normal file
136
node_modules/superagent/lib/response-base.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var utils = require('./utils');
|
||||
|
||||
/**
|
||||
* Expose `ResponseBase`.
|
||||
*/
|
||||
|
||||
module.exports = ResponseBase;
|
||||
|
||||
/**
|
||||
* Initialize a new `ResponseBase`.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function ResponseBase(obj) {
|
||||
if (obj) return mixin(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixin the prototype properties.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function mixin(obj) {
|
||||
for (var key in ResponseBase.prototype) {
|
||||
obj[key] = ResponseBase.prototype[key];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get case-insensitive `field` value.
|
||||
*
|
||||
* @param {String} field
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
ResponseBase.prototype.get = function(field) {
|
||||
return this.header[field.toLowerCase()];
|
||||
};
|
||||
|
||||
/**
|
||||
* Set header related properties:
|
||||
*
|
||||
* - `.type` the content type without params
|
||||
*
|
||||
* A response of "Content-Type: text/plain; charset=utf-8"
|
||||
* will provide you with a `.type` of "text/plain".
|
||||
*
|
||||
* @param {Object} header
|
||||
* @api private
|
||||
*/
|
||||
|
||||
ResponseBase.prototype._setHeaderProperties = function(header){
|
||||
// TODO: moar!
|
||||
// TODO: make this a util
|
||||
|
||||
// content-type
|
||||
var ct = header['content-type'] || '';
|
||||
this.type = utils.type(ct);
|
||||
|
||||
// params
|
||||
var params = utils.params(ct);
|
||||
for (var key in params) this[key] = params[key];
|
||||
|
||||
this.links = {};
|
||||
|
||||
// links
|
||||
try {
|
||||
if (header.link) {
|
||||
this.links = utils.parseLinks(header.link);
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set flags such as `.ok` based on `status`.
|
||||
*
|
||||
* For example a 2xx response will give you a `.ok` of __true__
|
||||
* whereas 5xx will be __false__ and `.error` will be __true__. The
|
||||
* `.clientError` and `.serverError` are also available to be more
|
||||
* specific, and `.statusType` is the class of error ranging from 1..5
|
||||
* sometimes useful for mapping respond colors etc.
|
||||
*
|
||||
* "sugar" properties are also defined for common cases. Currently providing:
|
||||
*
|
||||
* - .noContent
|
||||
* - .badRequest
|
||||
* - .unauthorized
|
||||
* - .notAcceptable
|
||||
* - .notFound
|
||||
*
|
||||
* @param {Number} status
|
||||
* @api private
|
||||
*/
|
||||
|
||||
ResponseBase.prototype._setStatusProperties = function(status){
|
||||
var type = status / 100 | 0;
|
||||
|
||||
// status / class
|
||||
this.status = this.statusCode = status;
|
||||
this.statusType = type;
|
||||
|
||||
// basics
|
||||
this.info = 1 == type;
|
||||
this.ok = 2 == type;
|
||||
this.redirect = 3 == type;
|
||||
this.clientError = 4 == type;
|
||||
this.serverError = 5 == type;
|
||||
this.error = (4 == type || 5 == type)
|
||||
? this.toError()
|
||||
: false;
|
||||
|
||||
// sugar
|
||||
this.created = 201 == status;
|
||||
this.accepted = 202 == status;
|
||||
this.noContent = 204 == status;
|
||||
this.badRequest = 400 == status;
|
||||
this.unauthorized = 401 == status;
|
||||
this.notAcceptable = 406 == status;
|
||||
this.forbidden = 403 == status;
|
||||
this.notFound = 404 == status;
|
||||
this.unprocessableEntity = 422 == status;
|
||||
};
|
||||
71
node_modules/superagent/lib/utils.js
generated
vendored
Normal file
71
node_modules/superagent/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Return the mime type for the given `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.type = function(str){
|
||||
return str.split(/ *; */).shift();
|
||||
};
|
||||
|
||||
/**
|
||||
* Return header field parameters.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.params = function(str){
|
||||
return str.split(/ *; */).reduce(function(obj, str){
|
||||
var parts = str.split(/ *= */);
|
||||
var key = parts.shift();
|
||||
var val = parts.shift();
|
||||
|
||||
if (key && val) obj[key] = val;
|
||||
return obj;
|
||||
}, {});
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse Link header fields.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.parseLinks = function(str){
|
||||
return str.split(/ *, */).reduce(function(obj, str){
|
||||
var parts = str.split(/ *; */);
|
||||
var url = parts[0].slice(1, -1);
|
||||
var rel = parts[1].split(/ *= */)[1].slice(1, -1);
|
||||
obj[rel] = url;
|
||||
return obj;
|
||||
}, {});
|
||||
};
|
||||
|
||||
/**
|
||||
* Strip content related fields from `header`.
|
||||
*
|
||||
* @param {Object} header
|
||||
* @return {Object} header
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.cleanHeader = function(header, changesOrigin){
|
||||
delete header['content-type'];
|
||||
delete header['content-length'];
|
||||
delete header['transfer-encoding'];
|
||||
delete header['host'];
|
||||
// secuirty
|
||||
if (changesOrigin) {
|
||||
delete header['authorization'];
|
||||
delete header['cookie'];
|
||||
}
|
||||
return header;
|
||||
};
|
||||
108
node_modules/superagent/package.json
generated
vendored
Normal file
108
node_modules/superagent/package.json
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"_from": "superagent",
|
||||
"_id": "superagent@3.8.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA==",
|
||||
"_location": "/superagent",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "superagent",
|
||||
"name": "superagent",
|
||||
"escapedName": "superagent",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.3.tgz",
|
||||
"_shasum": "460ea0dbdb7d5b11bc4f78deba565f86a178e128",
|
||||
"_spec": "superagent",
|
||||
"_where": "C:\\Users\\mkswa\\Documents\\osrs-json-hiscores",
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/node/index.js": "./lib/client.js",
|
||||
"./test/support/server.js": "./test/support/blank.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/visionmedia/superagent/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"component": {
|
||||
"scripts": {
|
||||
"superagent": "lib/client.js"
|
||||
}
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Kornel Lesiński",
|
||||
"email": "kornel@geekhood.net"
|
||||
},
|
||||
{
|
||||
"name": "Peter Lyons",
|
||||
"email": "pete@peterlyons.com"
|
||||
},
|
||||
{
|
||||
"name": "Hunter Loftis",
|
||||
"email": "hunter@hunterloftis.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"component-emitter": "^1.2.0",
|
||||
"cookiejar": "^2.1.0",
|
||||
"debug": "^3.1.0",
|
||||
"extend": "^3.0.0",
|
||||
"form-data": "^2.3.1",
|
||||
"formidable": "^1.2.0",
|
||||
"methods": "^1.1.1",
|
||||
"mime": "^1.4.1",
|
||||
"qs": "^6.5.1",
|
||||
"readable-stream": "^2.3.5"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "elegant & feature rich browser / node HTTP with a fluent API",
|
||||
"devDependencies": {
|
||||
"Base64": "^1.0.1",
|
||||
"basic-auth-connect": "^1.0.0",
|
||||
"body-parser": "^1.18.2",
|
||||
"browserify": "^14.1.0",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"express": "^4.16.3",
|
||||
"express-session": "^1.15.6",
|
||||
"marked": "0.3.12",
|
||||
"mocha": "^3.5.3",
|
||||
"multer": "^1.3.0",
|
||||
"should": "^11.2.0",
|
||||
"should-http": "^0.1.1",
|
||||
"zuul": "^3.11.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4.0"
|
||||
},
|
||||
"homepage": "https://github.com/visionmedia/superagent#readme",
|
||||
"keywords": [
|
||||
"http",
|
||||
"ajax",
|
||||
"request",
|
||||
"agent"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/node/index.js",
|
||||
"name": "superagent",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/visionmedia/superagent.git"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "make all",
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "3.8.3"
|
||||
}
|
||||
2035
node_modules/superagent/superagent.js
generated
vendored
Normal file
2035
node_modules/superagent/superagent.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7
node_modules/superagent/test.js
generated
vendored
Normal file
7
node_modules/superagent/test.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
const request = require('./lib/node');
|
||||
|
||||
request.post('nevermind')
|
||||
.field({a:1,b:2})
|
||||
.attach('c', 'does-not-exist.txt')
|
||||
.then(() => assert.fail("It should not allow this"))
|
||||
.catch(() => true);
|
||||
3676
node_modules/superagent/yarn.lock
generated
vendored
Normal file
3676
node_modules/superagent/yarn.lock
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user