parent
f162d2fe21
commit
ba893df15f
@ -1 +0,0 @@ |
|||||||
Subproject commit 53acb93454b9a175edd8439aa172420d25bb03bf |
|
@ -0,0 +1 @@ |
|||||||
|
web: node server |
@ -0,0 +1,4 @@ |
|||||||
|
git add * |
||||||
|
git commit -m "Committing" |
||||||
|
git push |
||||||
|
heroku logs --tail |
@ -0,0 +1,15 @@ |
|||||||
|
#!/bin/sh |
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") |
||||||
|
|
||||||
|
case `uname` in |
||||||
|
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; |
||||||
|
esac |
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then |
||||||
|
"$basedir/node" "$basedir/../mime/cli.js" "$@" |
||||||
|
ret=$? |
||||||
|
else |
||||||
|
node "$basedir/../mime/cli.js" "$@" |
||||||
|
ret=$? |
||||||
|
fi |
||||||
|
exit $ret |
@ -0,0 +1,17 @@ |
|||||||
|
@ECHO off |
||||||
|
SETLOCAL |
||||||
|
CALL :find_dp0 |
||||||
|
|
||||||
|
IF EXIST "%dp0%\node.exe" ( |
||||||
|
SET "_prog=%dp0%\node.exe" |
||||||
|
) ELSE ( |
||||||
|
SET "_prog=node" |
||||||
|
SET PATHEXT=%PATHEXT:;.JS;=;% |
||||||
|
) |
||||||
|
|
||||||
|
"%_prog%" "%dp0%\..\mime\cli.js" %* |
||||||
|
ENDLOCAL |
||||||
|
EXIT /b %errorlevel% |
||||||
|
:find_dp0 |
||||||
|
SET dp0=%~dp0 |
||||||
|
EXIT /b |
@ -0,0 +1,18 @@ |
|||||||
|
#!/usr/bin/env pwsh |
||||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent |
||||||
|
|
||||||
|
$exe="" |
||||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { |
||||||
|
# Fix case when both the Windows and Linux builds of Node |
||||||
|
# are installed in the same directory |
||||||
|
$exe=".exe" |
||||||
|
} |
||||||
|
$ret=0 |
||||||
|
if (Test-Path "$basedir/node$exe") { |
||||||
|
& "$basedir/node$exe" "$basedir/../mime/cli.js" $args |
||||||
|
$ret=$LASTEXITCODE |
||||||
|
} else { |
||||||
|
& "node$exe" "$basedir/../mime/cli.js" $args |
||||||
|
$ret=$LASTEXITCODE |
||||||
|
} |
||||||
|
exit $ret |
@ -0,0 +1,236 @@ |
|||||||
|
1.3.7 / 2019-04-29 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: negotiator@0.6.2 |
||||||
|
- Fix sorting charset, encoding, and language with extra parameters |
||||||
|
|
||||||
|
1.3.6 / 2019-04-28 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.24 |
||||||
|
- deps: mime-db@~1.40.0 |
||||||
|
|
||||||
|
1.3.5 / 2018-02-28 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.18 |
||||||
|
- deps: mime-db@~1.33.0 |
||||||
|
|
||||||
|
1.3.4 / 2017-08-22 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.16 |
||||||
|
- deps: mime-db@~1.29.0 |
||||||
|
|
||||||
|
1.3.3 / 2016-05-02 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.11 |
||||||
|
- deps: mime-db@~1.23.0 |
||||||
|
* deps: negotiator@0.6.1 |
||||||
|
- perf: improve `Accept` parsing speed |
||||||
|
- perf: improve `Accept-Charset` parsing speed |
||||||
|
- perf: improve `Accept-Encoding` parsing speed |
||||||
|
- perf: improve `Accept-Language` parsing speed |
||||||
|
|
||||||
|
1.3.2 / 2016-03-08 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.10 |
||||||
|
- Fix extension of `application/dash+xml` |
||||||
|
- Update primary extension for `audio/mp4` |
||||||
|
- deps: mime-db@~1.22.0 |
||||||
|
|
||||||
|
1.3.1 / 2016-01-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.9 |
||||||
|
- deps: mime-db@~1.21.0 |
||||||
|
|
||||||
|
1.3.0 / 2015-09-29 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.7 |
||||||
|
- deps: mime-db@~1.19.0 |
||||||
|
* deps: negotiator@0.6.0 |
||||||
|
- Fix including type extensions in parameters in `Accept` parsing |
||||||
|
- Fix parsing `Accept` parameters with quoted equals |
||||||
|
- Fix parsing `Accept` parameters with quoted semicolons |
||||||
|
- Lazy-load modules from main entry point |
||||||
|
- perf: delay type concatenation until needed |
||||||
|
- perf: enable strict mode |
||||||
|
- perf: hoist regular expressions |
||||||
|
- perf: remove closures getting spec properties |
||||||
|
- perf: remove a closure from media type parsing |
||||||
|
- perf: remove property delete from media type parsing |
||||||
|
|
||||||
|
1.2.13 / 2015-09-06 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.6 |
||||||
|
- deps: mime-db@~1.18.0 |
||||||
|
|
||||||
|
1.2.12 / 2015-07-30 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.4 |
||||||
|
- deps: mime-db@~1.16.0 |
||||||
|
|
||||||
|
1.2.11 / 2015-07-16 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.3 |
||||||
|
- deps: mime-db@~1.15.0 |
||||||
|
|
||||||
|
1.2.10 / 2015-07-01 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.2 |
||||||
|
- deps: mime-db@~1.14.0 |
||||||
|
|
||||||
|
1.2.9 / 2015-06-08 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.1 |
||||||
|
- perf: fix deopt during mapping |
||||||
|
|
||||||
|
1.2.8 / 2015-06-07 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.1.0 |
||||||
|
- deps: mime-db@~1.13.0 |
||||||
|
* perf: avoid argument reassignment & argument slice |
||||||
|
* perf: avoid negotiator recursive construction |
||||||
|
* perf: enable strict mode |
||||||
|
* perf: remove unnecessary bitwise operator |
||||||
|
|
||||||
|
1.2.7 / 2015-05-10 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: negotiator@0.5.3 |
||||||
|
- Fix media type parameter matching to be case-insensitive |
||||||
|
|
||||||
|
1.2.6 / 2015-05-07 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.0.11 |
||||||
|
- deps: mime-db@~1.9.1 |
||||||
|
* deps: negotiator@0.5.2 |
||||||
|
- Fix comparing media types with quoted values |
||||||
|
- Fix splitting media types with quoted commas |
||||||
|
|
||||||
|
1.2.5 / 2015-03-13 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.0.10 |
||||||
|
- deps: mime-db@~1.8.0 |
||||||
|
|
||||||
|
1.2.4 / 2015-02-14 |
||||||
|
================== |
||||||
|
|
||||||
|
* Support Node.js 0.6 |
||||||
|
* deps: mime-types@~2.0.9 |
||||||
|
- deps: mime-db@~1.7.0 |
||||||
|
* deps: negotiator@0.5.1 |
||||||
|
- Fix preference sorting to be stable for long acceptable lists |
||||||
|
|
||||||
|
1.2.3 / 2015-01-31 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.0.8 |
||||||
|
- deps: mime-db@~1.6.0 |
||||||
|
|
||||||
|
1.2.2 / 2014-12-30 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.0.7 |
||||||
|
- deps: mime-db@~1.5.0 |
||||||
|
|
||||||
|
1.2.1 / 2014-12-30 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.0.5 |
||||||
|
- deps: mime-db@~1.3.1 |
||||||
|
|
||||||
|
1.2.0 / 2014-12-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: negotiator@0.5.0 |
||||||
|
- Fix list return order when large accepted list |
||||||
|
- Fix missing identity encoding when q=0 exists |
||||||
|
- Remove dynamic building of Negotiator class |
||||||
|
|
||||||
|
1.1.4 / 2014-12-10 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.0.4 |
||||||
|
- deps: mime-db@~1.3.0 |
||||||
|
|
||||||
|
1.1.3 / 2014-11-09 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.0.3 |
||||||
|
- deps: mime-db@~1.2.0 |
||||||
|
|
||||||
|
1.1.2 / 2014-10-14 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: negotiator@0.4.9 |
||||||
|
- Fix error when media type has invalid parameter |
||||||
|
|
||||||
|
1.1.1 / 2014-09-28 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: mime-types@~2.0.2 |
||||||
|
- deps: mime-db@~1.1.0 |
||||||
|
* deps: negotiator@0.4.8 |
||||||
|
- Fix all negotiations to be case-insensitive |
||||||
|
- Stable sort preferences of same quality according to client order |
||||||
|
|
||||||
|
1.1.0 / 2014-09-02 |
||||||
|
================== |
||||||
|
|
||||||
|
* update `mime-types` |
||||||
|
|
||||||
|
1.0.7 / 2014-07-04 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix wrong type returned from `type` when match after unknown extension |
||||||
|
|
||||||
|
1.0.6 / 2014-06-24 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: negotiator@0.4.7 |
||||||
|
|
||||||
|
1.0.5 / 2014-06-20 |
||||||
|
================== |
||||||
|
|
||||||
|
* fix crash when unknown extension given |
||||||
|
|
||||||
|
1.0.4 / 2014-06-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* use `mime-types` |
||||||
|
|
||||||
|
1.0.3 / 2014-06-11 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: negotiator@0.4.6 |
||||||
|
- Order by specificity when quality is the same |
||||||
|
|
||||||
|
1.0.2 / 2014-05-29 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix interpretation when header not in request |
||||||
|
* deps: pin negotiator@0.4.5 |
||||||
|
|
||||||
|
1.0.1 / 2014-01-18 |
||||||
|
================== |
||||||
|
|
||||||
|
* Identity encoding isn't always acceptable |
||||||
|
* deps: negotiator@~0.4.0 |
||||||
|
|
||||||
|
1.0.0 / 2013-12-27 |
||||||
|
================== |
||||||
|
|
||||||
|
* Genesis |
@ -0,0 +1,23 @@ |
|||||||
|
(The MIT License) |
||||||
|
|
||||||
|
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com> |
||||||
|
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com> |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,142 @@ |
|||||||
|
# accepts |
||||||
|
|
||||||
|
[![NPM Version][npm-version-image]][npm-url] |
||||||
|
[![NPM Downloads][npm-downloads-image]][npm-url] |
||||||
|
[![Node.js Version][node-version-image]][node-version-url] |
||||||
|
[![Build Status][travis-image]][travis-url] |
||||||
|
[![Test Coverage][coveralls-image]][coveralls-url] |
||||||
|
|
||||||
|
Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator). |
||||||
|
Extracted from [koa](https://www.npmjs.com/package/koa) for general use. |
||||||
|
|
||||||
|
In addition to negotiator, it allows: |
||||||
|
|
||||||
|
- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])` |
||||||
|
as well as `('text/html', 'application/json')`. |
||||||
|
- Allows type shorthands such as `json`. |
||||||
|
- Returns `false` when no types match |
||||||
|
- Treats non-existent headers as `*` |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
This is a [Node.js](https://nodejs.org/en/) module available through the |
||||||
|
[npm registry](https://www.npmjs.com/). Installation is done using the |
||||||
|
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): |
||||||
|
|
||||||
|
```sh |
||||||
|
$ npm install accepts |
||||||
|
``` |
||||||
|
|
||||||
|
## API |
||||||
|
|
||||||
|
<!-- eslint-disable no-unused-vars --> |
||||||
|
|
||||||
|
```js |
||||||
|
var accepts = require('accepts') |
||||||
|
``` |
||||||
|
|
||||||
|
### accepts(req) |
||||||
|
|
||||||
|
Create a new `Accepts` object for the given `req`. |
||||||
|
|
||||||
|
#### .charset(charsets) |
||||||
|
|
||||||
|
Return the first accepted charset. If nothing in `charsets` is accepted, |
||||||
|
then `false` is returned. |
||||||
|
|
||||||
|
#### .charsets() |
||||||
|
|
||||||
|
Return the charsets that the request accepts, in the order of the client's |
||||||
|
preference (most preferred first). |
||||||
|
|
||||||
|
#### .encoding(encodings) |
||||||
|
|
||||||
|
Return the first accepted encoding. If nothing in `encodings` is accepted, |
||||||
|
then `false` is returned. |
||||||
|
|
||||||
|
#### .encodings() |
||||||
|
|
||||||
|
Return the encodings that the request accepts, in the order of the client's |
||||||
|
preference (most preferred first). |
||||||
|
|
||||||
|
#### .language(languages) |
||||||
|
|
||||||
|
Return the first accepted language. If nothing in `languages` is accepted, |
||||||
|
then `false` is returned. |
||||||
|
|
||||||
|
#### .languages() |
||||||
|
|
||||||
|
Return the languages that the request accepts, in the order of the client's |
||||||
|
preference (most preferred first). |
||||||
|
|
||||||
|
#### .type(types) |
||||||
|
|
||||||
|
Return the first accepted type (and it is returned as the same text as what |
||||||
|
appears in the `types` array). If nothing in `types` is accepted, then `false` |
||||||
|
is returned. |
||||||
|
|
||||||
|
The `types` array can contain full MIME types or file extensions. Any value |
||||||
|
that is not a full MIME types is passed to `require('mime-types').lookup`. |
||||||
|
|
||||||
|
#### .types() |
||||||
|
|
||||||
|
Return the types that the request accepts, in the order of the client's |
||||||
|
preference (most preferred first). |
||||||
|
|
||||||
|
## Examples |
||||||
|
|
||||||
|
### Simple type negotiation |
||||||
|
|
||||||
|
This simple example shows how to use `accepts` to return a different typed |
||||||
|
respond body based on what the client wants to accept. The server lists it's |
||||||
|
preferences in order and will get back the best match between the client and |
||||||
|
server. |
||||||
|
|
||||||
|
```js |
||||||
|
var accepts = require('accepts') |
||||||
|
var http = require('http') |
||||||
|
|
||||||
|
function app (req, res) { |
||||||
|
var accept = accepts(req) |
||||||
|
|
||||||
|
// the order of this list is significant; should be server preferred order |
||||||
|
switch (accept.type(['json', 'html'])) { |
||||||
|
case 'json': |
||||||
|
res.setHeader('Content-Type', 'application/json') |
||||||
|
res.write('{"hello":"world!"}') |
||||||
|
break |
||||||
|
case 'html': |
||||||
|
res.setHeader('Content-Type', 'text/html') |
||||||
|
res.write('<b>hello, world!</b>') |
||||||
|
break |
||||||
|
default: |
||||||
|
// the fallback is text/plain, so no need to specify it above |
||||||
|
res.setHeader('Content-Type', 'text/plain') |
||||||
|
res.write('hello, world!') |
||||||
|
break |
||||||
|
} |
||||||
|
|
||||||
|
res.end() |
||||||
|
} |
||||||
|
|
||||||
|
http.createServer(app).listen(3000) |
||||||
|
``` |
||||||
|
|
||||||
|
You can test this out with the cURL program: |
||||||
|
```sh |
||||||
|
curl -I -H'Accept: text/html' http://localhost:3000/ |
||||||
|
``` |
||||||
|
|
||||||
|
## License |
||||||
|
|
||||||
|
[MIT](LICENSE) |
||||||
|
|
||||||
|
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master |
||||||
|
[coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master |
||||||
|
[node-version-image]: https://badgen.net/npm/node/accepts |
||||||
|
[node-version-url]: https://nodejs.org/en/download |
||||||
|
[npm-downloads-image]: https://badgen.net/npm/dm/accepts |
||||||
|
[npm-url]: https://npmjs.org/package/accepts |
||||||
|
[npm-version-image]: https://badgen.net/npm/v/accepts |
||||||
|
[travis-image]: https://badgen.net/travis/jshttp/accepts/master |
||||||
|
[travis-url]: https://travis-ci.org/jshttp/accepts |
@ -0,0 +1,238 @@ |
|||||||
|
/*! |
||||||
|
* accepts |
||||||
|
* Copyright(c) 2014 Jonathan Ong |
||||||
|
* Copyright(c) 2015 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var Negotiator = require('negotiator') |
||||||
|
var mime = require('mime-types') |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
module.exports = Accepts |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a new Accepts object for the given req. |
||||||
|
* |
||||||
|
* @param {object} req |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function Accepts (req) { |
||||||
|
if (!(this instanceof Accepts)) { |
||||||
|
return new Accepts(req) |
||||||
|
} |
||||||
|
|
||||||
|
this.headers = req.headers |
||||||
|
this.negotiator = new Negotiator(req) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check if the given `type(s)` is acceptable, returning |
||||||
|
* the best match when true, otherwise `undefined`, in which |
||||||
|
* case you should respond with 406 "Not Acceptable". |
||||||
|
* |
||||||
|
* The `type` value may be a single mime type string |
||||||
|
* such as "application/json", the extension name |
||||||
|
* such as "json" or an array `["json", "html", "text/plain"]`. When a list |
||||||
|
* or array is given the _best_ match, if any is returned. |
||||||
|
* |
||||||
|
* Examples: |
||||||
|
* |
||||||
|
* // Accept: text/html
|
||||||
|
* this.types('html'); |
||||||
|
* // => "html"
|
||||||
|
* |
||||||
|
* // Accept: text/*, application/json
|
||||||
|
* this.types('html'); |
||||||
|
* // => "html"
|
||||||
|
* this.types('text/html'); |
||||||
|
* // => "text/html"
|
||||||
|
* this.types('json', 'text'); |
||||||
|
* // => "json"
|
||||||
|
* this.types('application/json'); |
||||||
|
* // => "application/json"
|
||||||
|
* |
||||||
|
* // Accept: text/*, application/json
|
||||||
|
* this.types('image/png'); |
||||||
|
* this.types('png'); |
||||||
|
* // => undefined
|
||||||
|
* |
||||||
|
* // Accept: text/*;q=.5, application/json
|
||||||
|
* this.types(['html', 'json']); |
||||||
|
* this.types('html', 'json'); |
||||||
|
* // => "json"
|
||||||
|
* |
||||||
|
* @param {String|Array} types... |
||||||
|
* @return {String|Array|Boolean} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
Accepts.prototype.type = |
||||||
|
Accepts.prototype.types = function (types_) { |
||||||
|
var types = types_ |
||||||
|
|
||||||
|
// support flattened arguments
|
||||||
|
if (types && !Array.isArray(types)) { |
||||||
|
types = new Array(arguments.length) |
||||||
|
for (var i = 0; i < types.length; i++) { |
||||||
|
types[i] = arguments[i] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// no types, return all requested types
|
||||||
|
if (!types || types.length === 0) { |
||||||
|
return this.negotiator.mediaTypes() |
||||||
|
} |
||||||
|
|
||||||
|
// no accept header, return first given type
|
||||||
|
if (!this.headers.accept) { |
||||||
|
return types[0] |
||||||
|
} |
||||||
|
|
||||||
|
var mimes = types.map(extToMime) |
||||||
|
var accepts = this.negotiator.mediaTypes(mimes.filter(validMime)) |
||||||
|
var first = accepts[0] |
||||||
|
|
||||||
|
return first |
||||||
|
? types[mimes.indexOf(first)] |
||||||
|
: false |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return accepted encodings or best fit based on `encodings`. |
||||||
|
* |
||||||
|
* Given `Accept-Encoding: gzip, deflate` |
||||||
|
* an array sorted by quality is returned: |
||||||
|
* |
||||||
|
* ['gzip', 'deflate'] |
||||||
|
* |
||||||
|
* @param {String|Array} encodings... |
||||||
|
* @return {String|Array} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
Accepts.prototype.encoding = |
||||||
|
Accepts.prototype.encodings = function (encodings_) { |
||||||
|
var encodings = encodings_ |
||||||
|
|
||||||
|
// support flattened arguments
|
||||||
|
if (encodings && !Array.isArray(encodings)) { |
||||||
|
encodings = new Array(arguments.length) |
||||||
|
for (var i = 0; i < encodings.length; i++) { |
||||||
|
encodings[i] = arguments[i] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// no encodings, return all requested encodings
|
||||||
|
if (!encodings || encodings.length === 0) { |
||||||
|
return this.negotiator.encodings() |
||||||
|
} |
||||||
|
|
||||||
|
return this.negotiator.encodings(encodings)[0] || false |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return accepted charsets or best fit based on `charsets`. |
||||||
|
* |
||||||
|
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5` |
||||||
|
* an array sorted by quality is returned: |
||||||
|
* |
||||||
|
* ['utf-8', 'utf-7', 'iso-8859-1'] |
||||||
|
* |
||||||
|
* @param {String|Array} charsets... |
||||||
|
* @return {String|Array} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
Accepts.prototype.charset = |
||||||
|
Accepts.prototype.charsets = function (charsets_) { |
||||||
|
var charsets = charsets_ |
||||||
|
|
||||||
|
// support flattened arguments
|
||||||
|
if (charsets && !Array.isArray(charsets)) { |
||||||
|
charsets = new Array(arguments.length) |
||||||
|
for (var i = 0; i < charsets.length; i++) { |
||||||
|
charsets[i] = arguments[i] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// no charsets, return all requested charsets
|
||||||
|
if (!charsets || charsets.length === 0) { |
||||||
|
return this.negotiator.charsets() |
||||||
|
} |
||||||
|
|
||||||
|
return this.negotiator.charsets(charsets)[0] || false |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Return accepted languages or best fit based on `langs`. |
||||||
|
* |
||||||
|
* Given `Accept-Language: en;q=0.8, es, pt` |
||||||
|
* an array sorted by quality is returned: |
||||||
|
* |
||||||
|
* ['es', 'pt', 'en'] |
||||||
|
* |
||||||
|
* @param {String|Array} langs... |
||||||
|
* @return {Array|String} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
Accepts.prototype.lang = |
||||||
|
Accepts.prototype.langs = |
||||||
|
Accepts.prototype.language = |
||||||
|
Accepts.prototype.languages = function (languages_) { |
||||||
|
var languages = languages_ |
||||||
|
|
||||||
|
// support flattened arguments
|
||||||
|
if (languages && !Array.isArray(languages)) { |
||||||
|
languages = new Array(arguments.length) |
||||||
|
for (var i = 0; i < languages.length; i++) { |
||||||
|
languages[i] = arguments[i] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// no languages, return all requested languages
|
||||||
|
if (!languages || languages.length === 0) { |
||||||
|
return this.negotiator.languages() |
||||||
|
} |
||||||
|
|
||||||
|
return this.negotiator.languages(languages)[0] || false |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Convert extnames to mime. |
||||||
|
* |
||||||
|
* @param {String} type |
||||||
|
* @return {String} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function extToMime (type) { |
||||||
|
return type.indexOf('/') === -1 |
||||||
|
? mime.lookup(type) |
||||||
|
: type |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Check if mime is valid. |
||||||
|
* |
||||||
|
* @param {String} type |
||||||
|
* @return {String} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function validMime (type) { |
||||||
|
return typeof type === 'string' |
||||||
|
} |
@ -0,0 +1,86 @@ |
|||||||
|
{ |
||||||
|
"_from": "accepts@~1.3.7", |
||||||
|
"_id": "accepts@1.3.7", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", |
||||||
|
"_location": "/accepts", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "range", |
||||||
|
"registry": true, |
||||||
|
"raw": "accepts@~1.3.7", |
||||||
|
"name": "accepts", |
||||||
|
"escapedName": "accepts", |
||||||
|
"rawSpec": "~1.3.7", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "~1.3.7" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/express" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", |
||||||
|
"_shasum": "531bc726517a3b2b41f850021c6cc15eaab507cd", |
||||||
|
"_spec": "accepts@~1.3.7", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\express", |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/jshttp/accepts/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"contributors": [ |
||||||
|
{ |
||||||
|
"name": "Douglas Christopher Wilson", |
||||||
|
"email": "doug@somethingdoug.com" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"name": "Jonathan Ong", |
||||||
|
"email": "me@jongleberry.com", |
||||||
|
"url": "http://jongleberry.com" |
||||||
|
} |
||||||
|
], |
||||||
|
"dependencies": { |
||||||
|
"mime-types": "~2.1.24", |
||||||
|
"negotiator": "0.6.2" |
||||||
|
}, |
||||||
|
"deprecated": false, |
||||||
|
"description": "Higher-level content negotiation", |
||||||
|
"devDependencies": { |
||||||
|
"deep-equal": "1.0.1", |
||||||
|
"eslint": "5.16.0", |
||||||
|
"eslint-config-standard": "12.0.0", |
||||||
|
"eslint-plugin-import": "2.17.2", |
||||||
|
"eslint-plugin-markdown": "1.0.0", |
||||||
|
"eslint-plugin-node": "8.0.1", |
||||||
|
"eslint-plugin-promise": "4.1.1", |
||||||
|
"eslint-plugin-standard": "4.0.0", |
||||||
|
"mocha": "6.1.4", |
||||||
|
"nyc": "14.0.0" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">= 0.6" |
||||||
|
}, |
||||||
|
"files": [ |
||||||
|
"LICENSE", |
||||||
|
"HISTORY.md", |
||||||
|
"index.js" |
||||||
|
], |
||||||
|
"homepage": "https://github.com/jshttp/accepts#readme", |
||||||
|
"keywords": [ |
||||||
|
"content", |
||||||
|
"negotiation", |
||||||
|
"accept", |
||||||
|
"accepts" |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"name": "accepts", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/jshttp/accepts.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"lint": "eslint --plugin markdown --ext js,md .", |
||||||
|
"test": "mocha --reporter spec --check-leaks --bail test/", |
||||||
|
"test-cov": "nyc --reporter=html --reporter=text npm test", |
||||||
|
"test-travis": "nyc --reporter=text npm test" |
||||||
|
}, |
||||||
|
"version": "1.3.7" |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
The MIT License (MIT) |
||||||
|
|
||||||
|
Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com) |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,43 @@ |
|||||||
|
# Array Flatten |
||||||
|
|
||||||
|
[![NPM version][npm-image]][npm-url] |
||||||
|
[![NPM downloads][downloads-image]][downloads-url] |
||||||
|
[![Build status][travis-image]][travis-url] |
||||||
|
[![Test coverage][coveralls-image]][coveralls-url] |
||||||
|
|
||||||
|
> Flatten an array of nested arrays into a single flat array. Accepts an optional depth. |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
``` |
||||||
|
npm install array-flatten --save |
||||||
|
``` |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
```javascript |
||||||
|
var flatten = require('array-flatten') |
||||||
|
|
||||||
|
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9]) |
||||||
|
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9] |
||||||
|
|
||||||
|
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9], 2) |
||||||
|
//=> [1, 2, 3, [4, [5], 6], 7, 8, 9] |
||||||
|
|
||||||
|
(function () { |
||||||
|
flatten(arguments) //=> [1, 2, 3] |
||||||
|
})(1, [2, 3]) |
||||||
|
``` |
||||||
|
|
||||||
|
## License |
||||||
|
|
||||||
|
MIT |
||||||
|
|
||||||
|
[npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat |
||||||
|
[npm-url]: https://npmjs.org/package/array-flatten |
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat |
||||||
|
[downloads-url]: https://npmjs.org/package/array-flatten |
||||||
|
[travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat |
||||||
|
[travis-url]: https://travis-ci.org/blakeembrey/array-flatten |
||||||
|
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat |
||||||
|
[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master |
@ -0,0 +1,64 @@ |
|||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Expose `arrayFlatten`. |
||||||
|
*/ |
||||||
|
module.exports = arrayFlatten |
||||||
|
|
||||||
|
/** |
||||||
|
* Recursive flatten function with depth. |
||||||
|
* |
||||||
|
* @param {Array} array |
||||||
|
* @param {Array} result |
||||||
|
* @param {Number} depth |
||||||
|
* @return {Array} |
||||||
|
*/ |
||||||
|
function flattenWithDepth (array, result, depth) { |
||||||
|
for (var i = 0; i < array.length; i++) { |
||||||
|
var value = array[i] |
||||||
|
|
||||||
|
if (depth > 0 && Array.isArray(value)) { |
||||||
|
flattenWithDepth(value, result, depth - 1) |
||||||
|
} else { |
||||||
|
result.push(value) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return result |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Recursive flatten function. Omitting depth is slightly faster. |
||||||
|
* |
||||||
|
* @param {Array} array |
||||||
|
* @param {Array} result |
||||||
|
* @return {Array} |
||||||
|
*/ |
||||||
|
function flattenForever (array, result) { |
||||||
|
for (var i = 0; i < array.length; i++) { |
||||||
|
var value = array[i] |
||||||
|
|
||||||
|
if (Array.isArray(value)) { |
||||||
|
flattenForever(value, result) |
||||||
|
} else { |
||||||
|
result.push(value) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return result |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Flatten an array, with the ability to define a depth. |
||||||
|
* |
||||||
|
* @param {Array} array |
||||||
|
* @param {Number} depth |
||||||
|
* @return {Array} |
||||||
|
*/ |
||||||
|
function arrayFlatten (array, depth) { |
||||||
|
if (depth == null) { |
||||||
|
return flattenForever(array, []) |
||||||
|
} |
||||||
|
|
||||||
|
return flattenWithDepth(array, [], depth) |
||||||
|
} |
@ -0,0 +1,64 @@ |
|||||||
|
{ |
||||||
|
"_from": "array-flatten@1.1.1", |
||||||
|
"_id": "array-flatten@1.1.1", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=", |
||||||
|
"_location": "/array-flatten", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "version", |
||||||
|
"registry": true, |
||||||
|
"raw": "array-flatten@1.1.1", |
||||||
|
"name": "array-flatten", |
||||||
|
"escapedName": "array-flatten", |
||||||
|
"rawSpec": "1.1.1", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "1.1.1" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/express" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", |
||||||
|
"_shasum": "9a5f699051b1e7073328f2a008968b64ea2955d2", |
||||||
|
"_spec": "array-flatten@1.1.1", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\express", |
||||||
|
"author": { |
||||||
|
"name": "Blake Embrey", |
||||||
|
"email": "hello@blakeembrey.com", |
||||||
|
"url": "http://blakeembrey.me" |
||||||
|
}, |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/blakeembrey/array-flatten/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"deprecated": false, |
||||||
|
"description": "Flatten an array of nested arrays into a single flat array", |
||||||
|
"devDependencies": { |
||||||
|
"istanbul": "^0.3.13", |
||||||
|
"mocha": "^2.2.4", |
||||||
|
"pre-commit": "^1.0.7", |
||||||
|
"standard": "^3.7.3" |
||||||
|
}, |
||||||
|
"files": [ |
||||||
|
"array-flatten.js", |
||||||
|
"LICENSE" |
||||||
|
], |
||||||
|
"homepage": "https://github.com/blakeembrey/array-flatten", |
||||||
|
"keywords": [ |
||||||
|
"array", |
||||||
|
"flatten", |
||||||
|
"arguments", |
||||||
|
"depth" |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"main": "array-flatten.js", |
||||||
|
"name": "array-flatten", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git://github.com/blakeembrey/array-flatten.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"test": "istanbul cover _mocha -- -R spec" |
||||||
|
}, |
||||||
|
"version": "1.1.1" |
||||||
|
} |
@ -0,0 +1,685 @@ |
|||||||
|
# Changelog |
||||||
|
|
||||||
|
### 0.21.1 (December 21, 2020) |
||||||
|
|
||||||
|
Fixes and Functionality: |
||||||
|
|
||||||
|
- Hotfix: Prevent SSRF (#3410) |
||||||
|
- Protocol not parsed when setting proxy config from env vars (#3070) |
||||||
|
- Updating axios in types to be lower case (#2797) |
||||||
|
- Adding a type guard for `AxiosError` (#2949) |
||||||
|
|
||||||
|
Internal and Tests: |
||||||
|
|
||||||
|
- Remove the skipping of the `socket` http test (#3364) |
||||||
|
- Use different socket for Win32 test (#3375) |
||||||
|
|
||||||
|
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub: |
||||||
|
|
||||||
|
- Daniel Lopretto <timemachine3030@users.noreply.github.com> |
||||||
|
- Jason Kwok <JasonHK@users.noreply.github.com> |
||||||
|
- Jay <jasonsaayman@gmail.com> |
||||||
|
- Jonathan Foster <jonathan@jonathanfoster.io> |
||||||
|
- Remco Haszing <remcohaszing@gmail.com> |
||||||
|
- Xianming Zhong <chinesedfan@qq.com> |
||||||
|
|
||||||
|
### 0.21.0 (October 23, 2020) |
||||||
|
|
||||||
|
Fixes and Functionality: |
||||||
|
|
||||||
|
- Fixing requestHeaders.Authorization ([#3287](https://github.com/axios/axios/pull/3287)) |
||||||
|
- Fixing node types ([#3237](https://github.com/axios/axios/pull/3237)) |
||||||
|
- Fixing axios.delete ignores config.data ([#3282](https://github.com/axios/axios/pull/3282)) |
||||||
|
- Revert "Fixing overwrite Blob/File type as Content-Type in browser. (#1773)" ([#3289](https://github.com/axios/axios/pull/3289)) |
||||||
|
- Fixing an issue that type 'null' and 'undefined' is not assignable to validateStatus when typescript strict option is enabled ([#3200](https://github.com/axios/axios/pull/3200)) |
||||||
|
|
||||||
|
Internal and Tests: |
||||||
|
|
||||||
|
- Lock travis to not use node v15 ([#3361](https://github.com/axios/axios/pull/3361)) |
||||||
|
|
||||||
|
Documentation: |
||||||
|
|
||||||
|
- Fixing simple typo, existant -> existent ([#3252](https://github.com/axios/axios/pull/3252)) |
||||||
|
- Fixing typos ([#3309](https://github.com/axios/axios/pull/3309)) |
||||||
|
|
||||||
|
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub: |
||||||
|
|
||||||
|
- Allan Cruz <57270969+Allanbcruz@users.noreply.github.com> |
||||||
|
- George Cheng <Gerhut@GMail.com> |
||||||
|
- Jay <jasonsaayman@gmail.com> |
||||||
|
- Kevin Kirsche <Kev.Kirsche+GitHub@gmail.com> |
||||||
|
- Remco Haszing <remcohaszing@gmail.com> |
||||||
|
- Taemin Shin <cprayer13@gmail.com> |
||||||
|
- Tim Gates <tim.gates@iress.com> |
||||||
|
- Xianming Zhong <chinesedfan@qq.com> |
||||||
|
|
||||||
|
### 0.20.0 (August 20, 2020) |
||||||
|
|
||||||
|
Release of 0.20.0-pre as a full release with no other changes. |
||||||
|
|
||||||
|
### 0.20.0-pre (July 15, 2020) |
||||||
|
|
||||||
|
Fixes and Functionality: |
||||||
|
|
||||||
|
- Fixing response with utf-8 BOM can not parse to json ([#2419](https://github.com/axios/axios/pull/2419)) |
||||||
|
- fix: remove byte order marker (UTF-8 BOM) when transform response |
||||||
|
- fix: remove BOM only utf-8 |
||||||
|
- test: utf-8 BOM |
||||||
|
- fix: incorrect param name |
||||||
|
- Refactor mergeConfig without utils.deepMerge ([#2844](https://github.com/axios/axios/pull/2844)) |
||||||
|
- Adding failing test |
||||||
|
- Fixing #2587 default custom config persisting |
||||||
|
- Adding Concat keys and filter duplicates |
||||||
|
- Fixed value from CPE |
||||||
|
- update for review feedbacks |
||||||
|
- no deepMerge |
||||||
|
- only merge between plain objects |
||||||
|
- fix rename |
||||||
|
- always merge config by mergeConfig |
||||||
|
- extract function mergeDeepProperties |
||||||
|
- refactor mergeConfig with all keys, and add special logic for validateStatus |
||||||
|
- add test for resetting headers |
||||||
|
- add lots of tests and fix a bug |
||||||
|
- should not inherit `data` |
||||||
|
- use simple toString |
||||||
|
- Fixing overwrite Blob/File type as Content-Type in browser. ([#1773](https://github.com/axios/axios/pull/1773)) |
||||||
|
- Fixing an issue that type 'null' is not assignable to validateStatus ([#2773](https://github.com/axios/axios/pull/2773)) |
||||||
|
- Fixing special char encoding ([#1671](https://github.com/axios/axios/pull/1671)) |
||||||
|
- removing @ character from replacement list since it is a reserved character |
||||||
|
- Updating buildURL test to not include the @ character |
||||||
|
- Removing console logs |
||||||
|
- Fixing password encoding with special characters in basic authentication ([#1492](https://github.com/axios/axios/pull/1492)) |
||||||
|
- Fixing password encoding with special characters in basic authentication |
||||||
|
- Adding test to check if password with non-Latin1 characters pass |
||||||
|
- Fixing 'Network Error' in react native android ([#1487](https://github.com/axios/axios/pull/1487)) |
||||||
|
There is a bug in react native Android platform when using get method. It will trigger a 'Network Error' when passing the requestData which is an empty string to request.send function. So if the requestData is an empty string we can set it to null as well to fix the bug. |
||||||
|
- Fixing Cookie Helper with Asyc Components ([#1105](https://github.com/axios/axios/pull/1105)) ([#1107](https://github.com/axios/axios/pull/1107)) |
||||||
|
- Fixing 'progressEvent' type ([#2851](https://github.com/axios/axios/pull/2851)) |
||||||
|
- Fix 'progressEvent' type |
||||||
|
- Update axios.ts |
||||||
|
- Fixing getting local files (file://) failed ([#2470](https://github.com/axios/axios/pull/2470)) |
||||||
|
- fix issue #2416, #2396 |
||||||
|
- fix Eslint warn |
||||||
|
- Modify judgment conditions |
||||||
|
- add unit test |
||||||
|
- update unit test |
||||||
|
- update unit test |
||||||
|
- Allow PURGE method in typings ([#2191](https://github.com/axios/axios/pull/2191)) |
||||||
|
- Adding option to disable automatic decompression ([#2661](https://github.com/axios/axios/pull/2661)) |
||||||
|
- Adding ability to disable auto decompression |
||||||
|
- Updating decompress documentation in README |
||||||
|
- Fixing test\unit\adapters\http.js lint errors |
||||||
|
- Adding test for disabling auto decompression |
||||||
|
- Removing changes that fixed lint errors in tests |
||||||
|
- Removing formatting change to unit test |
||||||
|
- Add independent `maxBodyLength` option ([#2781](https://github.com/axios/axios/pull/2781)) |
||||||
|
- Add independent option to set the maximum size of the request body |
||||||
|
- Remove maxBodyLength check |
||||||
|
- Update README |
||||||
|
- Assert for error code and message |
||||||
|
- Adding responseEncoding to mergeConfig ([#1745](https://github.com/axios/axios/pull/1745)) |
||||||
|
- Compatible with follow-redirect aborts the request ([#2689](https://github.com/axios/axios/pull/2689)) |
||||||
|
- Compatible with follow-redirect aborts the request |
||||||
|
- Use the error code |
||||||
|
- Fix merging of params ([#2656](https://github.com/axios/axios/pull/2656)) |
||||||
|
- Name function to avoid ESLint func-names warning |
||||||
|
- Switch params config to merge list and update tests |
||||||
|
- Restore testing of both false and null |
||||||
|
- Restore test cases for keys without defaults |
||||||
|
- Include test for non-object values that aren't false-y. |
||||||
|
- Revert `finally` as `then` ([#2683](https://github.com/axios/axios/pull/2683)) |
||||||
|
|
||||||
|
Internal and Tests: |
||||||
|
|
||||||
|
- Fix stale bot config ([#3049](https://github.com/axios/axios/pull/3049)) |
||||||
|
- fix stale bot config |
||||||
|
- fix multiple lines |
||||||
|
- Add days and change name to work ([#3035](https://github.com/axios/axios/pull/3035)) |
||||||
|
- Update close-issues.yml ([#3031](https://github.com/axios/axios/pull/3031)) |
||||||
|
- Update close-issues.yml |
||||||
|
Update close message to read better 😄 |
||||||
|
- Fix use of quotations |
||||||
|
Use single quotes as per other .yml files |
||||||
|
- Remove user name form message |
||||||
|
- Add GitHub actions to close stale issues/prs ([#3029](https://github.com/axios/axios/pull/3029)) |
||||||
|
- prepare stale actions |
||||||
|
- update messages |
||||||
|
- Add exempt labels and lighten up comments |
||||||
|
- Add GitHub actions to close invalid issues ([#3022](https://github.com/axios/axios/pull/3022)) |
||||||
|
- add close actions |
||||||
|
- fix with checkout |
||||||
|
- update issue templates |
||||||
|
- add reminder |
||||||
|
- update close message |
||||||
|
- Add test with Node.js 12 ([#2860](https://github.com/axios/axios/pull/2860)) |
||||||
|
- test with Node.js 12 |
||||||
|
- test with latest |
||||||
|
- Adding console log on sandbox server startup ([#2210](https://github.com/axios/axios/pull/2210)) |
||||||
|
- Adding console log on sandbox server startup |
||||||
|
- Update server.js |
||||||
|
Add server error handling |
||||||
|
- Update server.js |
||||||
|
Better error message, remove retry. |
||||||
|
- Adding tests for method `options` type definitions ([#1996](https://github.com/axios/axios/pull/1996)) |
||||||
|
Update tests. |
||||||
|
- Add test for redirecting with too large response ([#2695](https://github.com/axios/axios/pull/2695)) |
||||||
|
- Fixing unit test failure in Windows OS ([#2601](https://github.com/axios/axios/pull/2601)) |
||||||
|
- Fixing issue for HEAD method and gzipped response ([#2666](https://github.com/axios/axios/pull/2666)) |
||||||
|
- Fix tests in browsers ([#2748](https://github.com/axios/axios/pull/2748)) |
||||||
|
- chore: add `jsdelivr` and `unpkg` support ([#2443](https://github.com/axios/axios/pull/2443)) |
||||||
|
|
||||||
|
Documentation: |
||||||
|
|
||||||
|
- Adding support for URLSearchParams in node ([#1900](https://github.com/axios/axios/pull/1900)) |
||||||
|
- Adding support for URLSearchParams in node |
||||||
|
- Remove un-needed code |
||||||
|
- Update utils.js |
||||||
|
- Make changes as suggested |
||||||
|
- Adding table of content (preview) ([#3050](https://github.com/axios/axios/pull/3050)) |
||||||
|
- add toc (preview) |
||||||
|
- remove toc in toc |
||||||
|
Signed-off-by: Moni <usmoni@gmail.com> |
||||||
|
- fix sublinks |
||||||
|
- fix indentation |
||||||
|
- remove redundant table links |
||||||
|
- update caps and indent |
||||||
|
- remove axios |
||||||
|
- Replace 'blacklist' with 'blocklist' ([#3006](https://github.com/axios/axios/pull/3006)) |
||||||
|
- docs(): Detailed config options environment. ([#2088](https://github.com/axios/axios/pull/2088)) |
||||||
|
- docs(): Detailed config options environment. |
||||||
|
- Update README.md |
||||||
|
- Include axios-data-unpacker in ECOSYSTEM.md ([#2080](https://github.com/axios/axios/pull/2080)) |
||||||
|
- Allow opening examples in Gitpod ([#1958](https://github.com/axios/axios/pull/1958)) |
||||||
|
- Remove axios.all() and axios.spread() from Readme.md ([#2727](https://github.com/axios/axios/pull/2727)) |
||||||
|
- remove axios.all(), axios.spread() |
||||||
|
- replace example |
||||||
|
- axios.all() -> Promise.all() |
||||||
|
- axios.spread(function (acct, perms)) -> function (acct, perms) |
||||||
|
- add deprecated mark |
||||||
|
- Update README.md ([#2887](https://github.com/axios/axios/pull/2887)) |
||||||
|
Small change to the data attribute doc of the config. A request body can also be set for DELETE methods but this wasn't mentioned in the documentation (it only mentioned POST, PUT and PATCH). Took my some 10-20 minutes until I realized that I don't need to manipulate the request body with transformRequest in the case of DELETE. |
||||||
|
- Include swagger-taxos-codegen in ECOSYSTEM.md ([#2162](https://github.com/axios/axios/pull/2162)) |
||||||
|
- Add CDNJS version badge in README.md ([#878](https://github.com/axios/axios/pull/878)) |
||||||
|
This badge will show the version on CDNJS! |
||||||
|
- Documentation update to clear up ambiguity in code examples ([#2928](https://github.com/axios/axios/pull/2928)) |
||||||
|
- Made an adjustment to the documentation to clear up any ambiguity around the use of "fs". This should help clear up that the code examples with "fs" cannot be used on the client side. |
||||||
|
- Update README.md about validateStatus ([#2912](https://github.com/axios/axios/pull/2912)) |
||||||
|
Rewrote the comment from "Reject only if the status code is greater than or equal to 500" to "Resolve only if the status code is less than 500" |
||||||
|
- Updating documentation for usage form-data ([#2805](https://github.com/axios/axios/pull/2805)) |
||||||
|
Closes #2049 |
||||||
|
- Fixing CHANGELOG.md issue link ([#2784](https://github.com/axios/axios/pull/2784)) |
||||||
|
- Include axios-hooks in ECOSYSTEM.md ([#2003](https://github.com/axios/axios/pull/2003)) |
||||||
|
- Added Response header access instructions ([#1901](https://github.com/axios/axios/pull/1901)) |
||||||
|
- Added Response header access instructions |
||||||
|
- Added note about using bracket notation |
||||||
|
- Add `onUploadProgress` and `onDownloadProgress` are browser only ([#2763](https://github.com/axios/axios/pull/2763)) |
||||||
|
Saw in #928 and #1966 that `onUploadProgress` and `onDownloadProgress` only work in the browser and was missing that from the README. |
||||||
|
- Update ' sign to ` in proxy spec ([#2778](https://github.com/axios/axios/pull/2778)) |
||||||
|
- Adding jsDelivr link in README ([#1110](https://github.com/axios/axios/pull/1110)) |
||||||
|
- Adding jsDelivr link |
||||||
|
- Add SRI |
||||||
|
- Remove SRI |
||||||
|
|
||||||
|
Huge thanks to everyone who contributed to this release via code (authors listed |
||||||
|
below) or via reviews and triaging on GitHub: |
||||||
|
|
||||||
|
- Alan Wang <wp_scut@163.com> |
||||||
|
- Alexandru Ungureanu <khakcarot@gmail.com> |
||||||
|
- Anubhav Srivastava <anubhav.srivastava00@gmail.com> |
||||||
|
- Benny Neugebauer <bn@bennyn.de> |
||||||
|
- Cr <631807682@qq.com> |
||||||
|
- David <cygnidavid@gmail.com> |
||||||
|
- David Ko <david.ko@pvtmethod.com> |
||||||
|
- David Tanner <david.tanner@lifeomic.com> |
||||||
|
- Emily Morehouse <emilyemorehouse@gmail.com> |
||||||
|
- Felipe Martins <felipewmartins@gmail.com> |
||||||
|
- Fonger <5862369+Fonger@users.noreply.github.com> |
||||||
|
- Frostack <soulburn007@gmail.com> |
||||||
|
- George Cheng <Gerhut@GMail.com> |
||||||
|
- grumblerchester <grumblerchester@users.noreply.github.com> |
||||||
|
- Gustavo López <gualopezb@gmail.com> |
||||||
|
- hexaez <45806662+hexaez@users.noreply.github.com> |
||||||
|
- huangzuizui <huangzuizui@gmail.com> |
||||||
|
- Ian Wijma <ian@wij.ma> |
||||||
|
- Jay <jasonsaayman@gmail.com> |
||||||
|
- jeffjing <zgayjjf@qq.com> |
||||||
|
- jennynju <46782518+jennynju@users.noreply.github.com> |
||||||
|
- Jimmy Liao <52391190+jimmy-liao-gogoro@users.noreply.github.com> |
||||||
|
- Jonathan Sharpe <j.r.sharpe@gmail.com> |
||||||
|
- JounQin <admin@1stg.me> |
||||||
|
- Justin Beckwith <justin.beckwith@gmail.com> |
||||||
|
- Kamil Posiadała <3dcreator.pl@gmail.com> |
||||||
|
- Lukas Drgon <lukas.drgon@gmail.com> |
||||||
|
- marcinx <mail@marcinx.com> |
||||||
|
- Martti Laine <martti@codeclown.net> |
||||||
|
- Michał Zarach <michal.m.zarach@gmail.com> |
||||||
|
- Moni <usmoni@gmail.com> |
||||||
|
- Motonori Iwata <121048+iwata@users.noreply.github.com> |
||||||
|
- Nikita Galkin <nikita@galk.in> |
||||||
|
- Petr Mares <petr@mares.tw> |
||||||
|
- Philippe Recto <precto1285@gmal.com> |
||||||
|
- Remco Haszing <remcohaszing@gmail.com> |
||||||
|
- rockcs1992 <chengshi1219@gmail.com> |
||||||
|
- Ryan Bown <rbown@niftee.com.au> |
||||||
|
- Samina Fu <sufuf3@gmail.com> |
||||||
|
- Simone Busoli <simone.busoli@gmail.com> |
||||||
|
- Spencer von der Ohe <s.vonderohe40@gmail.com> |
||||||
|
- Sven Efftinge <sven.efftinge@typefox.io> |
||||||
|
- Taegyeoung Oh <otk1090@naver.com> |
||||||
|
- Taemin Shin <cprayer13@gmail.com> |
||||||
|
- Thibault Ehrhart <1208424+ehrhart@users.noreply.github.com> |
||||||
|
- Xianming Zhong <chinesedfan@qq.com> |
||||||
|
- Yasu Flores <carlosyasu91@gmail.com> |
||||||
|
- Zac Delventhal <delventhalz@gmail.com> |
||||||
|
|
||||||
|
### 0.19.2 (Jan 20, 2020) |
||||||
|
|
||||||
|
- Remove unnecessary XSS check ([#2679](https://github.com/axios/axios/pull/2679)) (see ([#2646](https://github.com/axios/axios/issues/2646)) for discussion) |
||||||
|
|
||||||
|
### 0.19.1 (Jan 7, 2020) |
||||||
|
|
||||||
|
Fixes and Functionality: |
||||||
|
|
||||||
|
- Fixing invalid agent issue ([#1904](https://github.com/axios/axios/pull/1904)) |
||||||
|
- Fix ignore set withCredentials false ([#2582](https://github.com/axios/axios/pull/2582)) |
||||||
|
- Delete useless default to hash ([#2458](https://github.com/axios/axios/pull/2458)) |
||||||
|
- Fix HTTP/HTTPs agents passing to follow-redirect ([#1904](https://github.com/axios/axios/pull/1904)) |
||||||
|
- Fix ignore set withCredentials false ([#2582](https://github.com/axios/axios/pull/2582)) |
||||||
|
- Fix CI build failure ([#2570](https://github.com/axios/axios/pull/2570)) |
||||||
|
- Remove dependency on is-buffer from package.json ([#1816](https://github.com/axios/axios/pull/1816)) |
||||||
|
- Adding options typings ([#2341](https://github.com/axios/axios/pull/2341)) |
||||||
|
- Adding Typescript HTTP method definition for LINK and UNLINK. ([#2444](https://github.com/axios/axios/pull/2444)) |
||||||
|
- Update dist with newest changes, fixes Custom Attributes issue |
||||||
|
- Change syntax to see if build passes ([#2488](https://github.com/axios/axios/pull/2488)) |
||||||
|
- Update Webpack + deps, remove now unnecessary polyfills ([#2410](https://github.com/axios/axios/pull/2410)) |
||||||
|
- Fix to prevent XSS, throw an error when the URL contains a JS script ([#2464](https://github.com/axios/axios/pull/2464)) |
||||||
|
- Add custom timeout error copy in config ([#2275](https://github.com/axios/axios/pull/2275)) |
||||||
|
- Add error toJSON example ([#2466](https://github.com/axios/axios/pull/2466)) |
||||||
|
- Fixing Vulnerability A Fortify Scan finds a critical Cross-Site Scrip… ([#2451](https://github.com/axios/axios/pull/2451)) |
||||||
|
- Fixing subdomain handling on no_proxy ([#2442](https://github.com/axios/axios/pull/2442)) |
||||||
|
- Make redirection from HTTP to HTTPS work ([#2426](https://github.com/axios/axios/pull/2426)) and ([#2547](https://github.com/axios/axios/pull/2547)) |
||||||
|
- Add toJSON property to AxiosError type ([#2427](https://github.com/axios/axios/pull/2427)) |
||||||
|
- Fixing socket hang up error on node side for slow response. ([#1752](https://github.com/axios/axios/pull/1752)) |
||||||
|
- Alternative syntax to send data into the body ([#2317](https://github.com/axios/axios/pull/2317)) |
||||||
|
- Fixing custom config options ([#2207](https://github.com/axios/axios/pull/2207)) |
||||||
|
- Fixing set `config.method` after mergeConfig for Axios.prototype.request ([#2383](https://github.com/axios/axios/pull/2383)) |
||||||
|
- Axios create url bug ([#2290](https://github.com/axios/axios/pull/2290)) |
||||||
|
- Do not modify config.url when using a relative baseURL (resolves [#1628](https://github.com/axios/axios/issues/1098)) ([#2391](https://github.com/axios/axios/pull/2391)) |
||||||
|
- Add typescript HTTP method definition for LINK and UNLINK ([#2444](https://github.com/axios/axios/pull/2444)) |
||||||
|
|
||||||
|
Internal: |
||||||
|
|
||||||
|
- Revert "Update Webpack + deps, remove now unnecessary polyfills" ([#2479](https://github.com/axios/axios/pull/2479)) |
||||||
|
- Order of if/else blocks is causing unit tests mocking XHR. ([#2201](https://github.com/axios/axios/pull/2201)) |
||||||
|
- Add license badge ([#2446](https://github.com/axios/axios/pull/2446)) |
||||||
|
- Fix travis CI build [#2386](https://github.com/axios/axios/pull/2386) |
||||||
|
- Fix cancellation error on build master. #2290 #2207 ([#2407](https://github.com/axios/axios/pull/2407)) |
||||||
|
|
||||||
|
Documentation: |
||||||
|
|
||||||
|
- Fixing typo in CHANGELOG.md: s/Functionallity/Functionality ([#2639](https://github.com/axios/axios/pull/2639)) |
||||||
|
- Fix badge, use master branch ([#2538](https://github.com/axios/axios/pull/2538)) |
||||||
|
- Fix typo in changelog [#2193](https://github.com/axios/axios/pull/2193) |
||||||
|
- Document fix ([#2514](https://github.com/axios/axios/pull/2514)) |
||||||
|
- Update docs with no_proxy change, issue #2484 ([#2513](https://github.com/axios/axios/pull/2513)) |
||||||
|
- Fixing missing words in docs template ([#2259](https://github.com/axios/axios/pull/2259)) |
||||||
|
- 🐛Fix request finally documentation in README ([#2189](https://github.com/axios/axios/pull/2189)) |
||||||
|
- updating spelling and adding link to docs ([#2212](https://github.com/axios/axios/pull/2212)) |
||||||
|
- docs: minor tweak ([#2404](https://github.com/axios/axios/pull/2404)) |
||||||
|
- Update response interceptor docs ([#2399](https://github.com/axios/axios/pull/2399)) |
||||||
|
- Update README.md ([#2504](https://github.com/axios/axios/pull/2504)) |
||||||
|
- Fix word 'sintaxe' to 'syntax' in README.md ([#2432](https://github.com/axios/axios/pull/2432)) |
||||||
|
- updating README: notes on CommonJS autocomplete ([#2256](https://github.com/axios/axios/pull/2256)) |
||||||
|
- Fix grammar in README.md ([#2271](https://github.com/axios/axios/pull/2271)) |
||||||
|
- Doc fixes, minor examples cleanup ([#2198](https://github.com/axios/axios/pull/2198)) |
||||||
|
|
||||||
|
### 0.19.0 (May 30, 2019) |
||||||
|
|
||||||
|
Fixes and Functionality: |
||||||
|
|
||||||
|
- Added support for no_proxy env variable ([#1693](https://github.com/axios/axios/pull/1693/files)) - Chance Dickson |
||||||
|
- Unzip response body only for statuses != 204 ([#1129](https://github.com/axios/axios/pull/1129)) - drawski |
||||||
|
- Destroy stream on exceeding maxContentLength (fixes [#1098](https://github.com/axios/axios/issues/1098)) ([#1485](https://github.com/axios/axios/pull/1485)) - Gadzhi Gadzhiev |
||||||
|
- Makes Axios error generic to use AxiosResponse ([#1738](https://github.com/axios/axios/pull/1738)) - Suman Lama |
||||||
|
- Fixing Mocha tests by locking follow-redirects version to 1.5.10 ([#1993](https://github.com/axios/axios/pull/1993)) - grumblerchester |
||||||
|
- Allow uppercase methods in typings. ([#1781](https://github.com/axios/axios/pull/1781)) - Ken Powers |
||||||
|
- Fixing building url with hash mark ([#1771](https://github.com/axios/axios/pull/1771)) - Anatoly Ryabov |
||||||
|
- This commit fix building url with hash map (fragment identifier) when parameters are present: they must not be added after `#`, because client cut everything after `#` |
||||||
|
- Preserve HTTP method when following redirect ([#1758](https://github.com/axios/axios/pull/1758)) - Rikki Gibson |
||||||
|
- Add `getUri` signature to TypeScript definition. ([#1736](https://github.com/axios/axios/pull/1736)) - Alexander Trauzzi |
||||||
|
- Adding isAxiosError flag to errors thrown by axios ([#1419](https://github.com/axios/axios/pull/1419)) - Ayush Gupta |
||||||
|
|
||||||
|
Internal: |
||||||
|
|
||||||
|
- Fixing .eslintrc without extension ([#1789](https://github.com/axios/axios/pull/1789)) - Manoel |
||||||
|
- Fix failing SauceLabs tests by updating configuration - Emily Morehouse |
||||||
|
- Add issue templates - Emily Morehouse |
||||||
|
|
||||||
|
Documentation: |
||||||
|
|
||||||
|
- Consistent coding style in README ([#1787](https://github.com/axios/axios/pull/1787)) - Ali Servet Donmez |
||||||
|
- Add information about auth parameter to README ([#2166](https://github.com/axios/axios/pull/2166)) - xlaguna |
||||||
|
- Add DELETE to list of methods that allow data as a config option ([#2169](https://github.com/axios/axios/pull/2169)) - Daniela Borges Matos de Carvalho |
||||||
|
- Update ECOSYSTEM.md - Add Axios Endpoints ([#2176](https://github.com/axios/axios/pull/2176)) - Renan |
||||||
|
- Add r2curl in ECOSYSTEM ([#2141](https://github.com/axios/axios/pull/2141)) - 유용우 / CX |
||||||
|
- Update README.md - Add instructions for installing with yarn ([#2036](https://github.com/axios/axios/pull/2036)) - Victor Hermes |
||||||
|
- Fixing spacing for README.md ([#2066](https://github.com/axios/axios/pull/2066)) - Josh McCarty |
||||||
|
- Update README.md. - Change `.then` to `.finally` in example code ([#2090](https://github.com/axios/axios/pull/2090)) - Omar Cai |
||||||
|
- Clarify what values responseType can have in Node ([#2121](https://github.com/axios/axios/pull/2121)) - Tyler Breisacher |
||||||
|
- docs(ECOSYSTEM): add axios-api-versioning ([#2020](https://github.com/axios/axios/pull/2020)) - Weffe |
||||||
|
- It seems that `responseType: 'blob'` doesn't actually work in Node (when I tried using it, response.data was a string, not a Blob, since Node doesn't have Blobs), so this clarifies that this option should only be used in the browser |
||||||
|
- Update README.md. - Add Querystring library note ([#1896](https://github.com/axios/axios/pull/1896)) - Dmitriy Eroshenko |
||||||
|
- Add react-hooks-axios to Libraries section of ECOSYSTEM.md ([#1925](https://github.com/axios/axios/pull/1925)) - Cody Chan |
||||||
|
- Clarify in README that default timeout is 0 (no timeout) ([#1750](https://github.com/axios/axios/pull/1750)) - Ben Standefer |
||||||
|
|
||||||
|
### 0.19.0-beta.1 (Aug 9, 2018) |
||||||
|
|
||||||
|
**NOTE:** This is a beta version of this release. There may be functionality that is broken in |
||||||
|
certain browsers, though we suspect that builds are hanging and not erroring. See |
||||||
|
https://saucelabs.com/u/axios for the most up-to-date information. |
||||||
|
|
||||||
|
New Functionality: |
||||||
|
|
||||||
|
- Add getUri method ([#1712](https://github.com/axios/axios/issues/1712)) |
||||||
|
- Add support for no_proxy env variable ([#1693](https://github.com/axios/axios/issues/1693)) |
||||||
|
- Add toJSON to decorated Axios errors to facilitate serialization ([#1625](https://github.com/axios/axios/issues/1625)) |
||||||
|
- Add second then on axios call ([#1623](https://github.com/axios/axios/issues/1623)) |
||||||
|
- Typings: allow custom return types |
||||||
|
- Add option to specify character set in responses (with http adapter) |
||||||
|
|
||||||
|
Fixes: |
||||||
|
|
||||||
|
- Fix Keep defaults local to instance ([#385](https://github.com/axios/axios/issues/385)) |
||||||
|
- Correctly catch exception in http test ([#1475](https://github.com/axios/axios/issues/1475)) |
||||||
|
- Fix accept header normalization ([#1698](https://github.com/axios/axios/issues/1698)) |
||||||
|
- Fix http adapter to allow HTTPS connections via HTTP ([#959](https://github.com/axios/axios/issues/959)) |
||||||
|
- Fix Removes usage of deprecated Buffer constructor. ([#1555](https://github.com/axios/axios/issues/1555), [#1622](https://github.com/axios/axios/issues/1622)) |
||||||
|
- Fix defaults to use httpAdapter if available ([#1285](https://github.com/axios/axios/issues/1285)) |
||||||
|
- Fixing defaults to use httpAdapter if available |
||||||
|
- Use a safer, cross-platform method to detect the Node environment |
||||||
|
- Fix Reject promise if request is cancelled by the browser ([#537](https://github.com/axios/axios/issues/537)) |
||||||
|
- [Typescript] Fix missing type parameters on delete/head methods |
||||||
|
- [NS]: Send `false` flag isStandardBrowserEnv for Nativescript |
||||||
|
- Fix missing type parameters on delete/head |
||||||
|
- Fix Default method for an instance always overwritten by get |
||||||
|
- Fix type error when socketPath option in AxiosRequestConfig |
||||||
|
- Capture errors on request data streams |
||||||
|
- Decorate resolve and reject to clear timeout in all cases |
||||||
|
|
||||||
|
Huge thanks to everyone who contributed to this release via code (authors listed |
||||||
|
below) or via reviews and triaging on GitHub: |
||||||
|
|
||||||
|
- Andrew Scott <ascott18@gmail.com> |
||||||
|
- Anthony Gauthier <antho325@hotmail.com> |
||||||
|
- arpit <arpit2438735@gmail.com> |
||||||
|
- ascott18 |
||||||
|
- Benedikt Rötsch <axe312ger@users.noreply.github.com> |
||||||
|
- Chance Dickson <me@chancedickson.com> |
||||||
|
- Dave Stewart <info@davestewart.co.uk> |
||||||
|
- Deric Cain <deric.cain@gmail.com> |
||||||
|
- Guillaume Briday <guillaumebriday@gmail.com> |
||||||
|
- Jacob Wejendorp <jacob@wejendorp.dk> |
||||||
|
- Jim Lynch <mrdotjim@gmail.com> |
||||||
|
- johntron |
||||||
|
- Justin Beckwith <beckwith@google.com> |
||||||
|
- Justin Beckwith <justin.beckwith@gmail.com> |
||||||
|
- Khaled Garbaya <khaledgarbaya@gmail.com> |
||||||
|
- Lim Jing Rong <jjingrong@users.noreply.github.com> |
||||||
|
- Mark van den Broek <mvdnbrk@gmail.com> |
||||||
|
- Martti Laine <martti@codeclown.net> |
||||||
|
- mattridley |
||||||
|
- mattridley <matt.r@joinblink.com> |
||||||
|
- Nicolas Del Valle <nicolas.delvalle@gmail.com> |
||||||
|
- Nilegfx |
||||||
|
- pbarbiero |
||||||
|
- Rikki Gibson <rikkigibson@gmail.com> |
||||||
|
- Sako Hartounian <sakohartounian@yahoo.com> |
||||||
|
- Shane Fitzpatrick <fitzpasd@gmail.com> |
||||||
|
- Stephan Schneider <stephanschndr@gmail.com> |
||||||
|
- Steven <steven@ceriously.com> |
||||||
|
- Tim Garthwaite <tim.garthwaite@jibo.com> |
||||||
|
- Tim Johns <timjohns@yahoo.com> |
||||||
|
- Yutaro Miyazaki <yutaro@studio-rubbish.com> |
||||||
|
|
||||||
|
### 0.18.0 (Feb 19, 2018) |
||||||
|
|
||||||
|
- Adding support for UNIX Sockets when running with Node.js ([#1070](https://github.com/axios/axios/pull/1070)) |
||||||
|
- Fixing typings ([#1177](https://github.com/axios/axios/pull/1177)): |
||||||
|
- AxiosRequestConfig.proxy: allows type false |
||||||
|
- AxiosProxyConfig: added auth field |
||||||
|
- Adding function signature in AxiosInstance interface so AxiosInstance can be invoked ([#1192](https://github.com/axios/axios/pull/1192), [#1254](https://github.com/axios/axios/pull/1254)) |
||||||
|
- Allowing maxContentLength to pass through to redirected calls as maxBodyLength in follow-redirects config ([#1287](https://github.com/axios/axios/pull/1287)) |
||||||
|
- Fixing configuration when using an instance - method can now be set ([#1342](https://github.com/axios/axios/pull/1342)) |
||||||
|
|
||||||
|
### 0.17.1 (Nov 11, 2017) |
||||||
|
|
||||||
|
- Fixing issue with web workers ([#1160](https://github.com/axios/axios/pull/1160)) |
||||||
|
- Allowing overriding transport ([#1080](https://github.com/axios/axios/pull/1080)) |
||||||
|
- Updating TypeScript typings ([#1165](https://github.com/axios/axios/pull/1165), [#1125](https://github.com/axios/axios/pull/1125), [#1131](https://github.com/axios/axios/pull/1131)) |
||||||
|
|
||||||
|
### 0.17.0 (Oct 21, 2017) |
||||||
|
|
||||||
|
- **BREAKING** Fixing issue with `baseURL` and interceptors ([#950](https://github.com/axios/axios/pull/950)) |
||||||
|
- **BREAKING** Improving handing of duplicate headers ([#874](https://github.com/axios/axios/pull/874)) |
||||||
|
- Adding support for disabling proxies ([#691](https://github.com/axios/axios/pull/691)) |
||||||
|
- Updating TypeScript typings with generic type parameters ([#1061](https://github.com/axios/axios/pull/1061)) |
||||||
|
|
||||||
|
### 0.16.2 (Jun 3, 2017) |
||||||
|
|
||||||
|
- Fixing issue with including `buffer` in bundle ([#887](https://github.com/axios/axios/pull/887)) |
||||||
|
- Including underlying request in errors ([#830](https://github.com/axios/axios/pull/830)) |
||||||
|
- Convert `method` to lowercase ([#930](https://github.com/axios/axios/pull/930)) |
||||||
|
|
||||||
|
### 0.16.1 (Apr 8, 2017) |
||||||
|
|
||||||
|
- Improving HTTP adapter to return last request in case of redirects ([#828](https://github.com/axios/axios/pull/828)) |
||||||
|
- Updating `follow-redirects` dependency ([#829](https://github.com/axios/axios/pull/829)) |
||||||
|
- Adding support for passing `Buffer` in node ([#773](https://github.com/axios/axios/pull/773)) |
||||||
|
|
||||||
|
### 0.16.0 (Mar 31, 2017) |
||||||
|
|
||||||
|
- **BREAKING** Removing `Promise` from axios typings in favor of built-in type declarations ([#480](https://github.com/axios/axios/issues/480)) |
||||||
|
- Adding `options` shortcut method ([#461](https://github.com/axios/axios/pull/461)) |
||||||
|
- Fixing issue with using `responseType: 'json'` in browsers incompatible with XHR Level 2 ([#654](https://github.com/axios/axios/pull/654)) |
||||||
|
- Improving React Native detection ([#731](https://github.com/axios/axios/pull/731)) |
||||||
|
- Fixing `combineURLs` to support empty `relativeURL` ([#581](https://github.com/axios/axios/pull/581)) |
||||||
|
- Removing `PROTECTION_PREFIX` support ([#561](https://github.com/axios/axios/pull/561)) |
||||||
|
|
||||||
|
### 0.15.3 (Nov 27, 2016) |
||||||
|
|
||||||
|
- Fixing issue with custom instances and global defaults ([#443](https://github.com/axios/axios/issues/443)) |
||||||
|
- Renaming `axios.d.ts` to `index.d.ts` ([#519](https://github.com/axios/axios/issues/519)) |
||||||
|
- Adding `get`, `head`, and `delete` to `defaults.headers` ([#509](https://github.com/axios/axios/issues/509)) |
||||||
|
- Fixing issue with `btoa` and IE ([#507](https://github.com/axios/axios/issues/507)) |
||||||
|
- Adding support for proxy authentication ([#483](https://github.com/axios/axios/pull/483)) |
||||||
|
- Improving HTTP adapter to use `http` protocol by default ([#493](https://github.com/axios/axios/pull/493)) |
||||||
|
- Fixing proxy issues ([#491](https://github.com/axios/axios/pull/491)) |
||||||
|
|
||||||
|
### 0.15.2 (Oct 17, 2016) |
||||||
|
|
||||||
|
- Fixing issue with calling `cancel` after response has been received ([#482](https://github.com/axios/axios/issues/482)) |
||||||
|
|
||||||
|
### 0.15.1 (Oct 14, 2016) |
||||||
|
|
||||||
|
- Fixing issue with UMD ([#485](https://github.com/axios/axios/issues/485)) |
||||||
|
|
||||||
|
### 0.15.0 (Oct 10, 2016) |
||||||
|
|
||||||
|
- Adding cancellation support ([#452](https://github.com/axios/axios/pull/452)) |
||||||
|
- Moving default adapter to global defaults ([#437](https://github.com/axios/axios/pull/437)) |
||||||
|
- Fixing issue with `file` URI scheme ([#440](https://github.com/axios/axios/pull/440)) |
||||||
|
- Fixing issue with `params` objects that have no prototype ([#445](https://github.com/axios/axios/pull/445)) |
||||||
|
|
||||||
|
### 0.14.0 (Aug 27, 2016) |
||||||
|
|
||||||
|
- **BREAKING** Updating TypeScript definitions ([#419](https://github.com/axios/axios/pull/419)) |
||||||
|
- **BREAKING** Replacing `agent` option with `httpAgent` and `httpsAgent` ([#387](https://github.com/axios/axios/pull/387)) |
||||||
|
- **BREAKING** Splitting `progress` event handlers into `onUploadProgress` and `onDownloadProgress` ([#423](https://github.com/axios/axios/pull/423)) |
||||||
|
- Adding support for `http_proxy` and `https_proxy` environment variables ([#366](https://github.com/axios/axios/pull/366)) |
||||||
|
- Fixing issue with `auth` config option and `Authorization` header ([#397](https://github.com/axios/axios/pull/397)) |
||||||
|
- Don't set XSRF header if `xsrfCookieName` is `null` ([#406](https://github.com/axios/axios/pull/406)) |
||||||
|
|
||||||
|
### 0.13.1 (Jul 16, 2016) |
||||||
|
|
||||||
|
- Fixing issue with response data not being transformed on error ([#378](https://github.com/axios/axios/issues/378)) |
||||||
|
|
||||||
|
### 0.13.0 (Jul 13, 2016) |
||||||
|
|
||||||
|
- **BREAKING** Improved error handling ([#345](https://github.com/axios/axios/pull/345)) |
||||||
|
- **BREAKING** Response transformer now invoked in dispatcher not adapter ([10eb238](https://github.com/axios/axios/commit/10eb23865101f9347570552c04e9d6211376e25e)) |
||||||
|
- **BREAKING** Request adapters now return a `Promise` ([157efd5](https://github.com/axios/axios/commit/157efd5615890301824e3121cc6c9d2f9b21f94a)) |
||||||
|
- Fixing issue with `withCredentials` not being overwritten ([#343](https://github.com/axios/axios/issues/343)) |
||||||
|
- Fixing regression with request transformer being called before request interceptor ([#352](https://github.com/axios/axios/issues/352)) |
||||||
|
- Fixing custom instance defaults ([#341](https://github.com/axios/axios/issues/341)) |
||||||
|
- Fixing instances created from `axios.create` to have same API as default axios ([#217](https://github.com/axios/axios/issues/217)) |
||||||
|
|
||||||
|
### 0.12.0 (May 31, 2016) |
||||||
|
|
||||||
|
- Adding support for `URLSearchParams` ([#317](https://github.com/axios/axios/pull/317)) |
||||||
|
- Adding `maxRedirects` option ([#307](https://github.com/axios/axios/pull/307)) |
||||||
|
|
||||||
|
### 0.11.1 (May 17, 2016) |
||||||
|
|
||||||
|
- Fixing IE CORS support ([#313](https://github.com/axios/axios/pull/313)) |
||||||
|
- Fixing detection of `FormData` ([#325](https://github.com/axios/axios/pull/325)) |
||||||
|
- Adding `Axios` class to exports ([#321](https://github.com/axios/axios/pull/321)) |
||||||
|
|
||||||
|
### 0.11.0 (Apr 26, 2016) |
||||||
|
|
||||||
|
- Adding support for Stream with HTTP adapter ([#296](https://github.com/axios/axios/pull/296)) |
||||||
|
- Adding support for custom HTTP status code error ranges ([#308](https://github.com/axios/axios/pull/308)) |
||||||
|
- Fixing issue with ArrayBuffer ([#299](https://github.com/axios/axios/pull/299)) |
||||||
|
|
||||||
|
### 0.10.0 (Apr 20, 2016) |
||||||
|
|
||||||
|
- Fixing issue with some requests sending `undefined` instead of `null` ([#250](https://github.com/axios/axios/pull/250)) |
||||||
|
- Fixing basic auth for HTTP adapter ([#252](https://github.com/axios/axios/pull/252)) |
||||||
|
- Fixing request timeout for XHR adapter ([#227](https://github.com/axios/axios/pull/227)) |
||||||
|
- Fixing IE8 support by using `onreadystatechange` instead of `onload` ([#249](https://github.com/axios/axios/pull/249)) |
||||||
|
- Fixing IE9 cross domain requests ([#251](https://github.com/axios/axios/pull/251)) |
||||||
|
- Adding `maxContentLength` option ([#275](https://github.com/axios/axios/pull/275)) |
||||||
|
- Fixing XHR support for WebWorker environment ([#279](https://github.com/axios/axios/pull/279)) |
||||||
|
- Adding request instance to response ([#200](https://github.com/axios/axios/pull/200)) |
||||||
|
|
||||||
|
### 0.9.1 (Jan 24, 2016) |
||||||
|
|
||||||
|
- Improving handling of request timeout in node ([#124](https://github.com/axios/axios/issues/124)) |
||||||
|
- Fixing network errors not rejecting ([#205](https://github.com/axios/axios/pull/205)) |
||||||
|
- Fixing issue with IE rejecting on HTTP 204 ([#201](https://github.com/axios/axios/issues/201)) |
||||||
|
- Fixing host/port when following redirects ([#198](https://github.com/axios/axios/pull/198)) |
||||||
|
|
||||||
|
### 0.9.0 (Jan 18, 2016) |
||||||
|
|
||||||
|
- Adding support for custom adapters |
||||||
|
- Fixing Content-Type header being removed when data is false ([#195](https://github.com/axios/axios/pull/195)) |
||||||
|
- Improving XDomainRequest implementation ([#185](https://github.com/axios/axios/pull/185)) |
||||||
|
- Improving config merging and order of precedence ([#183](https://github.com/axios/axios/pull/183)) |
||||||
|
- Fixing XDomainRequest support for only <= IE9 ([#182](https://github.com/axios/axios/pull/182)) |
||||||
|
|
||||||
|
### 0.8.1 (Dec 14, 2015) |
||||||
|
|
||||||
|
- Adding support for passing XSRF token for cross domain requests when using `withCredentials` ([#168](https://github.com/axios/axios/pull/168)) |
||||||
|
- Fixing error with format of basic auth header ([#178](https://github.com/axios/axios/pull/173)) |
||||||
|
- Fixing error with JSON payloads throwing `InvalidStateError` in some cases ([#174](https://github.com/axios/axios/pull/174)) |
||||||
|
|
||||||
|
### 0.8.0 (Dec 11, 2015) |
||||||
|
|
||||||
|
- Adding support for creating instances of axios ([#123](https://github.com/axios/axios/pull/123)) |
||||||
|
- Fixing http adapter to use `Buffer` instead of `String` in case of `responseType === 'arraybuffer'` ([#128](https://github.com/axios/axios/pull/128)) |
||||||
|
- Adding support for using custom parameter serializer with `paramsSerializer` option ([#121](https://github.com/axios/axios/pull/121)) |
||||||
|
- Fixing issue in IE8 caused by `forEach` on `arguments` ([#127](https://github.com/axios/axios/pull/127)) |
||||||
|
- Adding support for following redirects in node ([#146](https://github.com/axios/axios/pull/146)) |
||||||
|
- Adding support for transparent decompression if `content-encoding` is set ([#149](https://github.com/axios/axios/pull/149)) |
||||||
|
- Adding support for transparent XDomainRequest to handle cross domain requests in IE9 ([#140](https://github.com/axios/axios/pull/140)) |
||||||
|
- Adding support for HTTP basic auth via Authorization header ([#167](https://github.com/axios/axios/pull/167)) |
||||||
|
- Adding support for baseURL option ([#160](https://github.com/axios/axios/pull/160)) |
||||||
|
|
||||||
|
### 0.7.0 (Sep 29, 2015) |
||||||
|
|
||||||
|
- Fixing issue with minified bundle in IE8 ([#87](https://github.com/axios/axios/pull/87)) |
||||||
|
- Adding support for passing agent in node ([#102](https://github.com/axios/axios/pull/102)) |
||||||
|
- Adding support for returning result from `axios.spread` for chaining ([#106](https://github.com/axios/axios/pull/106)) |
||||||
|
- Fixing typescript definition ([#105](https://github.com/axios/axios/pull/105)) |
||||||
|
- Fixing default timeout config for node ([#112](https://github.com/axios/axios/pull/112)) |
||||||
|
- Adding support for use in web workers, and react-native ([#70](https://github.com/axios/axios/issue/70)), ([#98](https://github.com/axios/axios/pull/98)) |
||||||
|
- Adding support for fetch like API `axios(url[, config])` ([#116](https://github.com/axios/axios/issues/116)) |
||||||
|
|
||||||
|
### 0.6.0 (Sep 21, 2015) |
||||||
|
|
||||||
|
- Removing deprecated success/error aliases |
||||||
|
- Fixing issue with array params not being properly encoded ([#49](https://github.com/axios/axios/pull/49)) |
||||||
|
- Fixing issue with User-Agent getting overridden ([#69](https://github.com/axios/axios/issues/69)) |
||||||
|
- Adding support for timeout config ([#56](https://github.com/axios/axios/issues/56)) |
||||||
|
- Removing es6-promise dependency |
||||||
|
- Fixing issue preventing `length` to be used as a parameter ([#91](https://github.com/axios/axios/pull/91)) |
||||||
|
- Fixing issue with IE8 ([#85](https://github.com/axios/axios/pull/85)) |
||||||
|
- Converting build to UMD |
||||||
|
|
||||||
|
### 0.5.4 (Apr 08, 2015) |
||||||
|
|
||||||
|
- Fixing issue with FormData not being sent ([#53](https://github.com/axios/axios/issues/53)) |
||||||
|
|
||||||
|
### 0.5.3 (Apr 07, 2015) |
||||||
|
|
||||||
|
- Using JSON.parse unconditionally when transforming response string ([#55](https://github.com/axios/axios/issues/55)) |
||||||
|
|
||||||
|
### 0.5.2 (Mar 13, 2015) |
||||||
|
|
||||||
|
- Adding support for `statusText` in response ([#46](https://github.com/axios/axios/issues/46)) |
||||||
|
|
||||||
|
### 0.5.1 (Mar 10, 2015) |
||||||
|
|
||||||
|
- Fixing issue using strict mode ([#45](https://github.com/axios/axios/issues/45)) |
||||||
|
- Fixing issue with standalone build ([#47](https://github.com/axios/axios/issues/47)) |
||||||
|
|
||||||
|
### 0.5.0 (Jan 23, 2015) |
||||||
|
|
||||||
|
- Adding support for intercepetors ([#14](https://github.com/axios/axios/issues/14)) |
||||||
|
- Updating es6-promise dependency |
||||||
|
|
||||||
|
### 0.4.2 (Dec 10, 2014) |
||||||
|
|
||||||
|
- Fixing issue with `Content-Type` when using `FormData` ([#22](https://github.com/axios/axios/issues/22)) |
||||||
|
- Adding support for TypeScript ([#25](https://github.com/axios/axios/issues/25)) |
||||||
|
- Fixing issue with standalone build ([#29](https://github.com/axios/axios/issues/29)) |
||||||
|
- Fixing issue with verbs needing to be capitalized in some browsers ([#30](https://github.com/axios/axios/issues/30)) |
||||||
|
|
||||||
|
### 0.4.1 (Oct 15, 2014) |
||||||
|
|
||||||
|
- Adding error handling to request for node.js ([#18](https://github.com/axios/axios/issues/18)) |
||||||
|
|
||||||
|
### 0.4.0 (Oct 03, 2014) |
||||||
|
|
||||||
|
- Adding support for `ArrayBuffer` and `ArrayBufferView` ([#10](https://github.com/axios/axios/issues/10)) |
||||||
|
- Adding support for utf-8 for node.js ([#13](https://github.com/axios/axios/issues/13)) |
||||||
|
- Adding support for SSL for node.js ([#12](https://github.com/axios/axios/issues/12)) |
||||||
|
- Fixing incorrect `Content-Type` header ([#9](https://github.com/axios/axios/issues/9)) |
||||||
|
- Adding standalone build without bundled es6-promise ([#11](https://github.com/axios/axios/issues/11)) |
||||||
|
- Deprecating `success`/`error` in favor of `then`/`catch` |
||||||
|
|
||||||
|
### 0.3.1 (Sep 16, 2014) |
||||||
|
|
||||||
|
- Fixing missing post body when using node.js ([#3](https://github.com/axios/axios/issues/3)) |
||||||
|
|
||||||
|
### 0.3.0 (Sep 16, 2014) |
||||||
|
|
||||||
|
- Fixing `success` and `error` to properly receive response data as individual arguments ([#8](https://github.com/axios/axios/issues/8)) |
||||||
|
- Updating `then` and `catch` to receive response data as a single object ([#6](https://github.com/axios/axios/issues/6)) |
||||||
|
- Fixing issue with `all` not working ([#7](https://github.com/axios/axios/issues/7)) |
||||||
|
|
||||||
|
### 0.2.2 (Sep 14, 2014) |
||||||
|
|
||||||
|
- Fixing bundling with browserify ([#4](https://github.com/axios/axios/issues/4)) |
||||||
|
|
||||||
|
### 0.2.1 (Sep 12, 2014) |
||||||
|
|
||||||
|
- Fixing build problem causing ridiculous file sizes |
||||||
|
|
||||||
|
### 0.2.0 (Sep 12, 2014) |
||||||
|
|
||||||
|
- Adding support for `all` and `spread` |
||||||
|
- Adding support for node.js ([#1](https://github.com/axios/axios/issues/1)) |
||||||
|
|
||||||
|
### 0.1.0 (Aug 29, 2014) |
||||||
|
|
||||||
|
- Initial release |
@ -0,0 +1,19 @@ |
|||||||
|
Copyright (c) 2014-present Matt Zabriskie |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,800 @@ |
|||||||
|
# axios |
||||||
|
|
||||||
|
[![npm version](https://img.shields.io/npm/v/axios.svg?style=flat-square)](https://www.npmjs.org/package/axios) |
||||||
|
[![CDNJS](https://img.shields.io/cdnjs/v/axios.svg?style=flat-square)](https://cdnjs.com/libraries/axios) |
||||||
|
[![build status](https://img.shields.io/travis/axios/axios/master.svg?style=flat-square)](https://travis-ci.org/axios/axios) |
||||||
|
[![code coverage](https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square)](https://coveralls.io/r/mzabriskie/axios) |
||||||
|
[![install size](https://packagephobia.now.sh/badge?p=axios)](https://packagephobia.now.sh/result?p=axios) |
||||||
|
[![npm downloads](https://img.shields.io/npm/dm/axios.svg?style=flat-square)](http://npm-stat.com/charts.html?package=axios) |
||||||
|
[![gitter chat](https://img.shields.io/gitter/room/mzabriskie/axios.svg?style=flat-square)](https://gitter.im/mzabriskie/axios) |
||||||
|
[![code helpers](https://www.codetriage.com/axios/axios/badges/users.svg)](https://www.codetriage.com/axios/axios) |
||||||
|
|
||||||
|
Promise based HTTP client for the browser and node.js |
||||||
|
## Table of Contents |
||||||
|
|
||||||
|
- [Features](#features) |
||||||
|
- [Browser Support](#browser-support) |
||||||
|
- [Installing](#installing) |
||||||
|
- [Example](#example) |
||||||
|
- [Axios API](#axios-api) |
||||||
|
- [Request method aliases](#request-method-aliases) |
||||||
|
- [Concurrency (Deprecated)](#concurrency-deprecated) |
||||||
|
- [Creating an instance](#creating-an-instance) |
||||||
|
- [Instance methods](#instance-methods) |
||||||
|
- [Request Config](#request-config) |
||||||
|
- [Response Schema](#response-schema) |
||||||
|
- [Config Defaults](#config-defaults) |
||||||
|
- [Global axios defaults](#global-axios-defaults) |
||||||
|
- [Custom instance defaults](#custom-instance-defaults) |
||||||
|
- [Config order of precedence](#config-order-of-precedence) |
||||||
|
- [Interceptors](#interceptors) |
||||||
|
- [Handling Errors](#handling-errors) |
||||||
|
- [Cancellation](#cancellation) |
||||||
|
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format) |
||||||
|
- [Browser](#browser) |
||||||
|
- [Node.js](#nodejs) |
||||||
|
- [Query string](#query-string) |
||||||
|
- [Form data](#form-data) |
||||||
|
- [Semver](#semver) |
||||||
|
- [Promises](#promises) |
||||||
|
- [TypeScript](#typescript) |
||||||
|
- [Resources](#resources) |
||||||
|
- [Credits](#credits) |
||||||
|
- [License](#license) |
||||||
|
|
||||||
|
## Features |
||||||
|
|
||||||
|
- Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser |
||||||
|
- Make [http](http://nodejs.org/api/http.html) requests from node.js |
||||||
|
- Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API |
||||||
|
- Intercept request and response |
||||||
|
- Transform request and response data |
||||||
|
- Cancel requests |
||||||
|
- Automatic transforms for JSON data |
||||||
|
- Client side support for protecting against [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) |
||||||
|
|
||||||
|
## Browser Support |
||||||
|
|
||||||
|
![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) | |
||||||
|
--- | --- | --- | --- | --- | --- | |
||||||
|
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ | |
||||||
|
|
||||||
|
[![Browser Matrix](https://saucelabs.com/open_sauce/build_matrix/axios.svg)](https://saucelabs.com/u/axios) |
||||||
|
|
||||||
|
## Installing |
||||||
|
|
||||||
|
Using npm: |
||||||
|
|
||||||
|
```bash |
||||||
|
$ npm install axios |
||||||
|
``` |
||||||
|
|
||||||
|
Using bower: |
||||||
|
|
||||||
|
```bash |
||||||
|
$ bower install axios |
||||||
|
``` |
||||||
|
|
||||||
|
Using yarn: |
||||||
|
|
||||||
|
```bash |
||||||
|
$ yarn add axios |
||||||
|
``` |
||||||
|
|
||||||
|
Using jsDelivr CDN: |
||||||
|
|
||||||
|
```html |
||||||
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> |
||||||
|
``` |
||||||
|
|
||||||
|
Using unpkg CDN: |
||||||
|
|
||||||
|
```html |
||||||
|
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> |
||||||
|
``` |
||||||
|
|
||||||
|
## Example |
||||||
|
|
||||||
|
### note: CommonJS usage |
||||||
|
In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with `require()` use the following approach: |
||||||
|
|
||||||
|
```js |
||||||
|
const axios = require('axios').default; |
||||||
|
|
||||||
|
// axios.<method> will now provide autocomplete and parameter typings |
||||||
|
``` |
||||||
|
|
||||||
|
Performing a `GET` request |
||||||
|
|
||||||
|
```js |
||||||
|
const axios = require('axios'); |
||||||
|
|
||||||
|
// Make a request for a user with a given ID |
||||||
|
axios.get('/user?ID=12345') |
||||||
|
.then(function (response) { |
||||||
|
// handle success |
||||||
|
console.log(response); |
||||||
|
}) |
||||||
|
.catch(function (error) { |
||||||
|
// handle error |
||||||
|
console.log(error); |
||||||
|
}) |
||||||
|
.then(function () { |
||||||
|
// always executed |
||||||
|
}); |
||||||
|
|
||||||
|
// Optionally the request above could also be done as |
||||||
|
axios.get('/user', { |
||||||
|
params: { |
||||||
|
ID: 12345 |
||||||
|
} |
||||||
|
}) |
||||||
|
.then(function (response) { |
||||||
|
console.log(response); |
||||||
|
}) |
||||||
|
.catch(function (error) { |
||||||
|
console.log(error); |
||||||
|
}) |
||||||
|
.then(function () { |
||||||
|
// always executed |
||||||
|
}); |
||||||
|
|
||||||
|
// Want to use async/await? Add the `async` keyword to your outer function/method. |
||||||
|
async function getUser() { |
||||||
|
try { |
||||||
|
const response = await axios.get('/user?ID=12345'); |
||||||
|
console.log(response); |
||||||
|
} catch (error) { |
||||||
|
console.error(error); |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
> **NOTE:** `async/await` is part of ECMAScript 2017 and is not supported in Internet |
||||||
|
> Explorer and older browsers, so use with caution. |
||||||
|
|
||||||
|
Performing a `POST` request |
||||||
|
|
||||||
|
```js |
||||||
|
axios.post('/user', { |
||||||
|
firstName: 'Fred', |
||||||
|
lastName: 'Flintstone' |
||||||
|
}) |
||||||
|
.then(function (response) { |
||||||
|
console.log(response); |
||||||
|
}) |
||||||
|
.catch(function (error) { |
||||||
|
console.log(error); |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
Performing multiple concurrent requests |
||||||
|
|
||||||
|
```js |
||||||
|
function getUserAccount() { |
||||||
|
return axios.get('/user/12345'); |
||||||
|
} |
||||||
|
|
||||||
|
function getUserPermissions() { |
||||||
|
return axios.get('/user/12345/permissions'); |
||||||
|
} |
||||||
|
|
||||||
|
Promise.all([getUserAccount(), getUserPermissions()]) |
||||||
|
.then(function (results) { |
||||||
|
const acct = results[0]; |
||||||
|
const perm = results[1]; |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
## axios API |
||||||
|
|
||||||
|
Requests can be made by passing the relevant config to `axios`. |
||||||
|
|
||||||
|
##### axios(config) |
||||||
|
|
||||||
|
```js |
||||||
|
// Send a POST request |
||||||
|
axios({ |
||||||
|
method: 'post', |
||||||
|
url: '/user/12345', |
||||||
|
data: { |
||||||
|
firstName: 'Fred', |
||||||
|
lastName: 'Flintstone' |
||||||
|
} |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
```js |
||||||
|
// GET request for remote image in node.js |
||||||
|
axios({ |
||||||
|
method: 'get', |
||||||
|
url: 'http://bit.ly/2mTM3nY', |
||||||
|
responseType: 'stream' |
||||||
|
}) |
||||||
|
.then(function (response) { |
||||||
|
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg')) |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
##### axios(url[, config]) |
||||||
|
|
||||||
|
```js |
||||||
|
// Send a GET request (default method) |
||||||
|
axios('/user/12345'); |
||||||
|
``` |
||||||
|
|
||||||
|
### Request method aliases |
||||||
|
|
||||||
|
For convenience aliases have been provided for all supported request methods. |
||||||
|
|
||||||
|
##### axios.request(config) |
||||||
|
##### axios.get(url[, config]) |
||||||
|
##### axios.delete(url[, config]) |
||||||
|
##### axios.head(url[, config]) |
||||||
|
##### axios.options(url[, config]) |
||||||
|
##### axios.post(url[, data[, config]]) |
||||||
|
##### axios.put(url[, data[, config]]) |
||||||
|
##### axios.patch(url[, data[, config]]) |
||||||
|
|
||||||
|
###### NOTE |
||||||
|
When using the alias methods `url`, `method`, and `data` properties don't need to be specified in config. |
||||||
|
|
||||||
|
### Concurrency (Deprecated) |
||||||
|
Please use `Promise.all` to replace the below functions. |
||||||
|
|
||||||
|
Helper functions for dealing with concurrent requests. |
||||||
|
|
||||||
|
axios.all(iterable) |
||||||
|
axios.spread(callback) |
||||||
|
|
||||||
|
### Creating an instance |
||||||
|
|
||||||
|
You can create a new instance of axios with a custom config. |
||||||
|
|
||||||
|
##### axios.create([config]) |
||||||
|
|
||||||
|
```js |
||||||
|
const instance = axios.create({ |
||||||
|
baseURL: 'https://some-domain.com/api/', |
||||||
|
timeout: 1000, |
||||||
|
headers: {'X-Custom-Header': 'foobar'} |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
### Instance methods |
||||||
|
|
||||||
|
The available instance methods are listed below. The specified config will be merged with the instance config. |
||||||
|
|
||||||
|
##### axios#request(config) |
||||||
|
##### axios#get(url[, config]) |
||||||
|
##### axios#delete(url[, config]) |
||||||
|
##### axios#head(url[, config]) |
||||||
|
##### axios#options(url[, config]) |
||||||
|
##### axios#post(url[, data[, config]]) |
||||||
|
##### axios#put(url[, data[, config]]) |
||||||
|
##### axios#patch(url[, data[, config]]) |
||||||
|
##### axios#getUri([config]) |
||||||
|
|
||||||
|
## Request Config |
||||||
|
|
||||||
|
These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified. |
||||||
|
|
||||||
|
```js |
||||||
|
{ |
||||||
|
// `url` is the server URL that will be used for the request |
||||||
|
url: '/user', |
||||||
|
|
||||||
|
// `method` is the request method to be used when making the request |
||||||
|
method: 'get', // default |
||||||
|
|
||||||
|
// `baseURL` will be prepended to `url` unless `url` is absolute. |
||||||
|
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs |
||||||
|
// to methods of that instance. |
||||||
|
baseURL: 'https://some-domain.com/api/', |
||||||
|
|
||||||
|
// `transformRequest` allows changes to the request data before it is sent to the server |
||||||
|
// This is only applicable for request methods 'PUT', 'POST', 'PATCH' and 'DELETE' |
||||||
|
// The last function in the array must return a string or an instance of Buffer, ArrayBuffer, |
||||||
|
// FormData or Stream |
||||||
|
// You may modify the headers object. |
||||||
|
transformRequest: [function (data, headers) { |
||||||
|
// Do whatever you want to transform the data |
||||||
|
|
||||||
|
return data; |
||||||
|
}], |
||||||
|
|
||||||
|
// `transformResponse` allows changes to the response data to be made before |
||||||
|
// it is passed to then/catch |
||||||
|
transformResponse: [function (data) { |
||||||
|
// Do whatever you want to transform the data |
||||||
|
|
||||||
|
return data; |
||||||
|
}], |
||||||
|
|
||||||
|
// `headers` are custom headers to be sent |
||||||
|
headers: {'X-Requested-With': 'XMLHttpRequest'}, |
||||||
|
|
||||||
|
// `params` are the URL parameters to be sent with the request |
||||||
|
// Must be a plain object or a URLSearchParams object |
||||||
|
params: { |
||||||
|
ID: 12345 |
||||||
|
}, |
||||||
|
|
||||||
|
// `paramsSerializer` is an optional function in charge of serializing `params` |
||||||
|
// (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/) |
||||||
|
paramsSerializer: function (params) { |
||||||
|
return Qs.stringify(params, {arrayFormat: 'brackets'}) |
||||||
|
}, |
||||||
|
|
||||||
|
// `data` is the data to be sent as the request body |
||||||
|
// Only applicable for request methods 'PUT', 'POST', 'DELETE , and 'PATCH' |
||||||
|
// When no `transformRequest` is set, must be of one of the following types: |
||||||
|
// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams |
||||||
|
// - Browser only: FormData, File, Blob |
||||||
|
// - Node only: Stream, Buffer |
||||||
|
data: { |
||||||
|
firstName: 'Fred' |
||||||
|
}, |
||||||
|
|
||||||
|
// syntax alternative to send data into the body |
||||||
|
// method post |
||||||
|
// only the value is sent, not the key |
||||||
|
data: 'Country=Brasil&City=Belo Horizonte', |
||||||
|
|
||||||
|
// `timeout` specifies the number of milliseconds before the request times out. |
||||||
|
// If the request takes longer than `timeout`, the request will be aborted. |
||||||
|
timeout: 1000, // default is `0` (no timeout) |
||||||
|
|
||||||
|
// `withCredentials` indicates whether or not cross-site Access-Control requests |
||||||
|
// should be made using credentials |
||||||
|
withCredentials: false, // default |
||||||
|
|
||||||
|
// `adapter` allows custom handling of requests which makes testing easier. |
||||||
|
// Return a promise and supply a valid response (see lib/adapters/README.md). |
||||||
|
adapter: function (config) { |
||||||
|
/* ... */ |
||||||
|
}, |
||||||
|
|
||||||
|
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials. |
||||||
|
// This will set an `Authorization` header, overwriting any existing |
||||||
|
// `Authorization` custom headers you have set using `headers`. |
||||||
|
// Please note that only HTTP Basic auth is configurable through this parameter. |
||||||
|
// For Bearer tokens and such, use `Authorization` custom headers instead. |
||||||
|
auth: { |
||||||
|
username: 'janedoe', |
||||||
|
password: 's00pers3cret' |
||||||
|
}, |
||||||
|
|
||||||
|
// `responseType` indicates the type of data that the server will respond with |
||||||
|
// options are: 'arraybuffer', 'document', 'json', 'text', 'stream' |
||||||
|
// browser only: 'blob' |
||||||
|
responseType: 'json', // default |
||||||
|
|
||||||
|
// `responseEncoding` indicates encoding to use for decoding responses (Node.js only) |
||||||
|
// Note: Ignored for `responseType` of 'stream' or client-side requests |
||||||
|
responseEncoding: 'utf8', // default |
||||||
|
|
||||||
|
// `xsrfCookieName` is the name of the cookie to use as a value for xsrf token |
||||||
|
xsrfCookieName: 'XSRF-TOKEN', // default |
||||||
|
|
||||||
|
// `xsrfHeaderName` is the name of the http header that carries the xsrf token value |
||||||
|
xsrfHeaderName: 'X-XSRF-TOKEN', // default |
||||||
|
|
||||||
|
// `onUploadProgress` allows handling of progress events for uploads |
||||||
|
// browser only |
||||||
|
onUploadProgress: function (progressEvent) { |
||||||
|
// Do whatever you want with the native progress event |
||||||
|
}, |
||||||
|
|
||||||
|
// `onDownloadProgress` allows handling of progress events for downloads |
||||||
|
// browser only |
||||||
|
onDownloadProgress: function (progressEvent) { |
||||||
|
// Do whatever you want with the native progress event |
||||||
|
}, |
||||||
|
|
||||||
|
// `maxContentLength` defines the max size of the http response content in bytes allowed in node.js |
||||||
|
maxContentLength: 2000, |
||||||
|
|
||||||
|
// `maxBodyLength` (Node only option) defines the max size of the http request content in bytes allowed |
||||||
|
maxBodyLength: 2000, |
||||||
|
|
||||||
|
// `validateStatus` defines whether to resolve or reject the promise for a given |
||||||
|
// HTTP response status code. If `validateStatus` returns `true` (or is set to `null` |
||||||
|
// or `undefined`), the promise will be resolved; otherwise, the promise will be |
||||||
|
// rejected. |
||||||
|
validateStatus: function (status) { |
||||||
|
return status >= 200 && status < 300; // default |
||||||
|
}, |
||||||
|
|
||||||
|
// `maxRedirects` defines the maximum number of redirects to follow in node.js. |
||||||
|
// If set to 0, no redirects will be followed. |
||||||
|
maxRedirects: 5, // default |
||||||
|
|
||||||
|
// `socketPath` defines a UNIX Socket to be used in node.js. |
||||||
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon. |
||||||
|
// Only either `socketPath` or `proxy` can be specified. |
||||||
|
// If both are specified, `socketPath` is used. |
||||||
|
socketPath: null, // default |
||||||
|
|
||||||
|
// `httpAgent` and `httpsAgent` define a custom agent to be used when performing http |
||||||
|
// and https requests, respectively, in node.js. This allows options to be added like |
||||||
|
// `keepAlive` that are not enabled by default. |
||||||
|
httpAgent: new http.Agent({ keepAlive: true }), |
||||||
|
httpsAgent: new https.Agent({ keepAlive: true }), |
||||||
|
|
||||||
|
// `proxy` defines the hostname, port, and protocol of the proxy server. |
||||||
|
// You can also define your proxy using the conventional `http_proxy` and |
||||||
|
// `https_proxy` environment variables. If you are using environment variables |
||||||
|
// for your proxy configuration, you can also define a `no_proxy` environment |
||||||
|
// variable as a comma-separated list of domains that should not be proxied. |
||||||
|
// Use `false` to disable proxies, ignoring environment variables. |
||||||
|
// `auth` indicates that HTTP Basic auth should be used to connect to the proxy, and |
||||||
|
// supplies credentials. |
||||||
|
// This will set an `Proxy-Authorization` header, overwriting any existing |
||||||
|
// `Proxy-Authorization` custom headers you have set using `headers`. |
||||||
|
// If the proxy server uses HTTPS, then you must set the protocol to `https`. |
||||||
|
proxy: { |
||||||
|
protocol: 'https', |
||||||
|
host: '127.0.0.1', |
||||||
|
port: 9000, |
||||||
|
auth: { |
||||||
|
username: 'mikeymike', |
||||||
|
password: 'rapunz3l' |
||||||
|
} |
||||||
|
}, |
||||||
|
|
||||||
|
// `cancelToken` specifies a cancel token that can be used to cancel the request |
||||||
|
// (see Cancellation section below for details) |
||||||
|
cancelToken: new CancelToken(function (cancel) { |
||||||
|
}), |
||||||
|
|
||||||
|
// `decompress` indicates whether or not the response body should be decompressed |
||||||
|
// automatically. If set to `true` will also remove the 'content-encoding' header |
||||||
|
// from the responses objects of all decompressed responses |
||||||
|
// - Node only (XHR cannot turn off decompression) |
||||||
|
decompress: true // default |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
## Response Schema |
||||||
|
|
||||||
|
The response for a request contains the following information. |
||||||
|
|
||||||
|
```js |
||||||
|
{ |
||||||
|
// `data` is the response that was provided by the server |
||||||
|
data: {}, |
||||||
|
|
||||||
|
// `status` is the HTTP status code from the server response |
||||||
|
status: 200, |
||||||
|
|
||||||
|
// `statusText` is the HTTP status message from the server response |
||||||
|
statusText: 'OK', |
||||||
|
|
||||||
|
// `headers` the HTTP headers that the server responded with |
||||||
|
// All header names are lower cased and can be accessed using the bracket notation. |
||||||
|
// Example: `response.headers['content-type']` |
||||||
|
headers: {}, |
||||||
|
|
||||||
|
// `config` is the config that was provided to `axios` for the request |
||||||
|
config: {}, |
||||||
|
|
||||||
|
// `request` is the request that generated this response |
||||||
|
// It is the last ClientRequest instance in node.js (in redirects) |
||||||
|
// and an XMLHttpRequest instance in the browser |
||||||
|
request: {} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
When using `then`, you will receive the response as follows: |
||||||
|
|
||||||
|
```js |
||||||
|
axios.get('/user/12345') |
||||||
|
.then(function (response) { |
||||||
|
console.log(response.data); |
||||||
|
console.log(response.status); |
||||||
|
console.log(response.statusText); |
||||||
|
console.log(response.headers); |
||||||
|
console.log(response.config); |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
When using `catch`, or passing a [rejection callback](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) as second parameter of `then`, the response will be available through the `error` object as explained in the [Handling Errors](#handling-errors) section. |
||||||
|
|
||||||
|
## Config Defaults |
||||||
|
|
||||||
|
You can specify config defaults that will be applied to every request. |
||||||
|
|
||||||
|
### Global axios defaults |
||||||
|
|
||||||
|
```js |
||||||
|
axios.defaults.baseURL = 'https://api.example.com'; |
||||||
|
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; |
||||||
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; |
||||||
|
``` |
||||||
|
|
||||||
|
### Custom instance defaults |
||||||
|
|
||||||
|
```js |
||||||
|
// Set config defaults when creating the instance |
||||||
|
const instance = axios.create({ |
||||||
|
baseURL: 'https://api.example.com' |
||||||
|
}); |
||||||
|
|
||||||
|
// Alter defaults after instance has been created |
||||||
|
instance.defaults.headers.common['Authorization'] = AUTH_TOKEN; |
||||||
|
``` |
||||||
|
|
||||||
|
### Config order of precedence |
||||||
|
|
||||||
|
Config will be merged with an order of precedence. The order is library defaults found in [lib/defaults.js](https://github.com/axios/axios/blob/master/lib/defaults.js#L28), then `defaults` property of the instance, and finally `config` argument for the request. The latter will take precedence over the former. Here's an example. |
||||||
|
|
||||||
|
```js |
||||||
|
// Create an instance using the config defaults provided by the library |
||||||
|
// At this point the timeout config value is `0` as is the default for the library |
||||||
|
const instance = axios.create(); |
||||||
|
|
||||||
|
// Override timeout default for the library |
||||||
|
// Now all requests using this instance will wait 2.5 seconds before timing out |
||||||
|
instance.defaults.timeout = 2500; |
||||||
|
|
||||||
|
// Override timeout for this request as it's known to take a long time |
||||||
|
instance.get('/longRequest', { |
||||||
|
timeout: 5000 |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
## Interceptors |
||||||
|
|
||||||
|
You can intercept requests or responses before they are handled by `then` or `catch`. |
||||||
|
|
||||||
|
```js |
||||||
|
// Add a request interceptor |
||||||
|
axios.interceptors.request.use(function (config) { |
||||||
|
// Do something before request is sent |
||||||
|
return config; |
||||||
|
}, function (error) { |
||||||
|
// Do something with request error |
||||||
|
return Promise.reject(error); |
||||||
|
}); |
||||||
|
|
||||||
|
// Add a response interceptor |
||||||
|
axios.interceptors.response.use(function (response) { |
||||||
|
// Any status code that lie within the range of 2xx cause this function to trigger |
||||||
|
// Do something with response data |
||||||
|
return response; |
||||||
|
}, function (error) { |
||||||
|
// Any status codes that falls outside the range of 2xx cause this function to trigger |
||||||
|
// Do something with response error |
||||||
|
return Promise.reject(error); |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
If you need to remove an interceptor later you can. |
||||||
|
|
||||||
|
```js |
||||||
|
const myInterceptor = axios.interceptors.request.use(function () {/*...*/}); |
||||||
|
axios.interceptors.request.eject(myInterceptor); |
||||||
|
``` |
||||||
|
|
||||||
|
You can add interceptors to a custom instance of axios. |
||||||
|
|
||||||
|
```js |
||||||
|
const instance = axios.create(); |
||||||
|
instance.interceptors.request.use(function () {/*...*/}); |
||||||
|
``` |
||||||
|
|
||||||
|
## Handling Errors |
||||||
|
|
||||||
|
```js |
||||||
|
axios.get('/user/12345') |
||||||
|
.catch(function (error) { |
||||||
|
if (error.response) { |
||||||
|
// The request was made and the server responded with a status code |
||||||
|
// that falls out of the range of 2xx |
||||||
|
console.log(error.response.data); |
||||||
|
console.log(error.response.status); |
||||||
|
console.log(error.response.headers); |
||||||
|
} else if (error.request) { |
||||||
|
// The request was made but no response was received |
||||||
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of |
||||||
|
// http.ClientRequest in node.js |
||||||
|
console.log(error.request); |
||||||
|
} else { |
||||||
|
// Something happened in setting up the request that triggered an Error |
||||||
|
console.log('Error', error.message); |
||||||
|
} |
||||||
|
console.log(error.config); |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
Using the `validateStatus` config option, you can define HTTP code(s) that should throw an error. |
||||||
|
|
||||||
|
```js |
||||||
|
axios.get('/user/12345', { |
||||||
|
validateStatus: function (status) { |
||||||
|
return status < 500; // Resolve only if the status code is less than 500 |
||||||
|
} |
||||||
|
}) |
||||||
|
``` |
||||||
|
|
||||||
|
Using `toJSON` you get an object with more information about the HTTP error. |
||||||
|
|
||||||
|
```js |
||||||
|
axios.get('/user/12345') |
||||||
|
.catch(function (error) { |
||||||
|
console.log(error.toJSON()); |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
## Cancellation |
||||||
|
|
||||||
|
You can cancel a request using a *cancel token*. |
||||||
|
|
||||||
|
> The axios cancel token API is based on the withdrawn [cancelable promises proposal](https://github.com/tc39/proposal-cancelable-promises). |
||||||
|
|
||||||
|
You can create a cancel token using the `CancelToken.source` factory as shown below: |
||||||
|
|
||||||
|
```js |
||||||
|
const CancelToken = axios.CancelToken; |
||||||
|
const source = CancelToken.source(); |
||||||
|
|
||||||
|
axios.get('/user/12345', { |
||||||
|
cancelToken: source.token |
||||||
|
}).catch(function (thrown) { |
||||||
|
if (axios.isCancel(thrown)) { |
||||||
|
console.log('Request canceled', thrown.message); |
||||||
|
} else { |
||||||
|
// handle error |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
axios.post('/user/12345', { |
||||||
|
name: 'new name' |
||||||
|
}, { |
||||||
|
cancelToken: source.token |
||||||
|
}) |
||||||
|
|
||||||
|
// cancel the request (the message parameter is optional) |
||||||
|
source.cancel('Operation canceled by the user.'); |
||||||
|
``` |
||||||
|
|
||||||
|
You can also create a cancel token by passing an executor function to the `CancelToken` constructor: |
||||||
|
|
||||||
|
```js |
||||||
|
const CancelToken = axios.CancelToken; |
||||||
|
let cancel; |
||||||
|
|
||||||
|
axios.get('/user/12345', { |
||||||
|
cancelToken: new CancelToken(function executor(c) { |
||||||
|
// An executor function receives a cancel function as a parameter |
||||||
|
cancel = c; |
||||||
|
}) |
||||||
|
}); |
||||||
|
|
||||||
|
// cancel the request |
||||||
|
cancel(); |
||||||
|
``` |
||||||
|
|
||||||
|
> Note: you can cancel several requests with the same cancel token. |
||||||
|
|
||||||
|
## Using application/x-www-form-urlencoded format |
||||||
|
|
||||||
|
By default, axios serializes JavaScript objects to `JSON`. To send data in the `application/x-www-form-urlencoded` format instead, you can use one of the following options. |
||||||
|
|
||||||
|
### Browser |
||||||
|
|
||||||
|
In a browser, you can use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API as follows: |
||||||
|
|
||||||
|
```js |
||||||
|
const params = new URLSearchParams(); |
||||||
|
params.append('param1', 'value1'); |
||||||
|
params.append('param2', 'value2'); |
||||||
|
axios.post('/foo', params); |
||||||
|
``` |
||||||
|
|
||||||
|
> Note that `URLSearchParams` is not supported by all browsers (see [caniuse.com](http://www.caniuse.com/#feat=urlsearchparams)), but there is a [polyfill](https://github.com/WebReflection/url-search-params) available (make sure to polyfill the global environment). |
||||||
|
|
||||||
|
Alternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library: |
||||||
|
|
||||||
|
```js |
||||||
|
const qs = require('qs'); |
||||||
|
axios.post('/foo', qs.stringify({ 'bar': 123 })); |
||||||
|
``` |
||||||
|
|
||||||
|
Or in another way (ES6), |
||||||
|
|
||||||
|
```js |
||||||
|
import qs from 'qs'; |
||||||
|
const data = { 'bar': 123 }; |
||||||
|
const options = { |
||||||
|
method: 'POST', |
||||||
|
headers: { 'content-type': 'application/x-www-form-urlencoded' }, |
||||||
|
data: qs.stringify(data), |
||||||
|
url, |
||||||
|
}; |
||||||
|
axios(options); |
||||||
|
``` |
||||||
|
|
||||||
|
### Node.js |
||||||
|
|
||||||
|
#### Query string |
||||||
|
|
||||||
|
In node.js, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows: |
||||||
|
|
||||||
|
```js |
||||||
|
const querystring = require('querystring'); |
||||||
|
axios.post('http://something.com/', querystring.stringify({ foo: 'bar' })); |
||||||
|
``` |
||||||
|
|
||||||
|
or ['URLSearchParams'](https://nodejs.org/api/url.html#url_class_urlsearchparams) from ['url module'](https://nodejs.org/api/url.html) as follows: |
||||||
|
|
||||||
|
```js |
||||||
|
const url = require('url'); |
||||||
|
const params = new url.URLSearchParams({ foo: 'bar' }); |
||||||
|
axios.post('http://something.com/', params.toString()); |
||||||
|
``` |
||||||
|
|
||||||
|
You can also use the [`qs`](https://github.com/ljharb/qs) library. |
||||||
|
|
||||||
|
###### NOTE |
||||||
|
The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has known issues with that use case (https://github.com/nodejs/node-v0.x-archive/issues/1665). |
||||||
|
|
||||||
|
#### Form data |
||||||
|
|
||||||
|
In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows: |
||||||
|
|
||||||
|
```js |
||||||
|
const FormData = require('form-data'); |
||||||
|
|
||||||
|
const form = new FormData(); |
||||||
|
form.append('my_field', 'my value'); |
||||||
|
form.append('my_buffer', new Buffer(10)); |
||||||
|
form.append('my_file', fs.createReadStream('/foo/bar.jpg')); |
||||||
|
|
||||||
|
axios.post('https://example.com', form, { headers: form.getHeaders() }) |
||||||
|
``` |
||||||
|
|
||||||
|
Alternatively, use an interceptor: |
||||||
|
|
||||||
|
```js |
||||||
|
axios.interceptors.request.use(config => { |
||||||
|
if (config.data instanceof FormData) { |
||||||
|
Object.assign(config.headers, config.data.getHeaders()); |
||||||
|
} |
||||||
|
return config; |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
## Semver |
||||||
|
|
||||||
|
Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes. |
||||||
|
|
||||||
|
## Promises |
||||||
|
|
||||||
|
axios depends on a native ES6 Promise implementation to be [supported](http://caniuse.com/promises). |
||||||
|
If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise). |
||||||
|
|
||||||
|
## TypeScript |
||||||
|
axios includes [TypeScript](http://typescriptlang.org) definitions. |
||||||
|
```typescript |
||||||
|
import axios from 'axios'; |
||||||
|
axios.get('/user?ID=12345'); |
||||||
|
``` |
||||||
|
|
||||||
|
## Resources |
||||||
|
|
||||||
|
* [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md) |
||||||
|
* [Upgrade Guide](https://github.com/axios/axios/blob/master/UPGRADE_GUIDE.md) |
||||||
|
* [Ecosystem](https://github.com/axios/axios/blob/master/ECOSYSTEM.md) |
||||||
|
* [Contributing Guide](https://github.com/axios/axios/blob/master/CONTRIBUTING.md) |
||||||
|
* [Code of Conduct](https://github.com/axios/axios/blob/master/CODE_OF_CONDUCT.md) |
||||||
|
|
||||||
|
## Credits |
||||||
|
|
||||||
|
axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) provided in [Angular](https://angularjs.org/). Ultimately axios is an effort to provide a standalone `$http`-like service for use outside of Angular. |
||||||
|
|
||||||
|
## License |
||||||
|
|
||||||
|
[MIT](LICENSE) |
@ -0,0 +1,162 @@ |
|||||||
|
# Upgrade Guide |
||||||
|
|
||||||
|
### 0.15.x -> 0.16.0 |
||||||
|
|
||||||
|
#### `Promise` Type Declarations |
||||||
|
|
||||||
|
The `Promise` type declarations have been removed from the axios typings in favor of the built-in type declarations. If you use axios in a TypeScript project that targets `ES5`, please make sure to include the `es2015.promise` lib. Please see [this post](https://blog.mariusschulz.com/2016/11/25/typescript-2-0-built-in-type-declarations) for details. |
||||||
|
|
||||||
|
### 0.13.x -> 0.14.0 |
||||||
|
|
||||||
|
#### TypeScript Definitions |
||||||
|
|
||||||
|
The axios TypeScript definitions have been updated to match the axios API and use the ES2015 module syntax. |
||||||
|
|
||||||
|
Please use the following `import` statement to import axios in TypeScript: |
||||||
|
|
||||||
|
```typescript |
||||||
|
import axios from 'axios'; |
||||||
|
|
||||||
|
axios.get('/foo') |
||||||
|
.then(response => console.log(response)) |
||||||
|
.catch(error => console.log(error)); |
||||||
|
``` |
||||||
|
|
||||||
|
#### `agent` Config Option |
||||||
|
|
||||||
|
The `agent` config option has been replaced with two new options: `httpAgent` and `httpsAgent`. Please use them instead. |
||||||
|
|
||||||
|
```js |
||||||
|
{ |
||||||
|
// Define a custom agent for HTTP |
||||||
|
httpAgent: new http.Agent({ keepAlive: true }), |
||||||
|
// Define a custom agent for HTTPS |
||||||
|
httpsAgent: new https.Agent({ keepAlive: true }) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
#### `progress` Config Option |
||||||
|
|
||||||
|
The `progress` config option has been replaced with the `onUploadProgress` and `onDownloadProgress` options. |
||||||
|
|
||||||
|
```js |
||||||
|
{ |
||||||
|
// Define a handler for upload progress events |
||||||
|
onUploadProgress: function (progressEvent) { |
||||||
|
// ... |
||||||
|
}, |
||||||
|
|
||||||
|
// Define a handler for download progress events |
||||||
|
onDownloadProgress: function (progressEvent) { |
||||||
|
// ... |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### 0.12.x -> 0.13.0 |
||||||
|
|
||||||
|
The `0.13.0` release contains several changes to custom adapters and error handling. |
||||||
|
|
||||||
|
#### Error Handling |
||||||
|
|
||||||
|
Previous to this release an error could either be a server response with bad status code or an actual `Error`. With this release Promise will always reject with an `Error`. In the case that a response was received, the `Error` will also include the response. |
||||||
|
|
||||||
|
```js |
||||||
|
axios.get('/user/12345') |
||||||
|
.catch((error) => { |
||||||
|
console.log(error.message); |
||||||
|
console.log(error.code); // Not always specified |
||||||
|
console.log(error.config); // The config that was used to make the request |
||||||
|
console.log(error.response); // Only available if response was received from the server |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
#### Request Adapters |
||||||
|
|
||||||
|
This release changes a few things about how request adapters work. Please take note if you are using your own custom adapter. |
||||||
|
|
||||||
|
1. Response transformer is now called outside of adapter. |
||||||
|
2. Request adapter returns a `Promise`. |
||||||
|
|
||||||
|
This means that you no longer need to invoke `transformData` on response data. You will also no longer receive `resolve` and `reject` as arguments in your adapter. |
||||||
|
|
||||||
|
Previous code: |
||||||
|
|
||||||
|
```js |
||||||
|
function myAdapter(resolve, reject, config) { |
||||||
|
var response = { |
||||||
|
data: transformData( |
||||||
|
responseData, |
||||||
|
responseHeaders, |
||||||
|
config.transformResponse |
||||||
|
), |
||||||
|
status: request.status, |
||||||
|
statusText: request.statusText, |
||||||
|
headers: responseHeaders |
||||||
|
}; |
||||||
|
settle(resolve, reject, response); |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
New code: |
||||||
|
|
||||||
|
```js |
||||||
|
function myAdapter(config) { |
||||||
|
return new Promise(function (resolve, reject) { |
||||||
|
var response = { |
||||||
|
data: responseData, |
||||||
|
status: request.status, |
||||||
|
statusText: request.statusText, |
||||||
|
headers: responseHeaders |
||||||
|
}; |
||||||
|
settle(resolve, reject, response); |
||||||
|
}); |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
See the related commits for more details: |
||||||
|
- [Response transformers](https://github.com/axios/axios/commit/10eb23865101f9347570552c04e9d6211376e25e) |
||||||
|
- [Request adapter Promise](https://github.com/axios/axios/commit/157efd5615890301824e3121cc6c9d2f9b21f94a) |
||||||
|
|
||||||
|
### 0.5.x -> 0.6.0 |
||||||
|
|
||||||
|
The `0.6.0` release contains mostly bug fixes, but there are a couple things to be aware of when upgrading. |
||||||
|
|
||||||
|
#### ES6 Promise Polyfill |
||||||
|
|
||||||
|
Up until the `0.6.0` release ES6 `Promise` was being polyfilled using [es6-promise](https://github.com/jakearchibald/es6-promise). With this release, the polyfill has been removed, and you will need to supply it yourself if your environment needs it. |
||||||
|
|
||||||
|
```js |
||||||
|
require('es6-promise').polyfill(); |
||||||
|
var axios = require('axios'); |
||||||
|
``` |
||||||
|
|
||||||
|
This will polyfill the global environment, and only needs to be done once. |
||||||
|
|
||||||
|
#### `axios.success`/`axios.error` |
||||||
|
|
||||||
|
The `success`, and `error` aliases were deprecated in [0.4.0](https://github.com/axios/axios/blob/master/CHANGELOG.md#040-oct-03-2014). As of this release they have been removed entirely. Instead please use `axios.then`, and `axios.catch` respectively. |
||||||
|
|
||||||
|
```js |
||||||
|
axios.get('some/url') |
||||||
|
.then(function (res) { |
||||||
|
/* ... */ |
||||||
|
}) |
||||||
|
.catch(function (err) { |
||||||
|
/* ... */ |
||||||
|
}); |
||||||
|
``` |
||||||
|
|
||||||
|
#### UMD |
||||||
|
|
||||||
|
Previous versions of axios shipped with an AMD, CommonJS, and Global build. This has all been rolled into a single UMD build. |
||||||
|
|
||||||
|
```js |
||||||
|
// AMD |
||||||
|
require(['bower_components/axios/dist/axios'], function (axios) { |
||||||
|
/* ... */ |
||||||
|
}); |
||||||
|
|
||||||
|
// CommonJS |
||||||
|
var axios = require('axios/dist/axios'); |
||||||
|
``` |
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,161 @@ |
|||||||
|
export interface AxiosTransformer { |
||||||
|
(data: any, headers?: any): any; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosAdapter { |
||||||
|
(config: AxiosRequestConfig): AxiosPromise<any>; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosBasicCredentials { |
||||||
|
username: string; |
||||||
|
password: string; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosProxyConfig { |
||||||
|
host: string; |
||||||
|
port: number; |
||||||
|
auth?: { |
||||||
|
username: string; |
||||||
|
password:string; |
||||||
|
}; |
||||||
|
protocol?: string; |
||||||
|
} |
||||||
|
|
||||||
|
export type Method = |
||||||
|
| 'get' | 'GET' |
||||||
|
| 'delete' | 'DELETE' |
||||||
|
| 'head' | 'HEAD' |
||||||
|
| 'options' | 'OPTIONS' |
||||||
|
| 'post' | 'POST' |
||||||
|
| 'put' | 'PUT' |
||||||
|
| 'patch' | 'PATCH' |
||||||
|
| 'purge' | 'PURGE' |
||||||
|
| 'link' | 'LINK' |
||||||
|
| 'unlink' | 'UNLINK' |
||||||
|
|
||||||
|
export type ResponseType = |
||||||
|
| 'arraybuffer' |
||||||
|
| 'blob' |
||||||
|
| 'document' |
||||||
|
| 'json' |
||||||
|
| 'text' |
||||||
|
| 'stream' |
||||||
|
|
||||||
|
export interface AxiosRequestConfig { |
||||||
|
url?: string; |
||||||
|
method?: Method; |
||||||
|
baseURL?: string; |
||||||
|
transformRequest?: AxiosTransformer | AxiosTransformer[]; |
||||||
|
transformResponse?: AxiosTransformer | AxiosTransformer[]; |
||||||
|
headers?: any; |
||||||
|
params?: any; |
||||||
|
paramsSerializer?: (params: any) => string; |
||||||
|
data?: any; |
||||||
|
timeout?: number; |
||||||
|
timeoutErrorMessage?: string; |
||||||
|
withCredentials?: boolean; |
||||||
|
adapter?: AxiosAdapter; |
||||||
|
auth?: AxiosBasicCredentials; |
||||||
|
responseType?: ResponseType; |
||||||
|
xsrfCookieName?: string; |
||||||
|
xsrfHeaderName?: string; |
||||||
|
onUploadProgress?: (progressEvent: any) => void; |
||||||
|
onDownloadProgress?: (progressEvent: any) => void; |
||||||
|
maxContentLength?: number; |
||||||
|
validateStatus?: ((status: number) => boolean) | null; |
||||||
|
maxBodyLength?: number; |
||||||
|
maxRedirects?: number; |
||||||
|
socketPath?: string | null; |
||||||
|
httpAgent?: any; |
||||||
|
httpsAgent?: any; |
||||||
|
proxy?: AxiosProxyConfig | false; |
||||||
|
cancelToken?: CancelToken; |
||||||
|
decompress?: boolean; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosResponse<T = any> { |
||||||
|
data: T; |
||||||
|
status: number; |
||||||
|
statusText: string; |
||||||
|
headers: any; |
||||||
|
config: AxiosRequestConfig; |
||||||
|
request?: any; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosError<T = any> extends Error { |
||||||
|
config: AxiosRequestConfig; |
||||||
|
code?: string; |
||||||
|
request?: any; |
||||||
|
response?: AxiosResponse<T>; |
||||||
|
isAxiosError: boolean; |
||||||
|
toJSON: () => object; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> { |
||||||
|
} |
||||||
|
|
||||||
|
export interface CancelStatic { |
||||||
|
new (message?: string): Cancel; |
||||||
|
} |
||||||
|
|
||||||
|
export interface Cancel { |
||||||
|
message: string; |
||||||
|
} |
||||||
|
|
||||||
|
export interface Canceler { |
||||||
|
(message?: string): void; |
||||||
|
} |
||||||
|
|
||||||
|
export interface CancelTokenStatic { |
||||||
|
new (executor: (cancel: Canceler) => void): CancelToken; |
||||||
|
source(): CancelTokenSource; |
||||||
|
} |
||||||
|
|
||||||
|
export interface CancelToken { |
||||||
|
promise: Promise<Cancel>; |
||||||
|
reason?: Cancel; |
||||||
|
throwIfRequested(): void; |
||||||
|
} |
||||||
|
|
||||||
|
export interface CancelTokenSource { |
||||||
|
token: CancelToken; |
||||||
|
cancel: Canceler; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosInterceptorManager<V> { |
||||||
|
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number; |
||||||
|
eject(id: number): void; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosInstance { |
||||||
|
(config: AxiosRequestConfig): AxiosPromise; |
||||||
|
(url: string, config?: AxiosRequestConfig): AxiosPromise; |
||||||
|
defaults: AxiosRequestConfig; |
||||||
|
interceptors: { |
||||||
|
request: AxiosInterceptorManager<AxiosRequestConfig>; |
||||||
|
response: AxiosInterceptorManager<AxiosResponse>; |
||||||
|
}; |
||||||
|
getUri(config?: AxiosRequestConfig): string; |
||||||
|
request<T = any, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R>; |
||||||
|
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>; |
||||||
|
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>; |
||||||
|
head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>; |
||||||
|
options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>; |
||||||
|
post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>; |
||||||
|
put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>; |
||||||
|
patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>; |
||||||
|
} |
||||||
|
|
||||||
|
export interface AxiosStatic extends AxiosInstance { |
||||||
|
create(config?: AxiosRequestConfig): AxiosInstance; |
||||||
|
Cancel: CancelStatic; |
||||||
|
CancelToken: CancelTokenStatic; |
||||||
|
isCancel(value: any): boolean; |
||||||
|
all<T>(values: (T | Promise<T>)[]): Promise<T[]>; |
||||||
|
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R; |
||||||
|
isAxiosError(payload: any): payload is AxiosError; |
||||||
|
} |
||||||
|
|
||||||
|
declare const axios: AxiosStatic; |
||||||
|
|
||||||
|
export default axios; |
@ -0,0 +1 @@ |
|||||||
|
module.exports = require('./lib/axios'); |
@ -0,0 +1,37 @@ |
|||||||
|
# axios // adapters |
||||||
|
|
||||||
|
The modules under `adapters/` are modules that handle dispatching a request and settling a returned `Promise` once a response is received. |
||||||
|
|
||||||
|
## Example |
||||||
|
|
||||||
|
```js |
||||||
|
var settle = require('./../core/settle'); |
||||||
|
|
||||||
|
module.exports = function myAdapter(config) { |
||||||
|
// At this point: |
||||||
|
// - config has been merged with defaults |
||||||
|
// - request transformers have already run |
||||||
|
// - request interceptors have already run |
||||||
|
|
||||||
|
// Make the request using config provided |
||||||
|
// Upon response settle the Promise |
||||||
|
|
||||||
|
return new Promise(function(resolve, reject) { |
||||||
|
|
||||||
|
var response = { |
||||||
|
data: responseData, |
||||||
|
status: request.status, |
||||||
|
statusText: request.statusText, |
||||||
|
headers: responseHeaders, |
||||||
|
config: config, |
||||||
|
request: request |
||||||
|
}; |
||||||
|
|
||||||
|
settle(resolve, reject, response); |
||||||
|
|
||||||
|
// From here: |
||||||
|
// - response transformers will run |
||||||
|
// - response interceptors will run |
||||||
|
}); |
||||||
|
} |
||||||
|
``` |
@ -0,0 +1,303 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
var settle = require('./../core/settle'); |
||||||
|
var buildFullPath = require('../core/buildFullPath'); |
||||||
|
var buildURL = require('./../helpers/buildURL'); |
||||||
|
var http = require('http'); |
||||||
|
var https = require('https'); |
||||||
|
var httpFollow = require('follow-redirects').http; |
||||||
|
var httpsFollow = require('follow-redirects').https; |
||||||
|
var url = require('url'); |
||||||
|
var zlib = require('zlib'); |
||||||
|
var pkg = require('./../../package.json'); |
||||||
|
var createError = require('../core/createError'); |
||||||
|
var enhanceError = require('../core/enhanceError'); |
||||||
|
|
||||||
|
var isHttps = /https:?/; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param {http.ClientRequestArgs} options |
||||||
|
* @param {AxiosProxyConfig} proxy |
||||||
|
* @param {string} location |
||||||
|
*/ |
||||||
|
function setProxy(options, proxy, location) { |
||||||
|
options.hostname = proxy.host; |
||||||
|
options.host = proxy.host; |
||||||
|
options.port = proxy.port; |
||||||
|
options.path = location; |
||||||
|
|
||||||
|
// Basic proxy authorization
|
||||||
|
if (proxy.auth) { |
||||||
|
var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64'); |
||||||
|
options.headers['Proxy-Authorization'] = 'Basic ' + base64; |
||||||
|
} |
||||||
|
|
||||||
|
// If a proxy is used, any redirects must also pass through the proxy
|
||||||
|
options.beforeRedirect = function beforeRedirect(redirection) { |
||||||
|
redirection.headers.host = redirection.host; |
||||||
|
setProxy(redirection, proxy, redirection.href); |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/*eslint consistent-return:0*/ |
||||||
|
module.exports = function httpAdapter(config) { |
||||||
|
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) { |
||||||
|
var resolve = function resolve(value) { |
||||||
|
resolvePromise(value); |
||||||
|
}; |
||||||
|
var reject = function reject(value) { |
||||||
|
rejectPromise(value); |
||||||
|
}; |
||||||
|
var data = config.data; |
||||||
|
var headers = config.headers; |
||||||
|
|
||||||
|
// Set User-Agent (required by some servers)
|
||||||
|
// Only set header if it hasn't been set in config
|
||||||
|
// See https://github.com/axios/axios/issues/69
|
||||||
|
if (!headers['User-Agent'] && !headers['user-agent']) { |
||||||
|
headers['User-Agent'] = 'axios/' + pkg.version; |
||||||
|
} |
||||||
|
|
||||||
|
if (data && !utils.isStream(data)) { |
||||||
|
if (Buffer.isBuffer(data)) { |
||||||
|
// Nothing to do...
|
||||||
|
} else if (utils.isArrayBuffer(data)) { |
||||||
|
data = Buffer.from(new Uint8Array(data)); |
||||||
|
} else if (utils.isString(data)) { |
||||||
|
data = Buffer.from(data, 'utf-8'); |
||||||
|
} else { |
||||||
|
return reject(createError( |
||||||
|
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream', |
||||||
|
config |
||||||
|
)); |
||||||
|
} |
||||||
|
|
||||||
|
// Add Content-Length header if data exists
|
||||||
|
headers['Content-Length'] = data.length; |
||||||
|
} |
||||||
|
|
||||||
|
// HTTP basic authentication
|
||||||
|
var auth = undefined; |
||||||
|
if (config.auth) { |
||||||
|
var username = config.auth.username || ''; |
||||||
|
var password = config.auth.password || ''; |
||||||
|
auth = username + ':' + password; |
||||||
|
} |
||||||
|
|
||||||
|
// Parse url
|
||||||
|
var fullPath = buildFullPath(config.baseURL, config.url); |
||||||
|
var parsed = url.parse(fullPath); |
||||||
|
var protocol = parsed.protocol || 'http:'; |
||||||
|
|
||||||
|
if (!auth && parsed.auth) { |
||||||
|
var urlAuth = parsed.auth.split(':'); |
||||||
|
var urlUsername = urlAuth[0] || ''; |
||||||
|
var urlPassword = urlAuth[1] || ''; |
||||||
|
auth = urlUsername + ':' + urlPassword; |
||||||
|
} |
||||||
|
|
||||||
|
if (auth) { |
||||||
|
delete headers.Authorization; |
||||||
|
} |
||||||
|
|
||||||
|
var isHttpsRequest = isHttps.test(protocol); |
||||||
|
var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent; |
||||||
|
|
||||||
|
var options = { |
||||||
|
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''), |
||||||
|
method: config.method.toUpperCase(), |
||||||
|
headers: headers, |
||||||
|
agent: agent, |
||||||
|
agents: { http: config.httpAgent, https: config.httpsAgent }, |
||||||
|
auth: auth |
||||||
|
}; |
||||||
|
|
||||||
|
if (config.socketPath) { |
||||||
|
options.socketPath = config.socketPath; |
||||||
|
} else { |
||||||
|
options.hostname = parsed.hostname; |
||||||
|
options.port = parsed.port; |
||||||
|
} |
||||||
|
|
||||||
|
var proxy = config.proxy; |
||||||
|
if (!proxy && proxy !== false) { |
||||||
|
var proxyEnv = protocol.slice(0, -1) + '_proxy'; |
||||||
|
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()]; |
||||||
|
if (proxyUrl) { |
||||||
|
var parsedProxyUrl = url.parse(proxyUrl); |
||||||
|
var noProxyEnv = process.env.no_proxy || process.env.NO_PROXY; |
||||||
|
var shouldProxy = true; |
||||||
|
|
||||||
|
if (noProxyEnv) { |
||||||
|
var noProxy = noProxyEnv.split(',').map(function trim(s) { |
||||||
|
return s.trim(); |
||||||
|
}); |
||||||
|
|
||||||
|
shouldProxy = !noProxy.some(function proxyMatch(proxyElement) { |
||||||
|
if (!proxyElement) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
if (proxyElement === '*') { |
||||||
|
return true; |
||||||
|
} |
||||||
|
if (proxyElement[0] === '.' && |
||||||
|
parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
return parsed.hostname === proxyElement; |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
if (shouldProxy) { |
||||||
|
proxy = { |
||||||
|
host: parsedProxyUrl.hostname, |
||||||
|
port: parsedProxyUrl.port, |
||||||
|
protocol: parsedProxyUrl.protocol |
||||||
|
}; |
||||||
|
|
||||||
|
if (parsedProxyUrl.auth) { |
||||||
|
var proxyUrlAuth = parsedProxyUrl.auth.split(':'); |
||||||
|
proxy.auth = { |
||||||
|
username: proxyUrlAuth[0], |
||||||
|
password: proxyUrlAuth[1] |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (proxy) { |
||||||
|
options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : ''); |
||||||
|
setProxy(options, proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path); |
||||||
|
} |
||||||
|
|
||||||
|
var transport; |
||||||
|
var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true); |
||||||
|
if (config.transport) { |
||||||
|
transport = config.transport; |
||||||
|
} else if (config.maxRedirects === 0) { |
||||||
|
transport = isHttpsProxy ? https : http; |
||||||
|
} else { |
||||||
|
if (config.maxRedirects) { |
||||||
|
options.maxRedirects = config.maxRedirects; |
||||||
|
} |
||||||
|
transport = isHttpsProxy ? httpsFollow : httpFollow; |
||||||
|
} |
||||||
|
|
||||||
|
if (config.maxBodyLength > -1) { |
||||||
|
options.maxBodyLength = config.maxBodyLength; |
||||||
|
} |
||||||
|
|
||||||
|
// Create the request
|
||||||
|
var req = transport.request(options, function handleResponse(res) { |
||||||
|
if (req.aborted) return; |
||||||
|
|
||||||
|
// uncompress the response body transparently if required
|
||||||
|
var stream = res; |
||||||
|
|
||||||
|
// return the last request in case of redirects
|
||||||
|
var lastRequest = res.req || req; |
||||||
|
|
||||||
|
|
||||||
|
// if no content, is HEAD request or decompress disabled we should not decompress
|
||||||
|
if (res.statusCode !== 204 && lastRequest.method !== 'HEAD' && config.decompress !== false) { |
||||||
|
switch (res.headers['content-encoding']) { |
||||||
|
/*eslint default-case:0*/ |
||||||
|
case 'gzip': |
||||||
|
case 'compress': |
||||||
|
case 'deflate': |
||||||
|
// add the unzipper to the body stream processing pipeline
|
||||||
|
stream = stream.pipe(zlib.createUnzip()); |
||||||
|
|
||||||
|
// remove the content-encoding in order to not confuse downstream operations
|
||||||
|
delete res.headers['content-encoding']; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var response = { |
||||||
|
status: res.statusCode, |
||||||
|
statusText: res.statusMessage, |
||||||
|
headers: res.headers, |
||||||
|
config: config, |
||||||
|
request: lastRequest |
||||||
|
}; |
||||||
|
|
||||||
|
if (config.responseType === 'stream') { |
||||||
|
response.data = stream; |
||||||
|
settle(resolve, reject, response); |
||||||
|
} else { |
||||||
|
var responseBuffer = []; |
||||||
|
stream.on('data', function handleStreamData(chunk) { |
||||||
|
responseBuffer.push(chunk); |
||||||
|
|
||||||
|
// make sure the content length is not over the maxContentLength if specified
|
||||||
|
if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) { |
||||||
|
stream.destroy(); |
||||||
|
reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded', |
||||||
|
config, null, lastRequest)); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
stream.on('error', function handleStreamError(err) { |
||||||
|
if (req.aborted) return; |
||||||
|
reject(enhanceError(err, config, null, lastRequest)); |
||||||
|
}); |
||||||
|
|
||||||
|
stream.on('end', function handleStreamEnd() { |
||||||
|
var responseData = Buffer.concat(responseBuffer); |
||||||
|
if (config.responseType !== 'arraybuffer') { |
||||||
|
responseData = responseData.toString(config.responseEncoding); |
||||||
|
if (!config.responseEncoding || config.responseEncoding === 'utf8') { |
||||||
|
responseData = utils.stripBOM(responseData); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
response.data = responseData; |
||||||
|
settle(resolve, reject, response); |
||||||
|
}); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
// Handle errors
|
||||||
|
req.on('error', function handleRequestError(err) { |
||||||
|
if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') return; |
||||||
|
reject(enhanceError(err, config, null, req)); |
||||||
|
}); |
||||||
|
|
||||||
|
// Handle request timeout
|
||||||
|
if (config.timeout) { |
||||||
|
// Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
|
||||||
|
// And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
|
||||||
|
// At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
|
||||||
|
// And then these socket which be hang up will devoring CPU little by little.
|
||||||
|
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
||||||
|
req.setTimeout(config.timeout, function handleRequestTimeout() { |
||||||
|
req.abort(); |
||||||
|
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req)); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
if (config.cancelToken) { |
||||||
|
// Handle cancellation
|
||||||
|
config.cancelToken.promise.then(function onCanceled(cancel) { |
||||||
|
if (req.aborted) return; |
||||||
|
|
||||||
|
req.abort(); |
||||||
|
reject(cancel); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
// Send the request
|
||||||
|
if (utils.isStream(data)) { |
||||||
|
data.on('error', function handleStreamError(err) { |
||||||
|
reject(enhanceError(err, config, null, req)); |
||||||
|
}).pipe(req); |
||||||
|
} else { |
||||||
|
req.end(data); |
||||||
|
} |
||||||
|
}); |
||||||
|
}; |
@ -0,0 +1,179 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
var settle = require('./../core/settle'); |
||||||
|
var cookies = require('./../helpers/cookies'); |
||||||
|
var buildURL = require('./../helpers/buildURL'); |
||||||
|
var buildFullPath = require('../core/buildFullPath'); |
||||||
|
var parseHeaders = require('./../helpers/parseHeaders'); |
||||||
|
var isURLSameOrigin = require('./../helpers/isURLSameOrigin'); |
||||||
|
var createError = require('../core/createError'); |
||||||
|
|
||||||
|
module.exports = function xhrAdapter(config) { |
||||||
|
return new Promise(function dispatchXhrRequest(resolve, reject) { |
||||||
|
var requestData = config.data; |
||||||
|
var requestHeaders = config.headers; |
||||||
|
|
||||||
|
if (utils.isFormData(requestData)) { |
||||||
|
delete requestHeaders['Content-Type']; // Let the browser set it
|
||||||
|
} |
||||||
|
|
||||||
|
var request = new XMLHttpRequest(); |
||||||
|
|
||||||
|
// HTTP basic authentication
|
||||||
|
if (config.auth) { |
||||||
|
var username = config.auth.username || ''; |
||||||
|
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : ''; |
||||||
|
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password); |
||||||
|
} |
||||||
|
|
||||||
|
var fullPath = buildFullPath(config.baseURL, config.url); |
||||||
|
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true); |
||||||
|
|
||||||
|
// Set the request timeout in MS
|
||||||
|
request.timeout = config.timeout; |
||||||
|
|
||||||
|
// Listen for ready state
|
||||||
|
request.onreadystatechange = function handleLoad() { |
||||||
|
if (!request || request.readyState !== 4) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// The request errored out and we didn't get a response, this will be
|
||||||
|
// handled by onerror instead
|
||||||
|
// With one exception: request that using file: protocol, most browsers
|
||||||
|
// will return status as 0 even though it's a successful request
|
||||||
|
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// Prepare the response
|
||||||
|
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null; |
||||||
|
var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response; |
||||||
|
var response = { |
||||||
|
data: responseData, |
||||||
|
status: request.status, |
||||||
|
statusText: request.statusText, |
||||||
|
headers: responseHeaders, |
||||||
|
config: config, |
||||||
|
request: request |
||||||
|
}; |
||||||
|
|
||||||
|
settle(resolve, reject, response); |
||||||
|
|
||||||
|
// Clean up request
|
||||||
|
request = null; |
||||||
|
}; |
||||||
|
|
||||||
|
// Handle browser request cancellation (as opposed to a manual cancellation)
|
||||||
|
request.onabort = function handleAbort() { |
||||||
|
if (!request) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
reject(createError('Request aborted', config, 'ECONNABORTED', request)); |
||||||
|
|
||||||
|
// Clean up request
|
||||||
|
request = null; |
||||||
|
}; |
||||||
|
|
||||||
|
// Handle low level network errors
|
||||||
|
request.onerror = function handleError() { |
||||||
|
// Real errors are hidden from us by the browser
|
||||||
|
// onerror should only fire if it's a network error
|
||||||
|
reject(createError('Network Error', config, null, request)); |
||||||
|
|
||||||
|
// Clean up request
|
||||||
|
request = null; |
||||||
|
}; |
||||||
|
|
||||||
|
// Handle timeout
|
||||||
|
request.ontimeout = function handleTimeout() { |
||||||
|
var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded'; |
||||||
|
if (config.timeoutErrorMessage) { |
||||||
|
timeoutErrorMessage = config.timeoutErrorMessage; |
||||||
|
} |
||||||
|
reject(createError(timeoutErrorMessage, config, 'ECONNABORTED', |
||||||
|
request)); |
||||||
|
|
||||||
|
// Clean up request
|
||||||
|
request = null; |
||||||
|
}; |
||||||
|
|
||||||
|
// Add xsrf header
|
||||||
|
// This is only done if running in a standard browser environment.
|
||||||
|
// Specifically not if we're in a web worker, or react-native.
|
||||||
|
if (utils.isStandardBrowserEnv()) { |
||||||
|
// Add xsrf header
|
||||||
|
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ? |
||||||
|
cookies.read(config.xsrfCookieName) : |
||||||
|
undefined; |
||||||
|
|
||||||
|
if (xsrfValue) { |
||||||
|
requestHeaders[config.xsrfHeaderName] = xsrfValue; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Add headers to the request
|
||||||
|
if ('setRequestHeader' in request) { |
||||||
|
utils.forEach(requestHeaders, function setRequestHeader(val, key) { |
||||||
|
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') { |
||||||
|
// Remove Content-Type if data is undefined
|
||||||
|
delete requestHeaders[key]; |
||||||
|
} else { |
||||||
|
// Otherwise add header to the request
|
||||||
|
request.setRequestHeader(key, val); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
// Add withCredentials to request if needed
|
||||||
|
if (!utils.isUndefined(config.withCredentials)) { |
||||||
|
request.withCredentials = !!config.withCredentials; |
||||||
|
} |
||||||
|
|
||||||
|
// Add responseType to request if needed
|
||||||
|
if (config.responseType) { |
||||||
|
try { |
||||||
|
request.responseType = config.responseType; |
||||||
|
} catch (e) { |
||||||
|
// Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
|
||||||
|
// But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
|
||||||
|
if (config.responseType !== 'json') { |
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Handle progress if needed
|
||||||
|
if (typeof config.onDownloadProgress === 'function') { |
||||||
|
request.addEventListener('progress', config.onDownloadProgress); |
||||||
|
} |
||||||
|
|
||||||
|
// Not all browsers support upload events
|
||||||
|
if (typeof config.onUploadProgress === 'function' && request.upload) { |
||||||
|
request.upload.addEventListener('progress', config.onUploadProgress); |
||||||
|
} |
||||||
|
|
||||||
|
if (config.cancelToken) { |
||||||
|
// Handle cancellation
|
||||||
|
config.cancelToken.promise.then(function onCanceled(cancel) { |
||||||
|
if (!request) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
request.abort(); |
||||||
|
reject(cancel); |
||||||
|
// Clean up request
|
||||||
|
request = null; |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
if (!requestData) { |
||||||
|
requestData = null; |
||||||
|
} |
||||||
|
|
||||||
|
// Send the request
|
||||||
|
request.send(requestData); |
||||||
|
}); |
||||||
|
}; |
@ -0,0 +1,56 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./utils'); |
||||||
|
var bind = require('./helpers/bind'); |
||||||
|
var Axios = require('./core/Axios'); |
||||||
|
var mergeConfig = require('./core/mergeConfig'); |
||||||
|
var defaults = require('./defaults'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Create an instance of Axios |
||||||
|
* |
||||||
|
* @param {Object} defaultConfig The default config for the instance |
||||||
|
* @return {Axios} A new instance of Axios |
||||||
|
*/ |
||||||
|
function createInstance(defaultConfig) { |
||||||
|
var context = new Axios(defaultConfig); |
||||||
|
var instance = bind(Axios.prototype.request, context); |
||||||
|
|
||||||
|
// Copy axios.prototype to instance
|
||||||
|
utils.extend(instance, Axios.prototype, context); |
||||||
|
|
||||||
|
// Copy context to instance
|
||||||
|
utils.extend(instance, context); |
||||||
|
|
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
// Create the default instance to be exported
|
||||||
|
var axios = createInstance(defaults); |
||||||
|
|
||||||
|
// Expose Axios class to allow class inheritance
|
||||||
|
axios.Axios = Axios; |
||||||
|
|
||||||
|
// Factory for creating new instances
|
||||||
|
axios.create = function create(instanceConfig) { |
||||||
|
return createInstance(mergeConfig(axios.defaults, instanceConfig)); |
||||||
|
}; |
||||||
|
|
||||||
|
// Expose Cancel & CancelToken
|
||||||
|
axios.Cancel = require('./cancel/Cancel'); |
||||||
|
axios.CancelToken = require('./cancel/CancelToken'); |
||||||
|
axios.isCancel = require('./cancel/isCancel'); |
||||||
|
|
||||||
|
// Expose all/spread
|
||||||
|
axios.all = function all(promises) { |
||||||
|
return Promise.all(promises); |
||||||
|
}; |
||||||
|
axios.spread = require('./helpers/spread'); |
||||||
|
|
||||||
|
// Expose isAxiosError
|
||||||
|
axios.isAxiosError = require('./helpers/isAxiosError'); |
||||||
|
|
||||||
|
module.exports = axios; |
||||||
|
|
||||||
|
// Allow use of default import syntax in TypeScript
|
||||||
|
module.exports.default = axios; |
@ -0,0 +1,19 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
/** |
||||||
|
* A `Cancel` is an object that is thrown when an operation is canceled. |
||||||
|
* |
||||||
|
* @class |
||||||
|
* @param {string=} message The message. |
||||||
|
*/ |
||||||
|
function Cancel(message) { |
||||||
|
this.message = message; |
||||||
|
} |
||||||
|
|
||||||
|
Cancel.prototype.toString = function toString() { |
||||||
|
return 'Cancel' + (this.message ? ': ' + this.message : ''); |
||||||
|
}; |
||||||
|
|
||||||
|
Cancel.prototype.__CANCEL__ = true; |
||||||
|
|
||||||
|
module.exports = Cancel; |
@ -0,0 +1,57 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var Cancel = require('./Cancel'); |
||||||
|
|
||||||
|
/** |
||||||
|
* A `CancelToken` is an object that can be used to request cancellation of an operation. |
||||||
|
* |
||||||
|
* @class |
||||||
|
* @param {Function} executor The executor function. |
||||||
|
*/ |
||||||
|
function CancelToken(executor) { |
||||||
|
if (typeof executor !== 'function') { |
||||||
|
throw new TypeError('executor must be a function.'); |
||||||
|
} |
||||||
|
|
||||||
|
var resolvePromise; |
||||||
|
this.promise = new Promise(function promiseExecutor(resolve) { |
||||||
|
resolvePromise = resolve; |
||||||
|
}); |
||||||
|
|
||||||
|
var token = this; |
||||||
|
executor(function cancel(message) { |
||||||
|
if (token.reason) { |
||||||
|
// Cancellation has already been requested
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
token.reason = new Cancel(message); |
||||||
|
resolvePromise(token.reason); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Throws a `Cancel` if cancellation has been requested. |
||||||
|
*/ |
||||||
|
CancelToken.prototype.throwIfRequested = function throwIfRequested() { |
||||||
|
if (this.reason) { |
||||||
|
throw this.reason; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns an object that contains a new `CancelToken` and a function that, when called, |
||||||
|
* cancels the `CancelToken`. |
||||||
|
*/ |
||||||
|
CancelToken.source = function source() { |
||||||
|
var cancel; |
||||||
|
var token = new CancelToken(function executor(c) { |
||||||
|
cancel = c; |
||||||
|
}); |
||||||
|
return { |
||||||
|
token: token, |
||||||
|
cancel: cancel |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
module.exports = CancelToken; |
@ -0,0 +1,5 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = function isCancel(value) { |
||||||
|
return !!(value && value.__CANCEL__); |
||||||
|
}; |
@ -0,0 +1,95 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
var buildURL = require('../helpers/buildURL'); |
||||||
|
var InterceptorManager = require('./InterceptorManager'); |
||||||
|
var dispatchRequest = require('./dispatchRequest'); |
||||||
|
var mergeConfig = require('./mergeConfig'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a new instance of Axios |
||||||
|
* |
||||||
|
* @param {Object} instanceConfig The default config for the instance |
||||||
|
*/ |
||||||
|
function Axios(instanceConfig) { |
||||||
|
this.defaults = instanceConfig; |
||||||
|
this.interceptors = { |
||||||
|
request: new InterceptorManager(), |
||||||
|
response: new InterceptorManager() |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Dispatch a request |
||||||
|
* |
||||||
|
* @param {Object} config The config specific for this request (merged with this.defaults) |
||||||
|
*/ |
||||||
|
Axios.prototype.request = function request(config) { |
||||||
|
/*eslint no-param-reassign:0*/ |
||||||
|
// Allow for axios('example/url'[, config]) a la fetch API
|
||||||
|
if (typeof config === 'string') { |
||||||
|
config = arguments[1] || {}; |
||||||
|
config.url = arguments[0]; |
||||||
|
} else { |
||||||
|
config = config || {}; |
||||||
|
} |
||||||
|
|
||||||
|
config = mergeConfig(this.defaults, config); |
||||||
|
|
||||||
|
// Set config.method
|
||||||
|
if (config.method) { |
||||||
|
config.method = config.method.toLowerCase(); |
||||||
|
} else if (this.defaults.method) { |
||||||
|
config.method = this.defaults.method.toLowerCase(); |
||||||
|
} else { |
||||||
|
config.method = 'get'; |
||||||
|
} |
||||||
|
|
||||||
|
// Hook up interceptors middleware
|
||||||
|
var chain = [dispatchRequest, undefined]; |
||||||
|
var promise = Promise.resolve(config); |
||||||
|
|
||||||
|
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) { |
||||||
|
chain.unshift(interceptor.fulfilled, interceptor.rejected); |
||||||
|
}); |
||||||
|
|
||||||
|
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) { |
||||||
|
chain.push(interceptor.fulfilled, interceptor.rejected); |
||||||
|
}); |
||||||
|
|
||||||
|
while (chain.length) { |
||||||
|
promise = promise.then(chain.shift(), chain.shift()); |
||||||
|
} |
||||||
|
|
||||||
|
return promise; |
||||||
|
}; |
||||||
|
|
||||||
|
Axios.prototype.getUri = function getUri(config) { |
||||||
|
config = mergeConfig(this.defaults, config); |
||||||
|
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, ''); |
||||||
|
}; |
||||||
|
|
||||||
|
// Provide aliases for supported request methods
|
||||||
|
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) { |
||||||
|
/*eslint func-names:0*/ |
||||||
|
Axios.prototype[method] = function(url, config) { |
||||||
|
return this.request(mergeConfig(config || {}, { |
||||||
|
method: method, |
||||||
|
url: url, |
||||||
|
data: (config || {}).data |
||||||
|
})); |
||||||
|
}; |
||||||
|
}); |
||||||
|
|
||||||
|
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) { |
||||||
|
/*eslint func-names:0*/ |
||||||
|
Axios.prototype[method] = function(url, data, config) { |
||||||
|
return this.request(mergeConfig(config || {}, { |
||||||
|
method: method, |
||||||
|
url: url, |
||||||
|
data: data |
||||||
|
})); |
||||||
|
}; |
||||||
|
}); |
||||||
|
|
||||||
|
module.exports = Axios; |
@ -0,0 +1,52 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
|
||||||
|
function InterceptorManager() { |
||||||
|
this.handlers = []; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Add a new interceptor to the stack |
||||||
|
* |
||||||
|
* @param {Function} fulfilled The function to handle `then` for a `Promise` |
||||||
|
* @param {Function} rejected The function to handle `reject` for a `Promise` |
||||||
|
* |
||||||
|
* @return {Number} An ID used to remove interceptor later |
||||||
|
*/ |
||||||
|
InterceptorManager.prototype.use = function use(fulfilled, rejected) { |
||||||
|
this.handlers.push({ |
||||||
|
fulfilled: fulfilled, |
||||||
|
rejected: rejected |
||||||
|
}); |
||||||
|
return this.handlers.length - 1; |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove an interceptor from the stack |
||||||
|
* |
||||||
|
* @param {Number} id The ID that was returned by `use` |
||||||
|
*/ |
||||||
|
InterceptorManager.prototype.eject = function eject(id) { |
||||||
|
if (this.handlers[id]) { |
||||||
|
this.handlers[id] = null; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Iterate over all the registered interceptors |
||||||
|
* |
||||||
|
* This method is particularly useful for skipping over any |
||||||
|
* interceptors that may have become `null` calling `eject`. |
||||||
|
* |
||||||
|
* @param {Function} fn The function to call for each interceptor |
||||||
|
*/ |
||||||
|
InterceptorManager.prototype.forEach = function forEach(fn) { |
||||||
|
utils.forEach(this.handlers, function forEachHandler(h) { |
||||||
|
if (h !== null) { |
||||||
|
fn(h); |
||||||
|
} |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
module.exports = InterceptorManager; |
@ -0,0 +1,7 @@ |
|||||||
|
# axios // core |
||||||
|
|
||||||
|
The modules found in `core/` should be modules that are specific to the domain logic of axios. These modules would most likely not make sense to be consumed outside of the axios module, as their logic is too specific. Some examples of core modules are: |
||||||
|
|
||||||
|
- Dispatching requests |
||||||
|
- Managing interceptors |
||||||
|
- Handling config |
@ -0,0 +1,20 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var isAbsoluteURL = require('../helpers/isAbsoluteURL'); |
||||||
|
var combineURLs = require('../helpers/combineURLs'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a new URL by combining the baseURL with the requestedURL, |
||||||
|
* only when the requestedURL is not already an absolute URL. |
||||||
|
* If the requestURL is absolute, this function returns the requestedURL untouched. |
||||||
|
* |
||||||
|
* @param {string} baseURL The base URL |
||||||
|
* @param {string} requestedURL Absolute or relative URL to combine |
||||||
|
* @returns {string} The combined full path |
||||||
|
*/ |
||||||
|
module.exports = function buildFullPath(baseURL, requestedURL) { |
||||||
|
if (baseURL && !isAbsoluteURL(requestedURL)) { |
||||||
|
return combineURLs(baseURL, requestedURL); |
||||||
|
} |
||||||
|
return requestedURL; |
||||||
|
}; |
@ -0,0 +1,18 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var enhanceError = require('./enhanceError'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Create an Error with the specified message, config, error code, request and response. |
||||||
|
* |
||||||
|
* @param {string} message The error message. |
||||||
|
* @param {Object} config The config. |
||||||
|
* @param {string} [code] The error code (for example, 'ECONNABORTED'). |
||||||
|
* @param {Object} [request] The request. |
||||||
|
* @param {Object} [response] The response. |
||||||
|
* @returns {Error} The created error. |
||||||
|
*/ |
||||||
|
module.exports = function createError(message, config, code, request, response) { |
||||||
|
var error = new Error(message); |
||||||
|
return enhanceError(error, config, code, request, response); |
||||||
|
}; |
@ -0,0 +1,79 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
var transformData = require('./transformData'); |
||||||
|
var isCancel = require('../cancel/isCancel'); |
||||||
|
var defaults = require('../defaults'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Throws a `Cancel` if cancellation has been requested. |
||||||
|
*/ |
||||||
|
function throwIfCancellationRequested(config) { |
||||||
|
if (config.cancelToken) { |
||||||
|
config.cancelToken.throwIfRequested(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Dispatch a request to the server using the configured adapter. |
||||||
|
* |
||||||
|
* @param {object} config The config that is to be used for the request |
||||||
|
* @returns {Promise} The Promise to be fulfilled |
||||||
|
*/ |
||||||
|
module.exports = function dispatchRequest(config) { |
||||||
|
throwIfCancellationRequested(config); |
||||||
|
|
||||||
|
// Ensure headers exist
|
||||||
|
config.headers = config.headers || {}; |
||||||
|
|
||||||
|
// Transform request data
|
||||||
|
config.data = transformData( |
||||||
|
config.data, |
||||||
|
config.headers, |
||||||
|
config.transformRequest |
||||||
|
); |
||||||
|
|
||||||
|
// Flatten headers
|
||||||
|
config.headers = utils.merge( |
||||||
|
config.headers.common || {}, |
||||||
|
config.headers[config.method] || {}, |
||||||
|
config.headers |
||||||
|
); |
||||||
|
|
||||||
|
utils.forEach( |
||||||
|
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], |
||||||
|
function cleanHeaderConfig(method) { |
||||||
|
delete config.headers[method]; |
||||||
|
} |
||||||
|
); |
||||||
|
|
||||||
|
var adapter = config.adapter || defaults.adapter; |
||||||
|
|
||||||
|
return adapter(config).then(function onAdapterResolution(response) { |
||||||
|
throwIfCancellationRequested(config); |
||||||
|
|
||||||
|
// Transform response data
|
||||||
|
response.data = transformData( |
||||||
|
response.data, |
||||||
|
response.headers, |
||||||
|
config.transformResponse |
||||||
|
); |
||||||
|
|
||||||
|
return response; |
||||||
|
}, function onAdapterRejection(reason) { |
||||||
|
if (!isCancel(reason)) { |
||||||
|
throwIfCancellationRequested(config); |
||||||
|
|
||||||
|
// Transform response data
|
||||||
|
if (reason && reason.response) { |
||||||
|
reason.response.data = transformData( |
||||||
|
reason.response.data, |
||||||
|
reason.response.headers, |
||||||
|
config.transformResponse |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return Promise.reject(reason); |
||||||
|
}); |
||||||
|
}; |
@ -0,0 +1,42 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Update an Error with the specified config, error code, and response. |
||||||
|
* |
||||||
|
* @param {Error} error The error to update. |
||||||
|
* @param {Object} config The config. |
||||||
|
* @param {string} [code] The error code (for example, 'ECONNABORTED'). |
||||||
|
* @param {Object} [request] The request. |
||||||
|
* @param {Object} [response] The response. |
||||||
|
* @returns {Error} The error. |
||||||
|
*/ |
||||||
|
module.exports = function enhanceError(error, config, code, request, response) { |
||||||
|
error.config = config; |
||||||
|
if (code) { |
||||||
|
error.code = code; |
||||||
|
} |
||||||
|
|
||||||
|
error.request = request; |
||||||
|
error.response = response; |
||||||
|
error.isAxiosError = true; |
||||||
|
|
||||||
|
error.toJSON = function toJSON() { |
||||||
|
return { |
||||||
|
// Standard
|
||||||
|
message: this.message, |
||||||
|
name: this.name, |
||||||
|
// Microsoft
|
||||||
|
description: this.description, |
||||||
|
number: this.number, |
||||||
|
// Mozilla
|
||||||
|
fileName: this.fileName, |
||||||
|
lineNumber: this.lineNumber, |
||||||
|
columnNumber: this.columnNumber, |
||||||
|
stack: this.stack, |
||||||
|
// Axios
|
||||||
|
config: this.config, |
||||||
|
code: this.code |
||||||
|
}; |
||||||
|
}; |
||||||
|
return error; |
||||||
|
}; |
@ -0,0 +1,87 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('../utils'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Config-specific merge-function which creates a new config-object |
||||||
|
* by merging two configuration objects together. |
||||||
|
* |
||||||
|
* @param {Object} config1 |
||||||
|
* @param {Object} config2 |
||||||
|
* @returns {Object} New object resulting from merging config2 to config1 |
||||||
|
*/ |
||||||
|
module.exports = function mergeConfig(config1, config2) { |
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
config2 = config2 || {}; |
||||||
|
var config = {}; |
||||||
|
|
||||||
|
var valueFromConfig2Keys = ['url', 'method', 'data']; |
||||||
|
var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params']; |
||||||
|
var defaultToConfig2Keys = [ |
||||||
|
'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer', |
||||||
|
'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName', |
||||||
|
'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress', |
||||||
|
'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent', |
||||||
|
'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding' |
||||||
|
]; |
||||||
|
var directMergeKeys = ['validateStatus']; |
||||||
|
|
||||||
|
function getMergedValue(target, source) { |
||||||
|
if (utils.isPlainObject(target) && utils.isPlainObject(source)) { |
||||||
|
return utils.merge(target, source); |
||||||
|
} else if (utils.isPlainObject(source)) { |
||||||
|
return utils.merge({}, source); |
||||||
|
} else if (utils.isArray(source)) { |
||||||
|
return source.slice(); |
||||||
|
} |
||||||
|
return source; |
||||||
|
} |
||||||
|
|
||||||
|
function mergeDeepProperties(prop) { |
||||||
|
if (!utils.isUndefined(config2[prop])) { |
||||||
|
config[prop] = getMergedValue(config1[prop], config2[prop]); |
||||||
|
} else if (!utils.isUndefined(config1[prop])) { |
||||||
|
config[prop] = getMergedValue(undefined, config1[prop]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) { |
||||||
|
if (!utils.isUndefined(config2[prop])) { |
||||||
|
config[prop] = getMergedValue(undefined, config2[prop]); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties); |
||||||
|
|
||||||
|
utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) { |
||||||
|
if (!utils.isUndefined(config2[prop])) { |
||||||
|
config[prop] = getMergedValue(undefined, config2[prop]); |
||||||
|
} else if (!utils.isUndefined(config1[prop])) { |
||||||
|
config[prop] = getMergedValue(undefined, config1[prop]); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
utils.forEach(directMergeKeys, function merge(prop) { |
||||||
|
if (prop in config2) { |
||||||
|
config[prop] = getMergedValue(config1[prop], config2[prop]); |
||||||
|
} else if (prop in config1) { |
||||||
|
config[prop] = getMergedValue(undefined, config1[prop]); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
var axiosKeys = valueFromConfig2Keys |
||||||
|
.concat(mergeDeepPropertiesKeys) |
||||||
|
.concat(defaultToConfig2Keys) |
||||||
|
.concat(directMergeKeys); |
||||||
|
|
||||||
|
var otherKeys = Object |
||||||
|
.keys(config1) |
||||||
|
.concat(Object.keys(config2)) |
||||||
|
.filter(function filterAxiosKeys(key) { |
||||||
|
return axiosKeys.indexOf(key) === -1; |
||||||
|
}); |
||||||
|
|
||||||
|
utils.forEach(otherKeys, mergeDeepProperties); |
||||||
|
|
||||||
|
return config; |
||||||
|
}; |
@ -0,0 +1,25 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var createError = require('./createError'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Resolve or reject a Promise based on response status. |
||||||
|
* |
||||||
|
* @param {Function} resolve A function that resolves the promise. |
||||||
|
* @param {Function} reject A function that rejects the promise. |
||||||
|
* @param {object} response The response. |
||||||
|
*/ |
||||||
|
module.exports = function settle(resolve, reject, response) { |
||||||
|
var validateStatus = response.config.validateStatus; |
||||||
|
if (!response.status || !validateStatus || validateStatus(response.status)) { |
||||||
|
resolve(response); |
||||||
|
} else { |
||||||
|
reject(createError( |
||||||
|
'Request failed with status code ' + response.status, |
||||||
|
response.config, |
||||||
|
null, |
||||||
|
response.request, |
||||||
|
response |
||||||
|
)); |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,20 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Transform the data for a request or a response |
||||||
|
* |
||||||
|
* @param {Object|String} data The data to be transformed |
||||||
|
* @param {Array} headers The headers for the request or response |
||||||
|
* @param {Array|Function} fns A single function or Array of functions |
||||||
|
* @returns {*} The resulting transformed data |
||||||
|
*/ |
||||||
|
module.exports = function transformData(data, headers, fns) { |
||||||
|
/*eslint no-param-reassign:0*/ |
||||||
|
utils.forEach(fns, function transform(fn) { |
||||||
|
data = fn(data, headers); |
||||||
|
}); |
||||||
|
|
||||||
|
return data; |
||||||
|
}; |
@ -0,0 +1,98 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./utils'); |
||||||
|
var normalizeHeaderName = require('./helpers/normalizeHeaderName'); |
||||||
|
|
||||||
|
var DEFAULT_CONTENT_TYPE = { |
||||||
|
'Content-Type': 'application/x-www-form-urlencoded' |
||||||
|
}; |
||||||
|
|
||||||
|
function setContentTypeIfUnset(headers, value) { |
||||||
|
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) { |
||||||
|
headers['Content-Type'] = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function getDefaultAdapter() { |
||||||
|
var adapter; |
||||||
|
if (typeof XMLHttpRequest !== 'undefined') { |
||||||
|
// For browsers use XHR adapter
|
||||||
|
adapter = require('./adapters/xhr'); |
||||||
|
} else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') { |
||||||
|
// For node use HTTP adapter
|
||||||
|
adapter = require('./adapters/http'); |
||||||
|
} |
||||||
|
return adapter; |
||||||
|
} |
||||||
|
|
||||||
|
var defaults = { |
||||||
|
adapter: getDefaultAdapter(), |
||||||
|
|
||||||
|
transformRequest: [function transformRequest(data, headers) { |
||||||
|
normalizeHeaderName(headers, 'Accept'); |
||||||
|
normalizeHeaderName(headers, 'Content-Type'); |
||||||
|
if (utils.isFormData(data) || |
||||||
|
utils.isArrayBuffer(data) || |
||||||
|
utils.isBuffer(data) || |
||||||
|
utils.isStream(data) || |
||||||
|
utils.isFile(data) || |
||||||
|
utils.isBlob(data) |
||||||
|
) { |
||||||
|
return data; |
||||||
|
} |
||||||
|
if (utils.isArrayBufferView(data)) { |
||||||
|
return data.buffer; |
||||||
|
} |
||||||
|
if (utils.isURLSearchParams(data)) { |
||||||
|
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8'); |
||||||
|
return data.toString(); |
||||||
|
} |
||||||
|
if (utils.isObject(data)) { |
||||||
|
setContentTypeIfUnset(headers, 'application/json;charset=utf-8'); |
||||||
|
return JSON.stringify(data); |
||||||
|
} |
||||||
|
return data; |
||||||
|
}], |
||||||
|
|
||||||
|
transformResponse: [function transformResponse(data) { |
||||||
|
/*eslint no-param-reassign:0*/ |
||||||
|
if (typeof data === 'string') { |
||||||
|
try { |
||||||
|
data = JSON.parse(data); |
||||||
|
} catch (e) { /* Ignore */ } |
||||||
|
} |
||||||
|
return data; |
||||||
|
}], |
||||||
|
|
||||||
|
/** |
||||||
|
* A timeout in milliseconds to abort a request. If set to 0 (default) a |
||||||
|
* timeout is not created. |
||||||
|
*/ |
||||||
|
timeout: 0, |
||||||
|
|
||||||
|
xsrfCookieName: 'XSRF-TOKEN', |
||||||
|
xsrfHeaderName: 'X-XSRF-TOKEN', |
||||||
|
|
||||||
|
maxContentLength: -1, |
||||||
|
maxBodyLength: -1, |
||||||
|
|
||||||
|
validateStatus: function validateStatus(status) { |
||||||
|
return status >= 200 && status < 300; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
defaults.headers = { |
||||||
|
common: { |
||||||
|
'Accept': 'application/json, text/plain, */*' |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) { |
||||||
|
defaults.headers[method] = {}; |
||||||
|
}); |
||||||
|
|
||||||
|
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) { |
||||||
|
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE); |
||||||
|
}); |
||||||
|
|
||||||
|
module.exports = defaults; |
@ -0,0 +1,7 @@ |
|||||||
|
# axios // helpers |
||||||
|
|
||||||
|
The modules found in `helpers/` should be generic modules that are _not_ specific to the domain logic of axios. These modules could theoretically be published to npm on their own and consumed by other modules or apps. Some examples of generic modules are things like: |
||||||
|
|
||||||
|
- Browser polyfills |
||||||
|
- Managing cookies |
||||||
|
- Parsing HTTP headers |
@ -0,0 +1,11 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
module.exports = function bind(fn, thisArg) { |
||||||
|
return function wrap() { |
||||||
|
var args = new Array(arguments.length); |
||||||
|
for (var i = 0; i < args.length; i++) { |
||||||
|
args[i] = arguments[i]; |
||||||
|
} |
||||||
|
return fn.apply(thisArg, args); |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,70 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
|
||||||
|
function encode(val) { |
||||||
|
return encodeURIComponent(val). |
||||||
|
replace(/%3A/gi, ':'). |
||||||
|
replace(/%24/g, '$'). |
||||||
|
replace(/%2C/gi, ','). |
||||||
|
replace(/%20/g, '+'). |
||||||
|
replace(/%5B/gi, '['). |
||||||
|
replace(/%5D/gi, ']'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Build a URL by appending params to the end |
||||||
|
* |
||||||
|
* @param {string} url The base of the url (e.g., http://www.google.com)
|
||||||
|
* @param {object} [params] The params to be appended |
||||||
|
* @returns {string} The formatted url |
||||||
|
*/ |
||||||
|
module.exports = function buildURL(url, params, paramsSerializer) { |
||||||
|
/*eslint no-param-reassign:0*/ |
||||||
|
if (!params) { |
||||||
|
return url; |
||||||
|
} |
||||||
|
|
||||||
|
var serializedParams; |
||||||
|
if (paramsSerializer) { |
||||||
|
serializedParams = paramsSerializer(params); |
||||||
|
} else if (utils.isURLSearchParams(params)) { |
||||||
|
serializedParams = params.toString(); |
||||||
|
} else { |
||||||
|
var parts = []; |
||||||
|
|
||||||
|
utils.forEach(params, function serialize(val, key) { |
||||||
|
if (val === null || typeof val === 'undefined') { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (utils.isArray(val)) { |
||||||
|
key = key + '[]'; |
||||||
|
} else { |
||||||
|
val = [val]; |
||||||
|
} |
||||||
|
|
||||||
|
utils.forEach(val, function parseValue(v) { |
||||||
|
if (utils.isDate(v)) { |
||||||
|
v = v.toISOString(); |
||||||
|
} else if (utils.isObject(v)) { |
||||||
|
v = JSON.stringify(v); |
||||||
|
} |
||||||
|
parts.push(encode(key) + '=' + encode(v)); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
serializedParams = parts.join('&'); |
||||||
|
} |
||||||
|
|
||||||
|
if (serializedParams) { |
||||||
|
var hashmarkIndex = url.indexOf('#'); |
||||||
|
if (hashmarkIndex !== -1) { |
||||||
|
url = url.slice(0, hashmarkIndex); |
||||||
|
} |
||||||
|
|
||||||
|
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; |
||||||
|
} |
||||||
|
|
||||||
|
return url; |
||||||
|
}; |
@ -0,0 +1,14 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a new URL by combining the specified URLs |
||||||
|
* |
||||||
|
* @param {string} baseURL The base URL |
||||||
|
* @param {string} relativeURL The relative URL |
||||||
|
* @returns {string} The combined URL |
||||||
|
*/ |
||||||
|
module.exports = function combineURLs(baseURL, relativeURL) { |
||||||
|
return relativeURL |
||||||
|
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') |
||||||
|
: baseURL; |
||||||
|
}; |
@ -0,0 +1,53 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
|
||||||
|
module.exports = ( |
||||||
|
utils.isStandardBrowserEnv() ? |
||||||
|
|
||||||
|
// Standard browser envs support document.cookie
|
||||||
|
(function standardBrowserEnv() { |
||||||
|
return { |
||||||
|
write: function write(name, value, expires, path, domain, secure) { |
||||||
|
var cookie = []; |
||||||
|
cookie.push(name + '=' + encodeURIComponent(value)); |
||||||
|
|
||||||
|
if (utils.isNumber(expires)) { |
||||||
|
cookie.push('expires=' + new Date(expires).toGMTString()); |
||||||
|
} |
||||||
|
|
||||||
|
if (utils.isString(path)) { |
||||||
|
cookie.push('path=' + path); |
||||||
|
} |
||||||
|
|
||||||
|
if (utils.isString(domain)) { |
||||||
|
cookie.push('domain=' + domain); |
||||||
|
} |
||||||
|
|
||||||
|
if (secure === true) { |
||||||
|
cookie.push('secure'); |
||||||
|
} |
||||||
|
|
||||||
|
document.cookie = cookie.join('; '); |
||||||
|
}, |
||||||
|
|
||||||
|
read: function read(name) { |
||||||
|
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)')); |
||||||
|
return (match ? decodeURIComponent(match[3]) : null); |
||||||
|
}, |
||||||
|
|
||||||
|
remove: function remove(name) { |
||||||
|
this.write(name, '', Date.now() - 86400000); |
||||||
|
} |
||||||
|
}; |
||||||
|
})() : |
||||||
|
|
||||||
|
// Non standard browser env (web workers, react-native) lack needed support.
|
||||||
|
(function nonStandardBrowserEnv() { |
||||||
|
return { |
||||||
|
write: function write() {}, |
||||||
|
read: function read() { return null; }, |
||||||
|
remove: function remove() {} |
||||||
|
}; |
||||||
|
})() |
||||||
|
); |
@ -0,0 +1,24 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
/*eslint no-console:0*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Supply a warning to the developer that a method they are using |
||||||
|
* has been deprecated. |
||||||
|
* |
||||||
|
* @param {string} method The name of the deprecated method |
||||||
|
* @param {string} [instead] The alternate method to use if applicable |
||||||
|
* @param {string} [docs] The documentation URL to get further details |
||||||
|
*/ |
||||||
|
module.exports = function deprecatedMethod(method, instead, docs) { |
||||||
|
try { |
||||||
|
console.warn( |
||||||
|
'DEPRECATED method `' + method + '`.' + |
||||||
|
(instead ? ' Use `' + instead + '` instead.' : '') + |
||||||
|
' This method will be removed in a future release.'); |
||||||
|
|
||||||
|
if (docs) { |
||||||
|
console.warn('For more information about usage see ' + docs); |
||||||
|
} |
||||||
|
} catch (e) { /* Ignore */ } |
||||||
|
}; |
@ -0,0 +1,14 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Determines whether the specified URL is absolute |
||||||
|
* |
||||||
|
* @param {string} url The URL to test |
||||||
|
* @returns {boolean} True if the specified URL is absolute, otherwise false |
||||||
|
*/ |
||||||
|
module.exports = function isAbsoluteURL(url) { |
||||||
|
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
||||||
|
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
||||||
|
// by any combination of letters, digits, plus, period, or hyphen.
|
||||||
|
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url); |
||||||
|
}; |
@ -0,0 +1,11 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Determines whether the payload is an error thrown by Axios |
||||||
|
* |
||||||
|
* @param {*} payload The value to test |
||||||
|
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false |
||||||
|
*/ |
||||||
|
module.exports = function isAxiosError(payload) { |
||||||
|
return (typeof payload === 'object') && (payload.isAxiosError === true); |
||||||
|
}; |
@ -0,0 +1,68 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
|
||||||
|
module.exports = ( |
||||||
|
utils.isStandardBrowserEnv() ? |
||||||
|
|
||||||
|
// Standard browser envs have full support of the APIs needed to test
|
||||||
|
// whether the request URL is of the same origin as current location.
|
||||||
|
(function standardBrowserEnv() { |
||||||
|
var msie = /(msie|trident)/i.test(navigator.userAgent); |
||||||
|
var urlParsingNode = document.createElement('a'); |
||||||
|
var originURL; |
||||||
|
|
||||||
|
/** |
||||||
|
* Parse a URL to discover it's components |
||||||
|
* |
||||||
|
* @param {String} url The URL to be parsed |
||||||
|
* @returns {Object} |
||||||
|
*/ |
||||||
|
function resolveURL(url) { |
||||||
|
var href = url; |
||||||
|
|
||||||
|
if (msie) { |
||||||
|
// IE needs attribute set twice to normalize properties
|
||||||
|
urlParsingNode.setAttribute('href', href); |
||||||
|
href = urlParsingNode.href; |
||||||
|
} |
||||||
|
|
||||||
|
urlParsingNode.setAttribute('href', href); |
||||||
|
|
||||||
|
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
||||||
|
return { |
||||||
|
href: urlParsingNode.href, |
||||||
|
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '', |
||||||
|
host: urlParsingNode.host, |
||||||
|
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '', |
||||||
|
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '', |
||||||
|
hostname: urlParsingNode.hostname, |
||||||
|
port: urlParsingNode.port, |
||||||
|
pathname: (urlParsingNode.pathname.charAt(0) === '/') ? |
||||||
|
urlParsingNode.pathname : |
||||||
|
'/' + urlParsingNode.pathname |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
originURL = resolveURL(window.location.href); |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a URL shares the same origin as the current location |
||||||
|
* |
||||||
|
* @param {String} requestURL The URL to test |
||||||
|
* @returns {boolean} True if URL shares the same origin, otherwise false |
||||||
|
*/ |
||||||
|
return function isURLSameOrigin(requestURL) { |
||||||
|
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL; |
||||||
|
return (parsed.protocol === originURL.protocol && |
||||||
|
parsed.host === originURL.host); |
||||||
|
}; |
||||||
|
})() : |
||||||
|
|
||||||
|
// Non standard browser envs (web workers, react-native) lack needed support.
|
||||||
|
(function nonStandardBrowserEnv() { |
||||||
|
return function isURLSameOrigin() { |
||||||
|
return true; |
||||||
|
}; |
||||||
|
})() |
||||||
|
); |
@ -0,0 +1,12 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('../utils'); |
||||||
|
|
||||||
|
module.exports = function normalizeHeaderName(headers, normalizedName) { |
||||||
|
utils.forEach(headers, function processHeader(value, name) { |
||||||
|
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) { |
||||||
|
headers[normalizedName] = value; |
||||||
|
delete headers[name]; |
||||||
|
} |
||||||
|
}); |
||||||
|
}; |
@ -0,0 +1,53 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var utils = require('./../utils'); |
||||||
|
|
||||||
|
// Headers whose duplicates are ignored by node
|
||||||
|
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
||||||
|
var ignoreDuplicateOf = [ |
||||||
|
'age', 'authorization', 'content-length', 'content-type', 'etag', |
||||||
|
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', |
||||||
|
'last-modified', 'location', 'max-forwards', 'proxy-authorization', |
||||||
|
'referer', 'retry-after', 'user-agent' |
||||||
|
]; |
||||||
|
|
||||||
|
/** |
||||||
|
* Parse headers into an object |
||||||
|
* |
||||||
|
* ``` |
||||||
|
* Date: Wed, 27 Aug 2014 08:58:49 GMT |
||||||
|
* Content-Type: application/json |
||||||
|
* Connection: keep-alive |
||||||
|
* Transfer-Encoding: chunked |
||||||
|
* ``` |
||||||
|
* |
||||||
|
* @param {String} headers Headers needing to be parsed |
||||||
|
* @returns {Object} Headers parsed into an object |
||||||
|
*/ |
||||||
|
module.exports = function parseHeaders(headers) { |
||||||
|
var parsed = {}; |
||||||
|
var key; |
||||||
|
var val; |
||||||
|
var i; |
||||||
|
|
||||||
|
if (!headers) { return parsed; } |
||||||
|
|
||||||
|
utils.forEach(headers.split('\n'), function parser(line) { |
||||||
|
i = line.indexOf(':'); |
||||||
|
key = utils.trim(line.substr(0, i)).toLowerCase(); |
||||||
|
val = utils.trim(line.substr(i + 1)); |
||||||
|
|
||||||
|
if (key) { |
||||||
|
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) { |
||||||
|
return; |
||||||
|
} |
||||||
|
if (key === 'set-cookie') { |
||||||
|
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]); |
||||||
|
} else { |
||||||
|
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val; |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
return parsed; |
||||||
|
}; |
@ -0,0 +1,27 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Syntactic sugar for invoking a function and expanding an array for arguments. |
||||||
|
* |
||||||
|
* Common use case would be to use `Function.prototype.apply`. |
||||||
|
* |
||||||
|
* ```js
|
||||||
|
* function f(x, y, z) {} |
||||||
|
* var args = [1, 2, 3]; |
||||||
|
* f.apply(null, args); |
||||||
|
* ``` |
||||||
|
* |
||||||
|
* With `spread` this example can be re-written. |
||||||
|
* |
||||||
|
* ```js
|
||||||
|
* spread(function(x, y, z) {})([1, 2, 3]); |
||||||
|
* ``` |
||||||
|
* |
||||||
|
* @param {Function} callback |
||||||
|
* @returns {Function} |
||||||
|
*/ |
||||||
|
module.exports = function spread(callback) { |
||||||
|
return function wrap(arr) { |
||||||
|
return callback.apply(null, arr); |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,351 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
var bind = require('./helpers/bind'); |
||||||
|
|
||||||
|
/*global toString:true*/ |
||||||
|
|
||||||
|
// utils is a library of generic helper functions non-specific to axios
|
||||||
|
|
||||||
|
var toString = Object.prototype.toString; |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is an Array |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is an Array, otherwise false |
||||||
|
*/ |
||||||
|
function isArray(val) { |
||||||
|
return toString.call(val) === '[object Array]'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is undefined |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if the value is undefined, otherwise false |
||||||
|
*/ |
||||||
|
function isUndefined(val) { |
||||||
|
return typeof val === 'undefined'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a Buffer |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a Buffer, otherwise false |
||||||
|
*/ |
||||||
|
function isBuffer(val) { |
||||||
|
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) |
||||||
|
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is an ArrayBuffer |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is an ArrayBuffer, otherwise false |
||||||
|
*/ |
||||||
|
function isArrayBuffer(val) { |
||||||
|
return toString.call(val) === '[object ArrayBuffer]'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a FormData |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is an FormData, otherwise false |
||||||
|
*/ |
||||||
|
function isFormData(val) { |
||||||
|
return (typeof FormData !== 'undefined') && (val instanceof FormData); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a view on an ArrayBuffer |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false |
||||||
|
*/ |
||||||
|
function isArrayBufferView(val) { |
||||||
|
var result; |
||||||
|
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) { |
||||||
|
result = ArrayBuffer.isView(val); |
||||||
|
} else { |
||||||
|
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a String |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a String, otherwise false |
||||||
|
*/ |
||||||
|
function isString(val) { |
||||||
|
return typeof val === 'string'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a Number |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a Number, otherwise false |
||||||
|
*/ |
||||||
|
function isNumber(val) { |
||||||
|
return typeof val === 'number'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is an Object |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is an Object, otherwise false |
||||||
|
*/ |
||||||
|
function isObject(val) { |
||||||
|
return val !== null && typeof val === 'object'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a plain Object |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @return {boolean} True if value is a plain Object, otherwise false |
||||||
|
*/ |
||||||
|
function isPlainObject(val) { |
||||||
|
if (toString.call(val) !== '[object Object]') { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
var prototype = Object.getPrototypeOf(val); |
||||||
|
return prototype === null || prototype === Object.prototype; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a Date |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a Date, otherwise false |
||||||
|
*/ |
||||||
|
function isDate(val) { |
||||||
|
return toString.call(val) === '[object Date]'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a File |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a File, otherwise false |
||||||
|
*/ |
||||||
|
function isFile(val) { |
||||||
|
return toString.call(val) === '[object File]'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a Blob |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a Blob, otherwise false |
||||||
|
*/ |
||||||
|
function isBlob(val) { |
||||||
|
return toString.call(val) === '[object Blob]'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a Function |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a Function, otherwise false |
||||||
|
*/ |
||||||
|
function isFunction(val) { |
||||||
|
return toString.call(val) === '[object Function]'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a Stream |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a Stream, otherwise false |
||||||
|
*/ |
||||||
|
function isStream(val) { |
||||||
|
return isObject(val) && isFunction(val.pipe); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if a value is a URLSearchParams object |
||||||
|
* |
||||||
|
* @param {Object} val The value to test |
||||||
|
* @returns {boolean} True if value is a URLSearchParams object, otherwise false |
||||||
|
*/ |
||||||
|
function isURLSearchParams(val) { |
||||||
|
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Trim excess whitespace off the beginning and end of a string |
||||||
|
* |
||||||
|
* @param {String} str The String to trim |
||||||
|
* @returns {String} The String freed of excess whitespace |
||||||
|
*/ |
||||||
|
function trim(str) { |
||||||
|
return str.replace(/^\s*/, '').replace(/\s*$/, ''); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Determine if we're running in a standard browser environment |
||||||
|
* |
||||||
|
* This allows axios to run in a web worker, and react-native. |
||||||
|
* Both environments support XMLHttpRequest, but not fully standard globals. |
||||||
|
* |
||||||
|
* web workers: |
||||||
|
* typeof window -> undefined |
||||||
|
* typeof document -> undefined |
||||||
|
* |
||||||
|
* react-native: |
||||||
|
* navigator.product -> 'ReactNative' |
||||||
|
* nativescript |
||||||
|
* navigator.product -> 'NativeScript' or 'NS' |
||||||
|
*/ |
||||||
|
function isStandardBrowserEnv() { |
||||||
|
if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' || |
||||||
|
navigator.product === 'NativeScript' || |
||||||
|
navigator.product === 'NS')) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return ( |
||||||
|
typeof window !== 'undefined' && |
||||||
|
typeof document !== 'undefined' |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Iterate over an Array or an Object invoking a function for each item. |
||||||
|
* |
||||||
|
* If `obj` is an Array callback will be called passing |
||||||
|
* the value, index, and complete array for each item. |
||||||
|
* |
||||||
|
* If 'obj' is an Object callback will be called passing |
||||||
|
* the value, key, and complete object for each property. |
||||||
|
* |
||||||
|
* @param {Object|Array} obj The object to iterate |
||||||
|
* @param {Function} fn The callback to invoke for each item |
||||||
|
*/ |
||||||
|
function forEach(obj, fn) { |
||||||
|
// Don't bother if no value provided
|
||||||
|
if (obj === null || typeof obj === 'undefined') { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// Force an array if not already something iterable
|
||||||
|
if (typeof obj !== 'object') { |
||||||
|
/*eslint no-param-reassign:0*/ |
||||||
|
obj = [obj]; |
||||||
|
} |
||||||
|
|
||||||
|
if (isArray(obj)) { |
||||||
|
// Iterate over array values
|
||||||
|
for (var i = 0, l = obj.length; i < l; i++) { |
||||||
|
fn.call(null, obj[i], i, obj); |
||||||
|
} |
||||||
|
} else { |
||||||
|
// Iterate over object keys
|
||||||
|
for (var key in obj) { |
||||||
|
if (Object.prototype.hasOwnProperty.call(obj, key)) { |
||||||
|
fn.call(null, obj[key], key, obj); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Accepts varargs expecting each argument to be an object, then |
||||||
|
* immutably merges the properties of each object and returns result. |
||||||
|
* |
||||||
|
* When multiple objects contain the same key the later object in |
||||||
|
* the arguments list will take precedence. |
||||||
|
* |
||||||
|
* Example: |
||||||
|
* |
||||||
|
* ```js
|
||||||
|
* var result = merge({foo: 123}, {foo: 456}); |
||||||
|
* console.log(result.foo); // outputs 456
|
||||||
|
* ``` |
||||||
|
* |
||||||
|
* @param {Object} obj1 Object to merge |
||||||
|
* @returns {Object} Result of all merge properties |
||||||
|
*/ |
||||||
|
function merge(/* obj1, obj2, obj3, ... */) { |
||||||
|
var result = {}; |
||||||
|
function assignValue(val, key) { |
||||||
|
if (isPlainObject(result[key]) && isPlainObject(val)) { |
||||||
|
result[key] = merge(result[key], val); |
||||||
|
} else if (isPlainObject(val)) { |
||||||
|
result[key] = merge({}, val); |
||||||
|
} else if (isArray(val)) { |
||||||
|
result[key] = val.slice(); |
||||||
|
} else { |
||||||
|
result[key] = val; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
for (var i = 0, l = arguments.length; i < l; i++) { |
||||||
|
forEach(arguments[i], assignValue); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Extends object a by mutably adding to it the properties of object b. |
||||||
|
* |
||||||
|
* @param {Object} a The object to be extended |
||||||
|
* @param {Object} b The object to copy properties from |
||||||
|
* @param {Object} thisArg The object to bind function to |
||||||
|
* @return {Object} The resulting value of object a |
||||||
|
*/ |
||||||
|
function extend(a, b, thisArg) { |
||||||
|
forEach(b, function assignValue(val, key) { |
||||||
|
if (thisArg && typeof val === 'function') { |
||||||
|
a[key] = bind(val, thisArg); |
||||||
|
} else { |
||||||
|
a[key] = val; |
||||||
|
} |
||||||
|
}); |
||||||
|
return a; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM) |
||||||
|
* |
||||||
|
* @param {string} content with BOM |
||||||
|
* @return {string} content value without BOM |
||||||
|
*/ |
||||||
|
function stripBOM(content) { |
||||||
|
if (content.charCodeAt(0) === 0xFEFF) { |
||||||
|
content = content.slice(1); |
||||||
|
} |
||||||
|
return content; |
||||||
|
} |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
isArray: isArray, |
||||||
|
isArrayBuffer: isArrayBuffer, |
||||||
|
isBuffer: isBuffer, |
||||||
|
isFormData: isFormData, |
||||||
|
isArrayBufferView: isArrayBufferView, |
||||||
|
isString: isString, |
||||||
|
isNumber: isNumber, |
||||||
|
isObject: isObject, |
||||||
|
isPlainObject: isPlainObject, |
||||||
|
isUndefined: isUndefined, |
||||||
|
isDate: isDate, |
||||||
|
isFile: isFile, |
||||||
|
isBlob: isBlob, |
||||||
|
isFunction: isFunction, |
||||||
|
isStream: isStream, |
||||||
|
isURLSearchParams: isURLSearchParams, |
||||||
|
isStandardBrowserEnv: isStandardBrowserEnv, |
||||||
|
forEach: forEach, |
||||||
|
merge: merge, |
||||||
|
extend: extend, |
||||||
|
trim: trim, |
||||||
|
stripBOM: stripBOM |
||||||
|
}; |
@ -0,0 +1,114 @@ |
|||||||
|
{ |
||||||
|
"_from": "axios", |
||||||
|
"_id": "axios@0.21.1", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", |
||||||
|
"_location": "/axios", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "tag", |
||||||
|
"registry": true, |
||||||
|
"raw": "axios", |
||||||
|
"name": "axios", |
||||||
|
"escapedName": "axios", |
||||||
|
"rawSpec": "", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "latest" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"#USER", |
||||||
|
"/" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", |
||||||
|
"_shasum": "22563481962f4d6bde9a76d516ef0e5d3c09b2b8", |
||||||
|
"_spec": "axios", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server", |
||||||
|
"author": { |
||||||
|
"name": "Matt Zabriskie" |
||||||
|
}, |
||||||
|
"browser": { |
||||||
|
"./lib/adapters/http.js": "./lib/adapters/xhr.js" |
||||||
|
}, |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/axios/axios/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"bundlesize": [ |
||||||
|
{ |
||||||
|
"path": "./dist/axios.min.js", |
||||||
|
"threshold": "5kB" |
||||||
|
} |
||||||
|
], |
||||||
|
"dependencies": { |
||||||
|
"follow-redirects": "^1.10.0" |
||||||
|
}, |
||||||
|
"deprecated": false, |
||||||
|
"description": "Promise based HTTP client for the browser and node.js", |
||||||
|
"devDependencies": { |
||||||
|
"bundlesize": "^0.17.0", |
||||||
|
"coveralls": "^3.0.0", |
||||||
|
"es6-promise": "^4.2.4", |
||||||
|
"grunt": "^1.0.2", |
||||||
|
"grunt-banner": "^0.6.0", |
||||||
|
"grunt-cli": "^1.2.0", |
||||||
|
"grunt-contrib-clean": "^1.1.0", |
||||||
|
"grunt-contrib-watch": "^1.0.0", |
||||||
|
"grunt-eslint": "^20.1.0", |
||||||
|
"grunt-karma": "^2.0.0", |
||||||
|
"grunt-mocha-test": "^0.13.3", |
||||||
|
"grunt-ts": "^6.0.0-beta.19", |
||||||
|
"grunt-webpack": "^1.0.18", |
||||||
|
"istanbul-instrumenter-loader": "^1.0.0", |
||||||
|
"jasmine-core": "^2.4.1", |
||||||
|
"karma": "^1.3.0", |
||||||
|
"karma-chrome-launcher": "^2.2.0", |
||||||
|
"karma-coverage": "^1.1.1", |
||||||
|
"karma-firefox-launcher": "^1.1.0", |
||||||
|
"karma-jasmine": "^1.1.1", |
||||||
|
"karma-jasmine-ajax": "^0.1.13", |
||||||
|
"karma-opera-launcher": "^1.0.0", |
||||||
|
"karma-safari-launcher": "^1.0.0", |
||||||
|
"karma-sauce-launcher": "^1.2.0", |
||||||
|
"karma-sinon": "^1.0.5", |
||||||
|
"karma-sourcemap-loader": "^0.3.7", |
||||||
|
"karma-webpack": "^1.7.0", |
||||||
|
"load-grunt-tasks": "^3.5.2", |
||||||
|
"minimist": "^1.2.0", |
||||||
|
"mocha": "^5.2.0", |
||||||
|
"sinon": "^4.5.0", |
||||||
|
"typescript": "^2.8.1", |
||||||
|
"url-search-params": "^0.10.0", |
||||||
|
"webpack": "^1.13.1", |
||||||
|
"webpack-dev-server": "^1.14.1" |
||||||
|
}, |
||||||
|
"homepage": "https://github.com/axios/axios", |
||||||
|
"jsdelivr": "dist/axios.min.js", |
||||||
|
"keywords": [ |
||||||
|
"xhr", |
||||||
|
"http", |
||||||
|
"ajax", |
||||||
|
"promise", |
||||||
|
"node" |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"main": "index.js", |
||||||
|
"name": "axios", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/axios/axios.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"build": "NODE_ENV=production grunt build", |
||||||
|
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", |
||||||
|
"examples": "node ./examples/server.js", |
||||||
|
"fix": "eslint --fix lib/**/*.js", |
||||||
|
"postversion": "git push && git push --tags", |
||||||
|
"preversion": "npm test", |
||||||
|
"start": "node ./sandbox/server.js", |
||||||
|
"test": "grunt test && bundlesize", |
||||||
|
"version": "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json" |
||||||
|
}, |
||||||
|
"typings": "./index.d.ts", |
||||||
|
"unpkg": "dist/axios.min.js", |
||||||
|
"version": "0.21.1" |
||||||
|
} |
@ -0,0 +1,609 @@ |
|||||||
|
1.19.0 / 2019-04-25 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: bytes@3.1.0 |
||||||
|
- Add petabyte (`pb`) support |
||||||
|
* deps: http-errors@1.7.2 |
||||||
|
- Set constructor name when possible |
||||||
|
- deps: setprototypeof@1.1.1 |
||||||
|
- deps: statuses@'>= 1.5.0 < 2' |
||||||
|
* deps: iconv-lite@0.4.24 |
||||||
|
- Added encoding MIK |
||||||
|
* deps: qs@6.7.0 |
||||||
|
- Fix parsing array brackets after index |
||||||
|
* deps: raw-body@2.4.0 |
||||||
|
- deps: bytes@3.1.0 |
||||||
|
- deps: http-errors@1.7.2 |
||||||
|
- deps: iconv-lite@0.4.24 |
||||||
|
* deps: type-is@~1.6.17 |
||||||
|
- deps: mime-types@~2.1.24 |
||||||
|
- perf: prevent internal `throw` on invalid type |
||||||
|
|
||||||
|
1.18.3 / 2018-05-14 |
||||||
|
=================== |
||||||
|
|
||||||
|
* Fix stack trace for strict json parse error |
||||||
|
* deps: depd@~1.1.2 |
||||||
|
- perf: remove argument reassignment |
||||||
|
* deps: http-errors@~1.6.3 |
||||||
|
- deps: depd@~1.1.2 |
||||||
|
- deps: setprototypeof@1.1.0 |
||||||
|
- deps: statuses@'>= 1.3.1 < 2' |
||||||
|
* deps: iconv-lite@0.4.23 |
||||||
|
- Fix loading encoding with year appended |
||||||
|
- Fix deprecation warnings on Node.js 10+ |
||||||
|
* deps: qs@6.5.2 |
||||||
|
* deps: raw-body@2.3.3 |
||||||
|
- deps: http-errors@1.6.3 |
||||||
|
- deps: iconv-lite@0.4.23 |
||||||
|
* deps: type-is@~1.6.16 |
||||||
|
- deps: mime-types@~2.1.18 |
||||||
|
|
||||||
|
1.18.2 / 2017-09-22 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: debug@2.6.9 |
||||||
|
* perf: remove argument reassignment |
||||||
|
|
||||||
|
1.18.1 / 2017-09-12 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: content-type@~1.0.4 |
||||||
|
- perf: remove argument reassignment |
||||||
|
- perf: skip parameter parsing when no parameters |
||||||
|
* deps: iconv-lite@0.4.19 |
||||||
|
- Fix ISO-8859-1 regression |
||||||
|
- Update Windows-1255 |
||||||
|
* deps: qs@6.5.1 |
||||||
|
- Fix parsing & compacting very deep objects |
||||||
|
* deps: raw-body@2.3.2 |
||||||
|
- deps: iconv-lite@0.4.19 |
||||||
|
|
||||||
|
1.18.0 / 2017-09-08 |
||||||
|
=================== |
||||||
|
|
||||||
|
* Fix JSON strict violation error to match native parse error |
||||||
|
* Include the `body` property on verify errors |
||||||
|
* Include the `type` property on all generated errors |
||||||
|
* Use `http-errors` to set status code on errors |
||||||
|
* deps: bytes@3.0.0 |
||||||
|
* deps: debug@2.6.8 |
||||||
|
* deps: depd@~1.1.1 |
||||||
|
- Remove unnecessary `Buffer` loading |
||||||
|
* deps: http-errors@~1.6.2 |
||||||
|
- deps: depd@1.1.1 |
||||||
|
* deps: iconv-lite@0.4.18 |
||||||
|
- Add support for React Native |
||||||
|
- Add a warning if not loaded as utf-8 |
||||||
|
- Fix CESU-8 decoding in Node.js 8 |
||||||
|
- Improve speed of ISO-8859-1 encoding |
||||||
|
* deps: qs@6.5.0 |
||||||
|
* deps: raw-body@2.3.1 |
||||||
|
- Use `http-errors` for standard emitted errors |
||||||
|
- deps: bytes@3.0.0 |
||||||
|
- deps: iconv-lite@0.4.18 |
||||||
|
- perf: skip buffer decoding on overage chunk |
||||||
|
* perf: prevent internal `throw` when missing charset |
||||||
|
|
||||||
|
1.17.2 / 2017-05-17 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: debug@2.6.7 |
||||||
|
- Fix `DEBUG_MAX_ARRAY_LENGTH` |
||||||
|
- deps: ms@2.0.0 |
||||||
|
* deps: type-is@~1.6.15 |
||||||
|
- deps: mime-types@~2.1.15 |
||||||
|
|
||||||
|
1.17.1 / 2017-03-06 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: qs@6.4.0 |
||||||
|
- Fix regression parsing keys starting with `[` |
||||||
|
|
||||||
|
1.17.0 / 2017-03-01 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: http-errors@~1.6.1 |
||||||
|
- Make `message` property enumerable for `HttpError`s |
||||||
|
- deps: setprototypeof@1.0.3 |
||||||
|
* deps: qs@6.3.1 |
||||||
|
- Fix compacting nested arrays |
||||||
|
|
||||||
|
1.16.1 / 2017-02-10 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: debug@2.6.1 |
||||||
|
- Fix deprecation messages in WebStorm and other editors |
||||||
|
- Undeprecate `DEBUG_FD` set to `1` or `2` |
||||||
|
|
||||||
|
1.16.0 / 2017-01-17 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: debug@2.6.0 |
||||||
|
- Allow colors in workers |
||||||
|
- Deprecated `DEBUG_FD` environment variable |
||||||
|
- Fix error when running under React Native |
||||||
|
- Use same color for same namespace |
||||||
|
- deps: ms@0.7.2 |
||||||
|
* deps: http-errors@~1.5.1 |
||||||
|
- deps: inherits@2.0.3 |
||||||
|
- deps: setprototypeof@1.0.2 |
||||||
|
- deps: statuses@'>= 1.3.1 < 2' |
||||||
|
* deps: iconv-lite@0.4.15 |
||||||
|
- Added encoding MS-31J |
||||||
|
- Added encoding MS-932 |
||||||
|
- Added encoding MS-936 |
||||||
|
- Added encoding MS-949 |
||||||
|
- Added encoding MS-950 |
||||||
|
- Fix GBK/GB18030 handling of Euro character |
||||||
|
* deps: qs@6.2.1 |
||||||
|
- Fix array parsing from skipping empty values |
||||||
|
* deps: raw-body@~2.2.0 |
||||||
|
- deps: iconv-lite@0.4.15 |
||||||
|
* deps: type-is@~1.6.14 |
||||||
|
- deps: mime-types@~2.1.13 |
||||||
|
|
||||||
|
1.15.2 / 2016-06-19 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: bytes@2.4.0 |
||||||
|
* deps: content-type@~1.0.2 |
||||||
|
- perf: enable strict mode |
||||||
|
* deps: http-errors@~1.5.0 |
||||||
|
- Use `setprototypeof` module to replace `__proto__` setting |
||||||
|
- deps: statuses@'>= 1.3.0 < 2' |
||||||
|
- perf: enable strict mode |
||||||
|
* deps: qs@6.2.0 |
||||||
|
* deps: raw-body@~2.1.7 |
||||||
|
- deps: bytes@2.4.0 |
||||||
|
- perf: remove double-cleanup on happy path |
||||||
|
* deps: type-is@~1.6.13 |
||||||
|
- deps: mime-types@~2.1.11 |
||||||
|
|
||||||
|
1.15.1 / 2016-05-05 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: bytes@2.3.0 |
||||||
|
- Drop partial bytes on all parsed units |
||||||
|
- Fix parsing byte string that looks like hex |
||||||
|
* deps: raw-body@~2.1.6 |
||||||
|
- deps: bytes@2.3.0 |
||||||
|
* deps: type-is@~1.6.12 |
||||||
|
- deps: mime-types@~2.1.10 |
||||||
|
|
||||||
|
1.15.0 / 2016-02-10 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: http-errors@~1.4.0 |
||||||
|
- Add `HttpError` export, for `err instanceof createError.HttpError` |
||||||
|
- deps: inherits@2.0.1 |
||||||
|
- deps: statuses@'>= 1.2.1 < 2' |
||||||
|
* deps: qs@6.1.0 |
||||||
|
* deps: type-is@~1.6.11 |
||||||
|
- deps: mime-types@~2.1.9 |
||||||
|
|
||||||
|
1.14.2 / 2015-12-16 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: bytes@2.2.0 |
||||||
|
* deps: iconv-lite@0.4.13 |
||||||
|
* deps: qs@5.2.0 |
||||||
|
* deps: raw-body@~2.1.5 |
||||||
|
- deps: bytes@2.2.0 |
||||||
|
- deps: iconv-lite@0.4.13 |
||||||
|
* deps: type-is@~1.6.10 |
||||||
|
- deps: mime-types@~2.1.8 |
||||||
|
|
||||||
|
1.14.1 / 2015-09-27 |
||||||
|
=================== |
||||||
|
|
||||||
|
* Fix issue where invalid charset results in 400 when `verify` used |
||||||
|
* deps: iconv-lite@0.4.12 |
||||||
|
- Fix CESU-8 decoding in Node.js 4.x |
||||||
|
* deps: raw-body@~2.1.4 |
||||||
|
- Fix masking critical errors from `iconv-lite` |
||||||
|
- deps: iconv-lite@0.4.12 |
||||||
|
* deps: type-is@~1.6.9 |
||||||
|
- deps: mime-types@~2.1.7 |
||||||
|
|
||||||
|
1.14.0 / 2015-09-16 |
||||||
|
=================== |
||||||
|
|
||||||
|
* Fix JSON strict parse error to match syntax errors |
||||||
|
* Provide static `require` analysis in `urlencoded` parser |
||||||
|
* deps: depd@~1.1.0 |
||||||
|
- Support web browser loading |
||||||
|
* deps: qs@5.1.0 |
||||||
|
* deps: raw-body@~2.1.3 |
||||||
|
- Fix sync callback when attaching data listener causes sync read |
||||||
|
* deps: type-is@~1.6.8 |
||||||
|
- Fix type error when given invalid type to match against |
||||||
|
- deps: mime-types@~2.1.6 |
||||||
|
|
||||||
|
1.13.3 / 2015-07-31 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: type-is@~1.6.6 |
||||||
|
- deps: mime-types@~2.1.4 |
||||||
|
|
||||||
|
1.13.2 / 2015-07-05 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: iconv-lite@0.4.11 |
||||||
|
* deps: qs@4.0.0 |
||||||
|
- Fix dropping parameters like `hasOwnProperty` |
||||||
|
- Fix user-visible incompatibilities from 3.1.0 |
||||||
|
- Fix various parsing edge cases |
||||||
|
* deps: raw-body@~2.1.2 |
||||||
|
- Fix error stack traces to skip `makeError` |
||||||
|
- deps: iconv-lite@0.4.11 |
||||||
|
* deps: type-is@~1.6.4 |
||||||
|
- deps: mime-types@~2.1.2 |
||||||
|
- perf: enable strict mode |
||||||
|
- perf: remove argument reassignment |
||||||
|
|
||||||
|
1.13.1 / 2015-06-16 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: qs@2.4.2 |
||||||
|
- Downgraded from 3.1.0 because of user-visible incompatibilities |
||||||
|
|
||||||
|
1.13.0 / 2015-06-14 |
||||||
|
=================== |
||||||
|
|
||||||
|
* Add `statusCode` property on `Error`s, in addition to `status` |
||||||
|
* Change `type` default to `application/json` for JSON parser |
||||||
|
* Change `type` default to `application/x-www-form-urlencoded` for urlencoded parser |
||||||
|
* Provide static `require` analysis |
||||||
|
* Use the `http-errors` module to generate errors |
||||||
|
* deps: bytes@2.1.0 |
||||||
|
- Slight optimizations |
||||||
|
* deps: iconv-lite@0.4.10 |
||||||
|
- The encoding UTF-16 without BOM now defaults to UTF-16LE when detection fails |
||||||
|
- Leading BOM is now removed when decoding |
||||||
|
* deps: on-finished@~2.3.0 |
||||||
|
- Add defined behavior for HTTP `CONNECT` requests |
||||||
|
- Add defined behavior for HTTP `Upgrade` requests |
||||||
|
- deps: ee-first@1.1.1 |
||||||
|
* deps: qs@3.1.0 |
||||||
|
- Fix dropping parameters like `hasOwnProperty` |
||||||
|
- Fix various parsing edge cases |
||||||
|
- Parsed object now has `null` prototype |
||||||
|
* deps: raw-body@~2.1.1 |
||||||
|
- Use `unpipe` module for unpiping requests |
||||||
|
- deps: iconv-lite@0.4.10 |
||||||
|
* deps: type-is@~1.6.3 |
||||||
|
- deps: mime-types@~2.1.1 |
||||||
|
- perf: reduce try block size |
||||||
|
- perf: remove bitwise operations |
||||||
|
* perf: enable strict mode |
||||||
|
* perf: remove argument reassignment |
||||||
|
* perf: remove delete call |
||||||
|
|
||||||
|
1.12.4 / 2015-05-10 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: debug@~2.2.0 |
||||||
|
* deps: qs@2.4.2 |
||||||
|
- Fix allowing parameters like `constructor` |
||||||
|
* deps: on-finished@~2.2.1 |
||||||
|
* deps: raw-body@~2.0.1 |
||||||
|
- Fix a false-positive when unpiping in Node.js 0.8 |
||||||
|
- deps: bytes@2.0.1 |
||||||
|
* deps: type-is@~1.6.2 |
||||||
|
- deps: mime-types@~2.0.11 |
||||||
|
|
||||||
|
1.12.3 / 2015-04-15 |
||||||
|
=================== |
||||||
|
|
||||||
|
* Slight efficiency improvement when not debugging |
||||||
|
* deps: depd@~1.0.1 |
||||||
|
* deps: iconv-lite@0.4.8 |
||||||
|
- Add encoding alias UNICODE-1-1-UTF-7 |
||||||
|
* deps: raw-body@1.3.4 |
||||||
|
- Fix hanging callback if request aborts during read |
||||||
|
- deps: iconv-lite@0.4.8 |
||||||
|
|
||||||
|
1.12.2 / 2015-03-16 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: qs@2.4.1 |
||||||
|
- Fix error when parameter `hasOwnProperty` is present |
||||||
|
|
||||||
|
1.12.1 / 2015-03-15 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: debug@~2.1.3 |
||||||
|
- Fix high intensity foreground color for bold |
||||||
|
- deps: ms@0.7.0 |
||||||
|
* deps: type-is@~1.6.1 |
||||||
|
- deps: mime-types@~2.0.10 |
||||||
|
|
||||||
|
1.12.0 / 2015-02-13 |
||||||
|
=================== |
||||||
|
|
||||||
|
* add `debug` messages |
||||||
|
* accept a function for the `type` option |
||||||
|
* use `content-type` to parse `Content-Type` headers |
||||||
|
* deps: iconv-lite@0.4.7 |
||||||
|
- Gracefully support enumerables on `Object.prototype` |
||||||
|
* deps: raw-body@1.3.3 |
||||||
|
- deps: iconv-lite@0.4.7 |
||||||
|
* deps: type-is@~1.6.0 |
||||||
|
- fix argument reassignment |
||||||
|
- fix false-positives in `hasBody` `Transfer-Encoding` check |
||||||
|
- support wildcard for both type and subtype (`*/*`) |
||||||
|
- deps: mime-types@~2.0.9 |
||||||
|
|
||||||
|
1.11.0 / 2015-01-30 |
||||||
|
=================== |
||||||
|
|
||||||
|
* make internal `extended: true` depth limit infinity |
||||||
|
* deps: type-is@~1.5.6 |
||||||
|
- deps: mime-types@~2.0.8 |
||||||
|
|
||||||
|
1.10.2 / 2015-01-20 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: iconv-lite@0.4.6 |
||||||
|
- Fix rare aliases of single-byte encodings |
||||||
|
* deps: raw-body@1.3.2 |
||||||
|
- deps: iconv-lite@0.4.6 |
||||||
|
|
||||||
|
1.10.1 / 2015-01-01 |
||||||
|
=================== |
||||||
|
|
||||||
|
* deps: on-finished@~2.2.0 |
||||||
|
* deps: type-is@~1.5.5 |
||||||
|
- deps: mime-types@~2.0.7 |
||||||
|
|
||||||
|
1.10.0 / 2014-12-02 |
||||||
|
=================== |
||||||
|
|
||||||
|
* make internal `extended: true` array limit dynamic |
||||||
|
|
||||||
|
1.9.3 / 2014-11-21 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: iconv-lite@0.4.5 |
||||||
|
- Fix Windows-31J and X-SJIS encoding support |
||||||
|
* deps: qs@2.3.3 |
||||||
|
- Fix `arrayLimit` behavior |
||||||
|
* deps: raw-body@1.3.1 |
||||||
|
- deps: iconv-lite@0.4.5 |
||||||
|
* deps: type-is@~1.5.3 |
||||||
|
- deps: mime-types@~2.0.3 |
||||||
|
|
||||||
|
1.9.2 / 2014-10-27 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@2.3.2 |
||||||
|
- Fix parsing of mixed objects and values |
||||||
|
|
||||||
|
1.9.1 / 2014-10-22 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: on-finished@~2.1.1 |
||||||
|
- Fix handling of pipelined requests |
||||||
|
* deps: qs@2.3.0 |
||||||
|
- Fix parsing of mixed implicit and explicit arrays |
||||||
|
* deps: type-is@~1.5.2 |
||||||
|
- deps: mime-types@~2.0.2 |
||||||
|
|
||||||
|
1.9.0 / 2014-09-24 |
||||||
|
================== |
||||||
|
|
||||||
|
* include the charset in "unsupported charset" error message |
||||||
|
* include the encoding in "unsupported content encoding" error message |
||||||
|
* deps: depd@~1.0.0 |
||||||
|
|
||||||
|
1.8.4 / 2014-09-23 |
||||||
|
================== |
||||||
|
|
||||||
|
* fix content encoding to be case-insensitive |
||||||
|
|
||||||
|
1.8.3 / 2014-09-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@2.2.4 |
||||||
|
- Fix issue with object keys starting with numbers truncated |
||||||
|
|
||||||
|
1.8.2 / 2014-09-15 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: depd@0.4.5 |
||||||
|
|
||||||
|
1.8.1 / 2014-09-07 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: media-typer@0.3.0 |
||||||
|
* deps: type-is@~1.5.1 |
||||||
|
|
||||||
|
1.8.0 / 2014-09-05 |
||||||
|
================== |
||||||
|
|
||||||
|
* make empty-body-handling consistent between chunked requests |
||||||
|
- empty `json` produces `{}` |
||||||
|
- empty `raw` produces `new Buffer(0)` |
||||||
|
- empty `text` produces `''` |
||||||
|
- empty `urlencoded` produces `{}` |
||||||
|
* deps: qs@2.2.3 |
||||||
|
- Fix issue where first empty value in array is discarded |
||||||
|
* deps: type-is@~1.5.0 |
||||||
|
- fix `hasbody` to be true for `content-length: 0` |
||||||
|
|
||||||
|
1.7.0 / 2014-09-01 |
||||||
|
================== |
||||||
|
|
||||||
|
* add `parameterLimit` option to `urlencoded` parser |
||||||
|
* change `urlencoded` extended array limit to 100 |
||||||
|
* respond with 413 when over `parameterLimit` in `urlencoded` |
||||||
|
|
||||||
|
1.6.7 / 2014-08-29 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@2.2.2 |
||||||
|
- Remove unnecessary cloning |
||||||
|
|
||||||
|
1.6.6 / 2014-08-27 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@2.2.0 |
||||||
|
- Array parsing fix |
||||||
|
- Performance improvements |
||||||
|
|
||||||
|
1.6.5 / 2014-08-16 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: on-finished@2.1.0 |
||||||
|
|
||||||
|
1.6.4 / 2014-08-14 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@1.2.2 |
||||||
|
|
||||||
|
1.6.3 / 2014-08-10 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@1.2.1 |
||||||
|
|
||||||
|
1.6.2 / 2014-08-07 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@1.2.0 |
||||||
|
- Fix parsing array of objects |
||||||
|
|
||||||
|
1.6.1 / 2014-08-06 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@1.1.0 |
||||||
|
- Accept urlencoded square brackets |
||||||
|
- Accept empty values in implicit array notation |
||||||
|
|
||||||
|
1.6.0 / 2014-08-05 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: qs@1.0.2 |
||||||
|
- Complete rewrite |
||||||
|
- Limits array length to 20 |
||||||
|
- Limits object depth to 5 |
||||||
|
- Limits parameters to 1,000 |
||||||
|
|
||||||
|
1.5.2 / 2014-07-27 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: depd@0.4.4 |
||||||
|
- Work-around v8 generating empty stack traces |
||||||
|
|
||||||
|
1.5.1 / 2014-07-26 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: depd@0.4.3 |
||||||
|
- Fix exception when global `Error.stackTraceLimit` is too low |
||||||
|
|
||||||
|
1.5.0 / 2014-07-20 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: depd@0.4.2 |
||||||
|
- Add `TRACE_DEPRECATION` environment variable |
||||||
|
- Remove non-standard grey color from color output |
||||||
|
- Support `--no-deprecation` argument |
||||||
|
- Support `--trace-deprecation` argument |
||||||
|
* deps: iconv-lite@0.4.4 |
||||||
|
- Added encoding UTF-7 |
||||||
|
* deps: raw-body@1.3.0 |
||||||
|
- deps: iconv-lite@0.4.4 |
||||||
|
- Added encoding UTF-7 |
||||||
|
- Fix `Cannot switch to old mode now` error on Node.js 0.10+ |
||||||
|
* deps: type-is@~1.3.2 |
||||||
|
|
||||||
|
1.4.3 / 2014-06-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: type-is@1.3.1 |
||||||
|
- fix global variable leak |
||||||
|
|
||||||
|
1.4.2 / 2014-06-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: type-is@1.3.0 |
||||||
|
- improve type parsing |
||||||
|
|
||||||
|
1.4.1 / 2014-06-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* fix urlencoded extended deprecation message |
||||||
|
|
||||||
|
1.4.0 / 2014-06-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* add `text` parser |
||||||
|
* add `raw` parser |
||||||
|
* check accepted charset in content-type (accepts utf-8) |
||||||
|
* check accepted encoding in content-encoding (accepts identity) |
||||||
|
* deprecate `bodyParser()` middleware; use `.json()` and `.urlencoded()` as needed |
||||||
|
* deprecate `urlencoded()` without provided `extended` option |
||||||
|
* lazy-load urlencoded parsers |
||||||
|
* parsers split into files for reduced mem usage |
||||||
|
* support gzip and deflate bodies |
||||||
|
- set `inflate: false` to turn off |
||||||
|
* deps: raw-body@1.2.2 |
||||||
|
- Support all encodings from `iconv-lite` |
||||||
|
|
||||||
|
1.3.1 / 2014-06-11 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: type-is@1.2.1 |
||||||
|
- Switch dependency from mime to mime-types@1.0.0 |
||||||
|
|
||||||
|
1.3.0 / 2014-05-31 |
||||||
|
================== |
||||||
|
|
||||||
|
* add `extended` option to urlencoded parser |
||||||
|
|
||||||
|
1.2.2 / 2014-05-27 |
||||||
|
================== |
||||||
|
|
||||||
|
* deps: raw-body@1.1.6 |
||||||
|
- assert stream encoding on node.js 0.8 |
||||||
|
- assert stream encoding on node.js < 0.10.6 |
||||||
|
- deps: bytes@1 |
||||||
|
|
||||||
|
1.2.1 / 2014-05-26 |
||||||
|
================== |
||||||
|
|
||||||
|
* invoke `next(err)` after request fully read |
||||||
|
- prevents hung responses and socket hang ups |
||||||
|
|
||||||
|
1.2.0 / 2014-05-11 |
||||||
|
================== |
||||||
|
|
||||||
|
* add `verify` option |
||||||
|
* deps: type-is@1.2.0 |
||||||
|
- support suffix matching |
||||||
|
|
||||||
|
1.1.2 / 2014-05-11 |
||||||
|
================== |
||||||
|
|
||||||
|
* improve json parser speed |
||||||
|
|
||||||
|
1.1.1 / 2014-05-11 |
||||||
|
================== |
||||||
|
|
||||||
|
* fix repeated limit parsing with every request |
||||||
|
|
||||||
|
1.1.0 / 2014-05-10 |
||||||
|
================== |
||||||
|
|
||||||
|
* add `type` option |
||||||
|
* deps: pin for safety and consistency |
||||||
|
|
||||||
|
1.0.2 / 2014-04-14 |
||||||
|
================== |
||||||
|
|
||||||
|
* use `type-is` module |
||||||
|
|
||||||
|
1.0.1 / 2014-03-20 |
||||||
|
================== |
||||||
|
|
||||||
|
* lower default limits to 100kb |
@ -0,0 +1,23 @@ |
|||||||
|
(The MIT License) |
||||||
|
|
||||||
|
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com> |
||||||
|
Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com> |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,443 @@ |
|||||||
|
# body-parser |
||||||
|
|
||||||
|
[![NPM Version][npm-image]][npm-url] |
||||||
|
[![NPM Downloads][downloads-image]][downloads-url] |
||||||
|
[![Build Status][travis-image]][travis-url] |
||||||
|
[![Test Coverage][coveralls-image]][coveralls-url] |
||||||
|
|
||||||
|
Node.js body parsing middleware. |
||||||
|
|
||||||
|
Parse incoming request bodies in a middleware before your handlers, available |
||||||
|
under the `req.body` property. |
||||||
|
|
||||||
|
**Note** As `req.body`'s shape is based on user-controlled input, all |
||||||
|
properties and values in this object are untrusted and should be validated |
||||||
|
before trusting. For example, `req.body.foo.toString()` may fail in multiple |
||||||
|
ways, for example the `foo` property may not be there or may not be a string, |
||||||
|
and `toString` may not be a function and instead a string or other user input. |
||||||
|
|
||||||
|
[Learn about the anatomy of an HTTP transaction in Node.js](https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/). |
||||||
|
|
||||||
|
_This does not handle multipart bodies_, due to their complex and typically |
||||||
|
large nature. For multipart bodies, you may be interested in the following |
||||||
|
modules: |
||||||
|
|
||||||
|
* [busboy](https://www.npmjs.org/package/busboy#readme) and |
||||||
|
[connect-busboy](https://www.npmjs.org/package/connect-busboy#readme) |
||||||
|
* [multiparty](https://www.npmjs.org/package/multiparty#readme) and |
||||||
|
[connect-multiparty](https://www.npmjs.org/package/connect-multiparty#readme) |
||||||
|
* [formidable](https://www.npmjs.org/package/formidable#readme) |
||||||
|
* [multer](https://www.npmjs.org/package/multer#readme) |
||||||
|
|
||||||
|
This module provides the following parsers: |
||||||
|
|
||||||
|
* [JSON body parser](#bodyparserjsonoptions) |
||||||
|
* [Raw body parser](#bodyparserrawoptions) |
||||||
|
* [Text body parser](#bodyparsertextoptions) |
||||||
|
* [URL-encoded form body parser](#bodyparserurlencodedoptions) |
||||||
|
|
||||||
|
Other body parsers you might be interested in: |
||||||
|
|
||||||
|
- [body](https://www.npmjs.org/package/body#readme) |
||||||
|
- [co-body](https://www.npmjs.org/package/co-body#readme) |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
```sh |
||||||
|
$ npm install body-parser |
||||||
|
``` |
||||||
|
|
||||||
|
## API |
||||||
|
|
||||||
|
<!-- eslint-disable no-unused-vars --> |
||||||
|
|
||||||
|
```js |
||||||
|
var bodyParser = require('body-parser') |
||||||
|
``` |
||||||
|
|
||||||
|
The `bodyParser` object exposes various factories to create middlewares. All |
||||||
|
middlewares will populate the `req.body` property with the parsed body when |
||||||
|
the `Content-Type` request header matches the `type` option, or an empty |
||||||
|
object (`{}`) if there was no body to parse, the `Content-Type` was not matched, |
||||||
|
or an error occurred. |
||||||
|
|
||||||
|
The various errors returned by this module are described in the |
||||||
|
[errors section](#errors). |
||||||
|
|
||||||
|
### bodyParser.json([options]) |
||||||
|
|
||||||
|
Returns middleware that only parses `json` and only looks at requests where |
||||||
|
the `Content-Type` header matches the `type` option. This parser accepts any |
||||||
|
Unicode encoding of the body and supports automatic inflation of `gzip` and |
||||||
|
`deflate` encodings. |
||||||
|
|
||||||
|
A new `body` object containing the parsed data is populated on the `request` |
||||||
|
object after the middleware (i.e. `req.body`). |
||||||
|
|
||||||
|
#### Options |
||||||
|
|
||||||
|
The `json` function takes an optional `options` object that may contain any of |
||||||
|
the following keys: |
||||||
|
|
||||||
|
##### inflate |
||||||
|
|
||||||
|
When set to `true`, then deflated (compressed) bodies will be inflated; when |
||||||
|
`false`, deflated bodies are rejected. Defaults to `true`. |
||||||
|
|
||||||
|
##### limit |
||||||
|
|
||||||
|
Controls the maximum request body size. If this is a number, then the value |
||||||
|
specifies the number of bytes; if it is a string, the value is passed to the |
||||||
|
[bytes](https://www.npmjs.com/package/bytes) library for parsing. Defaults |
||||||
|
to `'100kb'`. |
||||||
|
|
||||||
|
##### reviver |
||||||
|
|
||||||
|
The `reviver` option is passed directly to `JSON.parse` as the second |
||||||
|
argument. You can find more information on this argument |
||||||
|
[in the MDN documentation about JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter). |
||||||
|
|
||||||
|
##### strict |
||||||
|
|
||||||
|
When set to `true`, will only accept arrays and objects; when `false` will |
||||||
|
accept anything `JSON.parse` accepts. Defaults to `true`. |
||||||
|
|
||||||
|
##### type |
||||||
|
|
||||||
|
The `type` option is used to determine what media type the middleware will |
||||||
|
parse. This option can be a string, array of strings, or a function. If not a |
||||||
|
function, `type` option is passed directly to the |
||||||
|
[type-is](https://www.npmjs.org/package/type-is#readme) library and this can |
||||||
|
be an extension name (like `json`), a mime type (like `application/json`), or |
||||||
|
a mime type with a wildcard (like `*/*` or `*/json`). If a function, the `type` |
||||||
|
option is called as `fn(req)` and the request is parsed if it returns a truthy |
||||||
|
value. Defaults to `application/json`. |
||||||
|
|
||||||
|
##### verify |
||||||
|
|
||||||
|
The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`, |
||||||
|
where `buf` is a `Buffer` of the raw request body and `encoding` is the |
||||||
|
encoding of the request. The parsing can be aborted by throwing an error. |
||||||
|
|
||||||
|
### bodyParser.raw([options]) |
||||||
|
|
||||||
|
Returns middleware that parses all bodies as a `Buffer` and only looks at |
||||||
|
requests where the `Content-Type` header matches the `type` option. This |
||||||
|
parser supports automatic inflation of `gzip` and `deflate` encodings. |
||||||
|
|
||||||
|
A new `body` object containing the parsed data is populated on the `request` |
||||||
|
object after the middleware (i.e. `req.body`). This will be a `Buffer` object |
||||||
|
of the body. |
||||||
|
|
||||||
|
#### Options |
||||||
|
|
||||||
|
The `raw` function takes an optional `options` object that may contain any of |
||||||
|
the following keys: |
||||||
|
|
||||||
|
##### inflate |
||||||
|
|
||||||
|
When set to `true`, then deflated (compressed) bodies will be inflated; when |
||||||
|
`false`, deflated bodies are rejected. Defaults to `true`. |
||||||
|
|
||||||
|
##### limit |
||||||
|
|
||||||
|
Controls the maximum request body size. If this is a number, then the value |
||||||
|
specifies the number of bytes; if it is a string, the value is passed to the |
||||||
|
[bytes](https://www.npmjs.com/package/bytes) library for parsing. Defaults |
||||||
|
to `'100kb'`. |
||||||
|
|
||||||
|
##### type |
||||||
|
|
||||||
|
The `type` option is used to determine what media type the middleware will |
||||||
|
parse. This option can be a string, array of strings, or a function. |
||||||
|
If not a function, `type` option is passed directly to the |
||||||
|
[type-is](https://www.npmjs.org/package/type-is#readme) library and this |
||||||
|
can be an extension name (like `bin`), a mime type (like |
||||||
|
`application/octet-stream`), or a mime type with a wildcard (like `*/*` or |
||||||
|
`application/*`). If a function, the `type` option is called as `fn(req)` |
||||||
|
and the request is parsed if it returns a truthy value. Defaults to |
||||||
|
`application/octet-stream`. |
||||||
|
|
||||||
|
##### verify |
||||||
|
|
||||||
|
The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`, |
||||||
|
where `buf` is a `Buffer` of the raw request body and `encoding` is the |
||||||
|
encoding of the request. The parsing can be aborted by throwing an error. |
||||||
|
|
||||||
|
### bodyParser.text([options]) |
||||||
|
|
||||||
|
Returns middleware that parses all bodies as a string and only looks at |
||||||
|
requests where the `Content-Type` header matches the `type` option. This |
||||||
|
parser supports automatic inflation of `gzip` and `deflate` encodings. |
||||||
|
|
||||||
|
A new `body` string containing the parsed data is populated on the `request` |
||||||
|
object after the middleware (i.e. `req.body`). This will be a string of the |
||||||
|
body. |
||||||
|
|
||||||
|
#### Options |
||||||
|
|
||||||
|
The `text` function takes an optional `options` object that may contain any of |
||||||
|
the following keys: |
||||||
|
|
||||||
|
##### defaultCharset |
||||||
|
|
||||||
|
Specify the default character set for the text content if the charset is not |
||||||
|
specified in the `Content-Type` header of the request. Defaults to `utf-8`. |
||||||
|
|
||||||
|
##### inflate |
||||||
|
|
||||||
|
When set to `true`, then deflated (compressed) bodies will be inflated; when |
||||||
|
`false`, deflated bodies are rejected. Defaults to `true`. |
||||||
|
|
||||||
|
##### limit |
||||||
|
|
||||||
|
Controls the maximum request body size. If this is a number, then the value |
||||||
|
specifies the number of bytes; if it is a string, the value is passed to the |
||||||
|
[bytes](https://www.npmjs.com/package/bytes) library for parsing. Defaults |
||||||
|
to `'100kb'`. |
||||||
|
|
||||||
|
##### type |
||||||
|
|
||||||
|
The `type` option is used to determine what media type the middleware will |
||||||
|
parse. This option can be a string, array of strings, or a function. If not |
||||||
|
a function, `type` option is passed directly to the |
||||||
|
[type-is](https://www.npmjs.org/package/type-is#readme) library and this can |
||||||
|
be an extension name (like `txt`), a mime type (like `text/plain`), or a mime |
||||||
|
type with a wildcard (like `*/*` or `text/*`). If a function, the `type` |
||||||
|
option is called as `fn(req)` and the request is parsed if it returns a |
||||||
|
truthy value. Defaults to `text/plain`. |
||||||
|
|
||||||
|
##### verify |
||||||
|
|
||||||
|
The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`, |
||||||
|
where `buf` is a `Buffer` of the raw request body and `encoding` is the |
||||||
|
encoding of the request. The parsing can be aborted by throwing an error. |
||||||
|
|
||||||
|
### bodyParser.urlencoded([options]) |
||||||
|
|
||||||
|
Returns middleware that only parses `urlencoded` bodies and only looks at |
||||||
|
requests where the `Content-Type` header matches the `type` option. This |
||||||
|
parser accepts only UTF-8 encoding of the body and supports automatic |
||||||
|
inflation of `gzip` and `deflate` encodings. |
||||||
|
|
||||||
|
A new `body` object containing the parsed data is populated on the `request` |
||||||
|
object after the middleware (i.e. `req.body`). This object will contain |
||||||
|
key-value pairs, where the value can be a string or array (when `extended` is |
||||||
|
`false`), or any type (when `extended` is `true`). |
||||||
|
|
||||||
|
#### Options |
||||||
|
|
||||||
|
The `urlencoded` function takes an optional `options` object that may contain |
||||||
|
any of the following keys: |
||||||
|
|
||||||
|
##### extended |
||||||
|
|
||||||
|
The `extended` option allows to choose between parsing the URL-encoded data |
||||||
|
with the `querystring` library (when `false`) or the `qs` library (when |
||||||
|
`true`). The "extended" syntax allows for rich objects and arrays to be |
||||||
|
encoded into the URL-encoded format, allowing for a JSON-like experience |
||||||
|
with URL-encoded. For more information, please |
||||||
|
[see the qs library](https://www.npmjs.org/package/qs#readme). |
||||||
|
|
||||||
|
Defaults to `true`, but using the default has been deprecated. Please |
||||||
|
research into the difference between `qs` and `querystring` and choose the |
||||||
|
appropriate setting. |
||||||
|
|
||||||
|
##### inflate |
||||||
|
|
||||||
|
When set to `true`, then deflated (compressed) bodies will be inflated; when |
||||||
|
`false`, deflated bodies are rejected. Defaults to `true`. |
||||||
|
|
||||||
|
##### limit |
||||||
|
|
||||||
|
Controls the maximum request body size. If this is a number, then the value |
||||||
|
specifies the number of bytes; if it is a string, the value is passed to the |
||||||
|
[bytes](https://www.npmjs.com/package/bytes) library for parsing. Defaults |
||||||
|
to `'100kb'`. |
||||||
|
|
||||||
|
##### parameterLimit |
||||||
|
|
||||||
|
The `parameterLimit` option controls the maximum number of parameters that |
||||||
|
are allowed in the URL-encoded data. If a request contains more parameters |
||||||
|
than this value, a 413 will be returned to the client. Defaults to `1000`. |
||||||
|
|
||||||
|
##### type |
||||||
|
|
||||||
|
The `type` option is used to determine what media type the middleware will |
||||||
|
parse. This option can be a string, array of strings, or a function. If not |
||||||
|
a function, `type` option is passed directly to the |
||||||
|
[type-is](https://www.npmjs.org/package/type-is#readme) library and this can |
||||||
|
be an extension name (like `urlencoded`), a mime type (like |
||||||
|
`application/x-www-form-urlencoded`), or a mime type with a wildcard (like |
||||||
|
`*/x-www-form-urlencoded`). If a function, the `type` option is called as |
||||||
|
`fn(req)` and the request is parsed if it returns a truthy value. Defaults |
||||||
|
to `application/x-www-form-urlencoded`. |
||||||
|
|
||||||
|
##### verify |
||||||
|
|
||||||
|
The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`, |
||||||
|
where `buf` is a `Buffer` of the raw request body and `encoding` is the |
||||||
|
encoding of the request. The parsing can be aborted by throwing an error. |
||||||
|
|
||||||
|
## Errors |
||||||
|
|
||||||
|
The middlewares provided by this module create errors depending on the error |
||||||
|
condition during parsing. The errors will typically have a `status`/`statusCode` |
||||||
|
property that contains the suggested HTTP response code, an `expose` property |
||||||
|
to determine if the `message` property should be displayed to the client, a |
||||||
|
`type` property to determine the type of error without matching against the |
||||||
|
`message`, and a `body` property containing the read body, if available. |
||||||
|
|
||||||
|
The following are the common errors emitted, though any error can come through |
||||||
|
for various reasons. |
||||||
|
|
||||||
|
### content encoding unsupported |
||||||
|
|
||||||
|
This error will occur when the request had a `Content-Encoding` header that |
||||||
|
contained an encoding but the "inflation" option was set to `false`. The |
||||||
|
`status` property is set to `415`, the `type` property is set to |
||||||
|
`'encoding.unsupported'`, and the `charset` property will be set to the |
||||||
|
encoding that is unsupported. |
||||||
|
|
||||||
|
### request aborted |
||||||
|
|
||||||
|
This error will occur when the request is aborted by the client before reading |
||||||
|
the body has finished. The `received` property will be set to the number of |
||||||
|
bytes received before the request was aborted and the `expected` property is |
||||||
|
set to the number of expected bytes. The `status` property is set to `400` |
||||||
|
and `type` property is set to `'request.aborted'`. |
||||||
|
|
||||||
|
### request entity too large |
||||||
|
|
||||||
|
This error will occur when the request body's size is larger than the "limit" |
||||||
|
option. The `limit` property will be set to the byte limit and the `length` |
||||||
|
property will be set to the request body's length. The `status` property is |
||||||
|
set to `413` and the `type` property is set to `'entity.too.large'`. |
||||||
|
|
||||||
|
### request size did not match content length |
||||||
|
|
||||||
|
This error will occur when the request's length did not match the length from |
||||||
|
the `Content-Length` header. This typically occurs when the request is malformed, |
||||||
|
typically when the `Content-Length` header was calculated based on characters |
||||||
|
instead of bytes. The `status` property is set to `400` and the `type` property |
||||||
|
is set to `'request.size.invalid'`. |
||||||
|
|
||||||
|
### stream encoding should not be set |
||||||
|
|
||||||
|
This error will occur when something called the `req.setEncoding` method prior |
||||||
|
to this middleware. This module operates directly on bytes only and you cannot |
||||||
|
call `req.setEncoding` when using this module. The `status` property is set to |
||||||
|
`500` and the `type` property is set to `'stream.encoding.set'`. |
||||||
|
|
||||||
|
### too many parameters |
||||||
|
|
||||||
|
This error will occur when the content of the request exceeds the configured |
||||||
|
`parameterLimit` for the `urlencoded` parser. The `status` property is set to |
||||||
|
`413` and the `type` property is set to `'parameters.too.many'`. |
||||||
|
|
||||||
|
### unsupported charset "BOGUS" |
||||||
|
|
||||||
|
This error will occur when the request had a charset parameter in the |
||||||
|
`Content-Type` header, but the `iconv-lite` module does not support it OR the |
||||||
|
parser does not support it. The charset is contained in the message as well |
||||||
|
as in the `charset` property. The `status` property is set to `415`, the |
||||||
|
`type` property is set to `'charset.unsupported'`, and the `charset` property |
||||||
|
is set to the charset that is unsupported. |
||||||
|
|
||||||
|
### unsupported content encoding "bogus" |
||||||
|
|
||||||
|
This error will occur when the request had a `Content-Encoding` header that |
||||||
|
contained an unsupported encoding. The encoding is contained in the message |
||||||
|
as well as in the `encoding` property. The `status` property is set to `415`, |
||||||
|
the `type` property is set to `'encoding.unsupported'`, and the `encoding` |
||||||
|
property is set to the encoding that is unsupported. |
||||||
|
|
||||||
|
## Examples |
||||||
|
|
||||||
|
### Express/Connect top-level generic |
||||||
|
|
||||||
|
This example demonstrates adding a generic JSON and URL-encoded parser as a |
||||||
|
top-level middleware, which will parse the bodies of all incoming requests. |
||||||
|
This is the simplest setup. |
||||||
|
|
||||||
|
```js |
||||||
|
var express = require('express') |
||||||
|
var bodyParser = require('body-parser') |
||||||
|
|
||||||
|
var app = express() |
||||||
|
|
||||||
|
// parse application/x-www-form-urlencoded |
||||||
|
app.use(bodyParser.urlencoded({ extended: false })) |
||||||
|
|
||||||
|
// parse application/json |
||||||
|
app.use(bodyParser.json()) |
||||||
|
|
||||||
|
app.use(function (req, res) { |
||||||
|
res.setHeader('Content-Type', 'text/plain') |
||||||
|
res.write('you posted:\n') |
||||||
|
res.end(JSON.stringify(req.body, null, 2)) |
||||||
|
}) |
||||||
|
``` |
||||||
|
|
||||||
|
### Express route-specific |
||||||
|
|
||||||
|
This example demonstrates adding body parsers specifically to the routes that |
||||||
|
need them. In general, this is the most recommended way to use body-parser with |
||||||
|
Express. |
||||||
|
|
||||||
|
```js |
||||||
|
var express = require('express') |
||||||
|
var bodyParser = require('body-parser') |
||||||
|
|
||||||
|
var app = express() |
||||||
|
|
||||||
|
// create application/json parser |
||||||
|
var jsonParser = bodyParser.json() |
||||||
|
|
||||||
|
// create application/x-www-form-urlencoded parser |
||||||
|
var urlencodedParser = bodyParser.urlencoded({ extended: false }) |
||||||
|
|
||||||
|
// POST /login gets urlencoded bodies |
||||||
|
app.post('/login', urlencodedParser, function (req, res) { |
||||||
|
res.send('welcome, ' + req.body.username) |
||||||
|
}) |
||||||
|
|
||||||
|
// POST /api/users gets JSON bodies |
||||||
|
app.post('/api/users', jsonParser, function (req, res) { |
||||||
|
// create user in req.body |
||||||
|
}) |
||||||
|
``` |
||||||
|
|
||||||
|
### Change accepted type for parsers |
||||||
|
|
||||||
|
All the parsers accept a `type` option which allows you to change the |
||||||
|
`Content-Type` that the middleware will parse. |
||||||
|
|
||||||
|
```js |
||||||
|
var express = require('express') |
||||||
|
var bodyParser = require('body-parser') |
||||||
|
|
||||||
|
var app = express() |
||||||
|
|
||||||
|
// parse various different custom JSON types as JSON |
||||||
|
app.use(bodyParser.json({ type: 'application/*+json' })) |
||||||
|
|
||||||
|
// parse some custom thing into a Buffer |
||||||
|
app.use(bodyParser.raw({ type: 'application/vnd.custom-type' })) |
||||||
|
|
||||||
|
// parse an HTML body into a string |
||||||
|
app.use(bodyParser.text({ type: 'text/html' })) |
||||||
|
``` |
||||||
|
|
||||||
|
## License |
||||||
|
|
||||||
|
[MIT](LICENSE) |
||||||
|
|
||||||
|
[npm-image]: https://img.shields.io/npm/v/body-parser.svg |
||||||
|
[npm-url]: https://npmjs.org/package/body-parser |
||||||
|
[travis-image]: https://img.shields.io/travis/expressjs/body-parser/master.svg |
||||||
|
[travis-url]: https://travis-ci.org/expressjs/body-parser |
||||||
|
[coveralls-image]: https://img.shields.io/coveralls/expressjs/body-parser/master.svg |
||||||
|
[coveralls-url]: https://coveralls.io/r/expressjs/body-parser?branch=master |
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/body-parser.svg |
||||||
|
[downloads-url]: https://npmjs.org/package/body-parser |
@ -0,0 +1,157 @@ |
|||||||
|
/*! |
||||||
|
* body-parser |
||||||
|
* Copyright(c) 2014-2015 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var deprecate = require('depd')('body-parser') |
||||||
|
|
||||||
|
/** |
||||||
|
* Cache of loaded parsers. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var parsers = Object.create(null) |
||||||
|
|
||||||
|
/** |
||||||
|
* @typedef Parsers |
||||||
|
* @type {function} |
||||||
|
* @property {function} json |
||||||
|
* @property {function} raw |
||||||
|
* @property {function} text |
||||||
|
* @property {function} urlencoded |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
* @type {Parsers} |
||||||
|
*/ |
||||||
|
|
||||||
|
exports = module.exports = deprecate.function(bodyParser, |
||||||
|
'bodyParser: use individual json/urlencoded middlewares') |
||||||
|
|
||||||
|
/** |
||||||
|
* JSON parser. |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
Object.defineProperty(exports, 'json', { |
||||||
|
configurable: true, |
||||||
|
enumerable: true, |
||||||
|
get: createParserGetter('json') |
||||||
|
}) |
||||||
|
|
||||||
|
/** |
||||||
|
* Raw parser. |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
Object.defineProperty(exports, 'raw', { |
||||||
|
configurable: true, |
||||||
|
enumerable: true, |
||||||
|
get: createParserGetter('raw') |
||||||
|
}) |
||||||
|
|
||||||
|
/** |
||||||
|
* Text parser. |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
Object.defineProperty(exports, 'text', { |
||||||
|
configurable: true, |
||||||
|
enumerable: true, |
||||||
|
get: createParserGetter('text') |
||||||
|
}) |
||||||
|
|
||||||
|
/** |
||||||
|
* URL-encoded parser. |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
Object.defineProperty(exports, 'urlencoded', { |
||||||
|
configurable: true, |
||||||
|
enumerable: true, |
||||||
|
get: createParserGetter('urlencoded') |
||||||
|
}) |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a middleware to parse json and urlencoded bodies. |
||||||
|
* |
||||||
|
* @param {object} [options] |
||||||
|
* @return {function} |
||||||
|
* @deprecated |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function bodyParser (options) { |
||||||
|
var opts = {} |
||||||
|
|
||||||
|
// exclude type option
|
||||||
|
if (options) { |
||||||
|
for (var prop in options) { |
||||||
|
if (prop !== 'type') { |
||||||
|
opts[prop] = options[prop] |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var _urlencoded = exports.urlencoded(opts) |
||||||
|
var _json = exports.json(opts) |
||||||
|
|
||||||
|
return function bodyParser (req, res, next) { |
||||||
|
_json(req, res, function (err) { |
||||||
|
if (err) return next(err) |
||||||
|
_urlencoded(req, res, next) |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a getter for loading a parser. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function createParserGetter (name) { |
||||||
|
return function get () { |
||||||
|
return loadParser(name) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Load a parser module. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function loadParser (parserName) { |
||||||
|
var parser = parsers[parserName] |
||||||
|
|
||||||
|
if (parser !== undefined) { |
||||||
|
return parser |
||||||
|
} |
||||||
|
|
||||||
|
// this uses a switch for static require analysis
|
||||||
|
switch (parserName) { |
||||||
|
case 'json': |
||||||
|
parser = require('./lib/types/json') |
||||||
|
break |
||||||
|
case 'raw': |
||||||
|
parser = require('./lib/types/raw') |
||||||
|
break |
||||||
|
case 'text': |
||||||
|
parser = require('./lib/types/text') |
||||||
|
break |
||||||
|
case 'urlencoded': |
||||||
|
parser = require('./lib/types/urlencoded') |
||||||
|
break |
||||||
|
} |
||||||
|
|
||||||
|
// store to prevent invoking require()
|
||||||
|
return (parsers[parserName] = parser) |
||||||
|
} |
@ -0,0 +1,181 @@ |
|||||||
|
/*! |
||||||
|
* body-parser |
||||||
|
* Copyright(c) 2014-2015 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var createError = require('http-errors') |
||||||
|
var getBody = require('raw-body') |
||||||
|
var iconv = require('iconv-lite') |
||||||
|
var onFinished = require('on-finished') |
||||||
|
var zlib = require('zlib') |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
*/ |
||||||
|
|
||||||
|
module.exports = read |
||||||
|
|
||||||
|
/** |
||||||
|
* Read a request into a buffer and parse. |
||||||
|
* |
||||||
|
* @param {object} req |
||||||
|
* @param {object} res |
||||||
|
* @param {function} next |
||||||
|
* @param {function} parse |
||||||
|
* @param {function} debug |
||||||
|
* @param {object} options |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function read (req, res, next, parse, debug, options) { |
||||||
|
var length |
||||||
|
var opts = options |
||||||
|
var stream |
||||||
|
|
||||||
|
// flag as parsed
|
||||||
|
req._body = true |
||||||
|
|
||||||
|
// read options
|
||||||
|
var encoding = opts.encoding !== null |
||||||
|
? opts.encoding |
||||||
|
: null |
||||||
|
var verify = opts.verify |
||||||
|
|
||||||
|
try { |
||||||
|
// get the content stream
|
||||||
|
stream = contentstream(req, debug, opts.inflate) |
||||||
|
length = stream.length |
||||||
|
stream.length = undefined |
||||||
|
} catch (err) { |
||||||
|
return next(err) |
||||||
|
} |
||||||
|
|
||||||
|
// set raw-body options
|
||||||
|
opts.length = length |
||||||
|
opts.encoding = verify |
||||||
|
? null |
||||||
|
: encoding |
||||||
|
|
||||||
|
// assert charset is supported
|
||||||
|
if (opts.encoding === null && encoding !== null && !iconv.encodingExists(encoding)) { |
||||||
|
return next(createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', { |
||||||
|
charset: encoding.toLowerCase(), |
||||||
|
type: 'charset.unsupported' |
||||||
|
})) |
||||||
|
} |
||||||
|
|
||||||
|
// read body
|
||||||
|
debug('read body') |
||||||
|
getBody(stream, opts, function (error, body) { |
||||||
|
if (error) { |
||||||
|
var _error |
||||||
|
|
||||||
|
if (error.type === 'encoding.unsupported') { |
||||||
|
// echo back charset
|
||||||
|
_error = createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', { |
||||||
|
charset: encoding.toLowerCase(), |
||||||
|
type: 'charset.unsupported' |
||||||
|
}) |
||||||
|
} else { |
||||||
|
// set status code on error
|
||||||
|
_error = createError(400, error) |
||||||
|
} |
||||||
|
|
||||||
|
// read off entire request
|
||||||
|
stream.resume() |
||||||
|
onFinished(req, function onfinished () { |
||||||
|
next(createError(400, _error)) |
||||||
|
}) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// verify
|
||||||
|
if (verify) { |
||||||
|
try { |
||||||
|
debug('verify body') |
||||||
|
verify(req, res, body, encoding) |
||||||
|
} catch (err) { |
||||||
|
next(createError(403, err, { |
||||||
|
body: body, |
||||||
|
type: err.type || 'entity.verify.failed' |
||||||
|
})) |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// parse
|
||||||
|
var str = body |
||||||
|
try { |
||||||
|
debug('parse body') |
||||||
|
str = typeof body !== 'string' && encoding !== null |
||||||
|
? iconv.decode(body, encoding) |
||||||
|
: body |
||||||
|
req.body = parse(str) |
||||||
|
} catch (err) { |
||||||
|
next(createError(400, err, { |
||||||
|
body: str, |
||||||
|
type: err.type || 'entity.parse.failed' |
||||||
|
})) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
next() |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the content stream of the request. |
||||||
|
* |
||||||
|
* @param {object} req |
||||||
|
* @param {function} debug |
||||||
|
* @param {boolean} [inflate=true] |
||||||
|
* @return {object} |
||||||
|
* @api private |
||||||
|
*/ |
||||||
|
|
||||||
|
function contentstream (req, debug, inflate) { |
||||||
|
var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase() |
||||||
|
var length = req.headers['content-length'] |
||||||
|
var stream |
||||||
|
|
||||||
|
debug('content-encoding "%s"', encoding) |
||||||
|
|
||||||
|
if (inflate === false && encoding !== 'identity') { |
||||||
|
throw createError(415, 'content encoding unsupported', { |
||||||
|
encoding: encoding, |
||||||
|
type: 'encoding.unsupported' |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
switch (encoding) { |
||||||
|
case 'deflate': |
||||||
|
stream = zlib.createInflate() |
||||||
|
debug('inflate body') |
||||||
|
req.pipe(stream) |
||||||
|
break |
||||||
|
case 'gzip': |
||||||
|
stream = zlib.createGunzip() |
||||||
|
debug('gunzip body') |
||||||
|
req.pipe(stream) |
||||||
|
break |
||||||
|
case 'identity': |
||||||
|
stream = req |
||||||
|
stream.length = length |
||||||
|
break |
||||||
|
default: |
||||||
|
throw createError(415, 'unsupported content encoding "' + encoding + '"', { |
||||||
|
encoding: encoding, |
||||||
|
type: 'encoding.unsupported' |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
return stream |
||||||
|
} |
@ -0,0 +1,230 @@ |
|||||||
|
/*! |
||||||
|
* body-parser |
||||||
|
* Copyright(c) 2014 Jonathan Ong |
||||||
|
* Copyright(c) 2014-2015 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var bytes = require('bytes') |
||||||
|
var contentType = require('content-type') |
||||||
|
var createError = require('http-errors') |
||||||
|
var debug = require('debug')('body-parser:json') |
||||||
|
var read = require('../read') |
||||||
|
var typeis = require('type-is') |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
*/ |
||||||
|
|
||||||
|
module.exports = json |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match the first non-space in a string. |
||||||
|
* |
||||||
|
* Allowed whitespace is defined in RFC 7159: |
||||||
|
* |
||||||
|
* ws = *( |
||||||
|
* %x20 / ; Space |
||||||
|
* %x09 / ; Horizontal tab |
||||||
|
* %x0A / ; Line feed or New line |
||||||
|
* %x0D ) ; Carriage return |
||||||
|
*/ |
||||||
|
|
||||||
|
var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*(.)/ // eslint-disable-line no-control-regex
|
||||||
|
|
||||||
|
/** |
||||||
|
* Create a middleware to parse JSON bodies. |
||||||
|
* |
||||||
|
* @param {object} [options] |
||||||
|
* @return {function} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function json (options) { |
||||||
|
var opts = options || {} |
||||||
|
|
||||||
|
var limit = typeof opts.limit !== 'number' |
||||||
|
? bytes.parse(opts.limit || '100kb') |
||||||
|
: opts.limit |
||||||
|
var inflate = opts.inflate !== false |
||||||
|
var reviver = opts.reviver |
||||||
|
var strict = opts.strict !== false |
||||||
|
var type = opts.type || 'application/json' |
||||||
|
var verify = opts.verify || false |
||||||
|
|
||||||
|
if (verify !== false && typeof verify !== 'function') { |
||||||
|
throw new TypeError('option verify must be function') |
||||||
|
} |
||||||
|
|
||||||
|
// create the appropriate type checking function
|
||||||
|
var shouldParse = typeof type !== 'function' |
||||||
|
? typeChecker(type) |
||||||
|
: type |
||||||
|
|
||||||
|
function parse (body) { |
||||||
|
if (body.length === 0) { |
||||||
|
// special-case empty json body, as it's a common client-side mistake
|
||||||
|
// TODO: maybe make this configurable or part of "strict" option
|
||||||
|
return {} |
||||||
|
} |
||||||
|
|
||||||
|
if (strict) { |
||||||
|
var first = firstchar(body) |
||||||
|
|
||||||
|
if (first !== '{' && first !== '[') { |
||||||
|
debug('strict violation') |
||||||
|
throw createStrictSyntaxError(body, first) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
debug('parse json') |
||||||
|
return JSON.parse(body, reviver) |
||||||
|
} catch (e) { |
||||||
|
throw normalizeJsonSyntaxError(e, { |
||||||
|
message: e.message, |
||||||
|
stack: e.stack |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return function jsonParser (req, res, next) { |
||||||
|
if (req._body) { |
||||||
|
debug('body already parsed') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
req.body = req.body || {} |
||||||
|
|
||||||
|
// skip requests without bodies
|
||||||
|
if (!typeis.hasBody(req)) { |
||||||
|
debug('skip empty body') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
debug('content-type %j', req.headers['content-type']) |
||||||
|
|
||||||
|
// determine if request should be parsed
|
||||||
|
if (!shouldParse(req)) { |
||||||
|
debug('skip parsing') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// assert charset per RFC 7159 sec 8.1
|
||||||
|
var charset = getCharset(req) || 'utf-8' |
||||||
|
if (charset.substr(0, 4) !== 'utf-') { |
||||||
|
debug('invalid charset') |
||||||
|
next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', { |
||||||
|
charset: charset, |
||||||
|
type: 'charset.unsupported' |
||||||
|
})) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// read
|
||||||
|
read(req, res, next, parse, debug, { |
||||||
|
encoding: charset, |
||||||
|
inflate: inflate, |
||||||
|
limit: limit, |
||||||
|
verify: verify |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create strict violation syntax error matching native error. |
||||||
|
* |
||||||
|
* @param {string} str |
||||||
|
* @param {string} char |
||||||
|
* @return {Error} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function createStrictSyntaxError (str, char) { |
||||||
|
var index = str.indexOf(char) |
||||||
|
var partial = str.substring(0, index) + '#' |
||||||
|
|
||||||
|
try { |
||||||
|
JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation') |
||||||
|
} catch (e) { |
||||||
|
return normalizeJsonSyntaxError(e, { |
||||||
|
message: e.message.replace('#', char), |
||||||
|
stack: e.stack |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the first non-whitespace character in a string. |
||||||
|
* |
||||||
|
* @param {string} str |
||||||
|
* @return {function} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function firstchar (str) { |
||||||
|
return FIRST_CHAR_REGEXP.exec(str)[1] |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the charset of a request. |
||||||
|
* |
||||||
|
* @param {object} req |
||||||
|
* @api private |
||||||
|
*/ |
||||||
|
|
||||||
|
function getCharset (req) { |
||||||
|
try { |
||||||
|
return (contentType.parse(req).parameters.charset || '').toLowerCase() |
||||||
|
} catch (e) { |
||||||
|
return undefined |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Normalize a SyntaxError for JSON.parse. |
||||||
|
* |
||||||
|
* @param {SyntaxError} error |
||||||
|
* @param {object} obj |
||||||
|
* @return {SyntaxError} |
||||||
|
*/ |
||||||
|
|
||||||
|
function normalizeJsonSyntaxError (error, obj) { |
||||||
|
var keys = Object.getOwnPropertyNames(error) |
||||||
|
|
||||||
|
for (var i = 0; i < keys.length; i++) { |
||||||
|
var key = keys[i] |
||||||
|
if (key !== 'stack' && key !== 'message') { |
||||||
|
delete error[key] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// replace stack before message for Node.js 0.10 and below
|
||||||
|
error.stack = obj.stack.replace(error.message, obj.message) |
||||||
|
error.message = obj.message |
||||||
|
|
||||||
|
return error |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the simple type checker. |
||||||
|
* |
||||||
|
* @param {string} type |
||||||
|
* @return {function} |
||||||
|
*/ |
||||||
|
|
||||||
|
function typeChecker (type) { |
||||||
|
return function checkType (req) { |
||||||
|
return Boolean(typeis(req, type)) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,101 @@ |
|||||||
|
/*! |
||||||
|
* body-parser |
||||||
|
* Copyright(c) 2014-2015 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
*/ |
||||||
|
|
||||||
|
var bytes = require('bytes') |
||||||
|
var debug = require('debug')('body-parser:raw') |
||||||
|
var read = require('../read') |
||||||
|
var typeis = require('type-is') |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
*/ |
||||||
|
|
||||||
|
module.exports = raw |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a middleware to parse raw bodies. |
||||||
|
* |
||||||
|
* @param {object} [options] |
||||||
|
* @return {function} |
||||||
|
* @api public |
||||||
|
*/ |
||||||
|
|
||||||
|
function raw (options) { |
||||||
|
var opts = options || {} |
||||||
|
|
||||||
|
var inflate = opts.inflate !== false |
||||||
|
var limit = typeof opts.limit !== 'number' |
||||||
|
? bytes.parse(opts.limit || '100kb') |
||||||
|
: opts.limit |
||||||
|
var type = opts.type || 'application/octet-stream' |
||||||
|
var verify = opts.verify || false |
||||||
|
|
||||||
|
if (verify !== false && typeof verify !== 'function') { |
||||||
|
throw new TypeError('option verify must be function') |
||||||
|
} |
||||||
|
|
||||||
|
// create the appropriate type checking function
|
||||||
|
var shouldParse = typeof type !== 'function' |
||||||
|
? typeChecker(type) |
||||||
|
: type |
||||||
|
|
||||||
|
function parse (buf) { |
||||||
|
return buf |
||||||
|
} |
||||||
|
|
||||||
|
return function rawParser (req, res, next) { |
||||||
|
if (req._body) { |
||||||
|
debug('body already parsed') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
req.body = req.body || {} |
||||||
|
|
||||||
|
// skip requests without bodies
|
||||||
|
if (!typeis.hasBody(req)) { |
||||||
|
debug('skip empty body') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
debug('content-type %j', req.headers['content-type']) |
||||||
|
|
||||||
|
// determine if request should be parsed
|
||||||
|
if (!shouldParse(req)) { |
||||||
|
debug('skip parsing') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// read
|
||||||
|
read(req, res, next, parse, debug, { |
||||||
|
encoding: null, |
||||||
|
inflate: inflate, |
||||||
|
limit: limit, |
||||||
|
verify: verify |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the simple type checker. |
||||||
|
* |
||||||
|
* @param {string} type |
||||||
|
* @return {function} |
||||||
|
*/ |
||||||
|
|
||||||
|
function typeChecker (type) { |
||||||
|
return function checkType (req) { |
||||||
|
return Boolean(typeis(req, type)) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,121 @@ |
|||||||
|
/*! |
||||||
|
* body-parser |
||||||
|
* Copyright(c) 2014-2015 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
*/ |
||||||
|
|
||||||
|
var bytes = require('bytes') |
||||||
|
var contentType = require('content-type') |
||||||
|
var debug = require('debug')('body-parser:text') |
||||||
|
var read = require('../read') |
||||||
|
var typeis = require('type-is') |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
*/ |
||||||
|
|
||||||
|
module.exports = text |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a middleware to parse text bodies. |
||||||
|
* |
||||||
|
* @param {object} [options] |
||||||
|
* @return {function} |
||||||
|
* @api public |
||||||
|
*/ |
||||||
|
|
||||||
|
function text (options) { |
||||||
|
var opts = options || {} |
||||||
|
|
||||||
|
var defaultCharset = opts.defaultCharset || 'utf-8' |
||||||
|
var inflate = opts.inflate !== false |
||||||
|
var limit = typeof opts.limit !== 'number' |
||||||
|
? bytes.parse(opts.limit || '100kb') |
||||||
|
: opts.limit |
||||||
|
var type = opts.type || 'text/plain' |
||||||
|
var verify = opts.verify || false |
||||||
|
|
||||||
|
if (verify !== false && typeof verify !== 'function') { |
||||||
|
throw new TypeError('option verify must be function') |
||||||
|
} |
||||||
|
|
||||||
|
// create the appropriate type checking function
|
||||||
|
var shouldParse = typeof type !== 'function' |
||||||
|
? typeChecker(type) |
||||||
|
: type |
||||||
|
|
||||||
|
function parse (buf) { |
||||||
|
return buf |
||||||
|
} |
||||||
|
|
||||||
|
return function textParser (req, res, next) { |
||||||
|
if (req._body) { |
||||||
|
debug('body already parsed') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
req.body = req.body || {} |
||||||
|
|
||||||
|
// skip requests without bodies
|
||||||
|
if (!typeis.hasBody(req)) { |
||||||
|
debug('skip empty body') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
debug('content-type %j', req.headers['content-type']) |
||||||
|
|
||||||
|
// determine if request should be parsed
|
||||||
|
if (!shouldParse(req)) { |
||||||
|
debug('skip parsing') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// get charset
|
||||||
|
var charset = getCharset(req) || defaultCharset |
||||||
|
|
||||||
|
// read
|
||||||
|
read(req, res, next, parse, debug, { |
||||||
|
encoding: charset, |
||||||
|
inflate: inflate, |
||||||
|
limit: limit, |
||||||
|
verify: verify |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the charset of a request. |
||||||
|
* |
||||||
|
* @param {object} req |
||||||
|
* @api private |
||||||
|
*/ |
||||||
|
|
||||||
|
function getCharset (req) { |
||||||
|
try { |
||||||
|
return (contentType.parse(req).parameters.charset || '').toLowerCase() |
||||||
|
} catch (e) { |
||||||
|
return undefined |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the simple type checker. |
||||||
|
* |
||||||
|
* @param {string} type |
||||||
|
* @return {function} |
||||||
|
*/ |
||||||
|
|
||||||
|
function typeChecker (type) { |
||||||
|
return function checkType (req) { |
||||||
|
return Boolean(typeis(req, type)) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,284 @@ |
|||||||
|
/*! |
||||||
|
* body-parser |
||||||
|
* Copyright(c) 2014 Jonathan Ong |
||||||
|
* Copyright(c) 2014-2015 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var bytes = require('bytes') |
||||||
|
var contentType = require('content-type') |
||||||
|
var createError = require('http-errors') |
||||||
|
var debug = require('debug')('body-parser:urlencoded') |
||||||
|
var deprecate = require('depd')('body-parser') |
||||||
|
var read = require('../read') |
||||||
|
var typeis = require('type-is') |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
*/ |
||||||
|
|
||||||
|
module.exports = urlencoded |
||||||
|
|
||||||
|
/** |
||||||
|
* Cache of parser modules. |
||||||
|
*/ |
||||||
|
|
||||||
|
var parsers = Object.create(null) |
||||||
|
|
||||||
|
/** |
||||||
|
* Create a middleware to parse urlencoded bodies. |
||||||
|
* |
||||||
|
* @param {object} [options] |
||||||
|
* @return {function} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function urlencoded (options) { |
||||||
|
var opts = options || {} |
||||||
|
|
||||||
|
// notice because option default will flip in next major
|
||||||
|
if (opts.extended === undefined) { |
||||||
|
deprecate('undefined extended: provide extended option') |
||||||
|
} |
||||||
|
|
||||||
|
var extended = opts.extended !== false |
||||||
|
var inflate = opts.inflate !== false |
||||||
|
var limit = typeof opts.limit !== 'number' |
||||||
|
? bytes.parse(opts.limit || '100kb') |
||||||
|
: opts.limit |
||||||
|
var type = opts.type || 'application/x-www-form-urlencoded' |
||||||
|
var verify = opts.verify || false |
||||||
|
|
||||||
|
if (verify !== false && typeof verify !== 'function') { |
||||||
|
throw new TypeError('option verify must be function') |
||||||
|
} |
||||||
|
|
||||||
|
// create the appropriate query parser
|
||||||
|
var queryparse = extended |
||||||
|
? extendedparser(opts) |
||||||
|
: simpleparser(opts) |
||||||
|
|
||||||
|
// create the appropriate type checking function
|
||||||
|
var shouldParse = typeof type !== 'function' |
||||||
|
? typeChecker(type) |
||||||
|
: type |
||||||
|
|
||||||
|
function parse (body) { |
||||||
|
return body.length |
||||||
|
? queryparse(body) |
||||||
|
: {} |
||||||
|
} |
||||||
|
|
||||||
|
return function urlencodedParser (req, res, next) { |
||||||
|
if (req._body) { |
||||||
|
debug('body already parsed') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
req.body = req.body || {} |
||||||
|
|
||||||
|
// skip requests without bodies
|
||||||
|
if (!typeis.hasBody(req)) { |
||||||
|
debug('skip empty body') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
debug('content-type %j', req.headers['content-type']) |
||||||
|
|
||||||
|
// determine if request should be parsed
|
||||||
|
if (!shouldParse(req)) { |
||||||
|
debug('skip parsing') |
||||||
|
next() |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// assert charset
|
||||||
|
var charset = getCharset(req) || 'utf-8' |
||||||
|
if (charset !== 'utf-8') { |
||||||
|
debug('invalid charset') |
||||||
|
next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', { |
||||||
|
charset: charset, |
||||||
|
type: 'charset.unsupported' |
||||||
|
})) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// read
|
||||||
|
read(req, res, next, parse, debug, { |
||||||
|
debug: debug, |
||||||
|
encoding: charset, |
||||||
|
inflate: inflate, |
||||||
|
limit: limit, |
||||||
|
verify: verify |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the extended query parser. |
||||||
|
* |
||||||
|
* @param {object} options |
||||||
|
*/ |
||||||
|
|
||||||
|
function extendedparser (options) { |
||||||
|
var parameterLimit = options.parameterLimit !== undefined |
||||||
|
? options.parameterLimit |
||||||
|
: 1000 |
||||||
|
var parse = parser('qs') |
||||||
|
|
||||||
|
if (isNaN(parameterLimit) || parameterLimit < 1) { |
||||||
|
throw new TypeError('option parameterLimit must be a positive number') |
||||||
|
} |
||||||
|
|
||||||
|
if (isFinite(parameterLimit)) { |
||||||
|
parameterLimit = parameterLimit | 0 |
||||||
|
} |
||||||
|
|
||||||
|
return function queryparse (body) { |
||||||
|
var paramCount = parameterCount(body, parameterLimit) |
||||||
|
|
||||||
|
if (paramCount === undefined) { |
||||||
|
debug('too many parameters') |
||||||
|
throw createError(413, 'too many parameters', { |
||||||
|
type: 'parameters.too.many' |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
var arrayLimit = Math.max(100, paramCount) |
||||||
|
|
||||||
|
debug('parse extended urlencoding') |
||||||
|
return parse(body, { |
||||||
|
allowPrototypes: true, |
||||||
|
arrayLimit: arrayLimit, |
||||||
|
depth: Infinity, |
||||||
|
parameterLimit: parameterLimit |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the charset of a request. |
||||||
|
* |
||||||
|
* @param {object} req |
||||||
|
* @api private |
||||||
|
*/ |
||||||
|
|
||||||
|
function getCharset (req) { |
||||||
|
try { |
||||||
|
return (contentType.parse(req).parameters.charset || '').toLowerCase() |
||||||
|
} catch (e) { |
||||||
|
return undefined |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Count the number of parameters, stopping once limit reached |
||||||
|
* |
||||||
|
* @param {string} body |
||||||
|
* @param {number} limit |
||||||
|
* @api private |
||||||
|
*/ |
||||||
|
|
||||||
|
function parameterCount (body, limit) { |
||||||
|
var count = 0 |
||||||
|
var index = 0 |
||||||
|
|
||||||
|
while ((index = body.indexOf('&', index)) !== -1) { |
||||||
|
count++ |
||||||
|
index++ |
||||||
|
|
||||||
|
if (count === limit) { |
||||||
|
return undefined |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return count |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get parser for module name dynamically. |
||||||
|
* |
||||||
|
* @param {string} name |
||||||
|
* @return {function} |
||||||
|
* @api private |
||||||
|
*/ |
||||||
|
|
||||||
|
function parser (name) { |
||||||
|
var mod = parsers[name] |
||||||
|
|
||||||
|
if (mod !== undefined) { |
||||||
|
return mod.parse |
||||||
|
} |
||||||
|
|
||||||
|
// this uses a switch for static require analysis
|
||||||
|
switch (name) { |
||||||
|
case 'qs': |
||||||
|
mod = require('qs') |
||||||
|
break |
||||||
|
case 'querystring': |
||||||
|
mod = require('querystring') |
||||||
|
break |
||||||
|
} |
||||||
|
|
||||||
|
// store to prevent invoking require()
|
||||||
|
parsers[name] = mod |
||||||
|
|
||||||
|
return mod.parse |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the simple query parser. |
||||||
|
* |
||||||
|
* @param {object} options |
||||||
|
*/ |
||||||
|
|
||||||
|
function simpleparser (options) { |
||||||
|
var parameterLimit = options.parameterLimit !== undefined |
||||||
|
? options.parameterLimit |
||||||
|
: 1000 |
||||||
|
var parse = parser('querystring') |
||||||
|
|
||||||
|
if (isNaN(parameterLimit) || parameterLimit < 1) { |
||||||
|
throw new TypeError('option parameterLimit must be a positive number') |
||||||
|
} |
||||||
|
|
||||||
|
if (isFinite(parameterLimit)) { |
||||||
|
parameterLimit = parameterLimit | 0 |
||||||
|
} |
||||||
|
|
||||||
|
return function queryparse (body) { |
||||||
|
var paramCount = parameterCount(body, parameterLimit) |
||||||
|
|
||||||
|
if (paramCount === undefined) { |
||||||
|
debug('too many parameters') |
||||||
|
throw createError(413, 'too many parameters', { |
||||||
|
type: 'parameters.too.many' |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
debug('parse urlencoding') |
||||||
|
return parse(body, undefined, undefined, { maxKeys: parameterLimit }) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the simple type checker. |
||||||
|
* |
||||||
|
* @param {string} type |
||||||
|
* @return {function} |
||||||
|
*/ |
||||||
|
|
||||||
|
function typeChecker (type) { |
||||||
|
return function checkType (req) { |
||||||
|
return Boolean(typeis(req, type)) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,91 @@ |
|||||||
|
{ |
||||||
|
"_from": "body-parser@1.19.0", |
||||||
|
"_id": "body-parser@1.19.0", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", |
||||||
|
"_location": "/body-parser", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "version", |
||||||
|
"registry": true, |
||||||
|
"raw": "body-parser@1.19.0", |
||||||
|
"name": "body-parser", |
||||||
|
"escapedName": "body-parser", |
||||||
|
"rawSpec": "1.19.0", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "1.19.0" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/express" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", |
||||||
|
"_shasum": "96b2709e57c9c4e09a6fd66a8fd979844f69f08a", |
||||||
|
"_spec": "body-parser@1.19.0", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\express", |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/expressjs/body-parser/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"contributors": [ |
||||||
|
{ |
||||||
|
"name": "Douglas Christopher Wilson", |
||||||
|
"email": "doug@somethingdoug.com" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"name": "Jonathan Ong", |
||||||
|
"email": "me@jongleberry.com", |
||||||
|
"url": "http://jongleberry.com" |
||||||
|
} |
||||||
|
], |
||||||
|
"dependencies": { |
||||||
|
"bytes": "3.1.0", |
||||||
|
"content-type": "~1.0.4", |
||||||
|
"debug": "2.6.9", |
||||||
|
"depd": "~1.1.2", |
||||||
|
"http-errors": "1.7.2", |
||||||
|
"iconv-lite": "0.4.24", |
||||||
|
"on-finished": "~2.3.0", |
||||||
|
"qs": "6.7.0", |
||||||
|
"raw-body": "2.4.0", |
||||||
|
"type-is": "~1.6.17" |
||||||
|
}, |
||||||
|
"deprecated": false, |
||||||
|
"description": "Node.js body parsing middleware", |
||||||
|
"devDependencies": { |
||||||
|
"eslint": "5.16.0", |
||||||
|
"eslint-config-standard": "12.0.0", |
||||||
|
"eslint-plugin-import": "2.17.2", |
||||||
|
"eslint-plugin-markdown": "1.0.0", |
||||||
|
"eslint-plugin-node": "8.0.1", |
||||||
|
"eslint-plugin-promise": "4.1.1", |
||||||
|
"eslint-plugin-standard": "4.0.0", |
||||||
|
"istanbul": "0.4.5", |
||||||
|
"methods": "1.1.2", |
||||||
|
"mocha": "6.1.4", |
||||||
|
"safe-buffer": "5.1.2", |
||||||
|
"supertest": "4.0.2" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">= 0.8" |
||||||
|
}, |
||||||
|
"files": [ |
||||||
|
"lib/", |
||||||
|
"LICENSE", |
||||||
|
"HISTORY.md", |
||||||
|
"index.js" |
||||||
|
], |
||||||
|
"homepage": "https://github.com/expressjs/body-parser#readme", |
||||||
|
"license": "MIT", |
||||||
|
"name": "body-parser", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/expressjs/body-parser.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"lint": "eslint --plugin markdown --ext js,md .", |
||||||
|
"test": "mocha --require test/support/env --reporter spec --check-leaks --bail test/", |
||||||
|
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/", |
||||||
|
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/" |
||||||
|
}, |
||||||
|
"version": "1.19.0" |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
language: node_js |
||||||
|
node_js: |
||||||
|
- 4 |
||||||
|
- 6 |
||||||
|
- 8 |
||||||
|
- 10 |
||||||
|
- 11 |
@ -0,0 +1,19 @@ |
|||||||
|
The MIT License (MIT) |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,48 @@ |
|||||||
|
# buffer-writer |
||||||
|
|
||||||
|
[![Build Status](https://secure.travis-ci.org/brianc/node-buffer-writer.png?branch=master)](http://travis-ci.org/brianc/node-buffer-writer) |
||||||
|
|
||||||
|
Fast & efficient buffer writer used to keep memory usage low by internally recycling a single large buffer. |
||||||
|
|
||||||
|
Used as the binary protocol writer in [node-postgres](https://github.com/brianc/node-postgres) |
||||||
|
|
||||||
|
Since postgres requires big endian encoding, this only writes big endian numbers for now, but can & probably will easily be extended to write little endian as well. |
||||||
|
|
||||||
|
I'll admit this has a few postgres specific things I might need to take out in the future, such as `addHeader` |
||||||
|
|
||||||
|
## api |
||||||
|
|
||||||
|
`var writer = new (require('buffer-writer')());` |
||||||
|
|
||||||
|
### writer.addInt32(num) |
||||||
|
|
||||||
|
Writes a 4-byte big endian binary encoded number to the end of the buffer. |
||||||
|
|
||||||
|
### writer.addInt16(num) |
||||||
|
|
||||||
|
Writes a 2-byte big endian binary encoded number to the end of the buffer. |
||||||
|
|
||||||
|
### writer.addCString(string) |
||||||
|
|
||||||
|
Writes a string to the buffer `utf8` encoded and adds a null character (`\0`) at the end. |
||||||
|
|
||||||
|
### var buffer = writer.addHeader(char) |
||||||
|
|
||||||
|
Writes the 5 byte PostgreSQL required header to the beginning of the buffer. (1 byte for character, 1 BE Int32 for length of the buffer) |
||||||
|
|
||||||
|
### var buffer = writer.join() |
||||||
|
|
||||||
|
Collects all data in the writer and joins it into a single, new buffer. |
||||||
|
|
||||||
|
### var buffer = writer.flush(char) |
||||||
|
|
||||||
|
Writes the 5 byte postgres required message header, collects all data in the writer and joins it into a single, new buffer, and then resets the writer. |
||||||
|
|
||||||
|
## thoughts |
||||||
|
|
||||||
|
This is kind of node-postgres specific. If you're interested in using this for a more general purpose thing, lemme know. |
||||||
|
I would love to work with you on getting this more reusable for your needs. |
||||||
|
|
||||||
|
## license |
||||||
|
|
||||||
|
MIT |
@ -0,0 +1,129 @@ |
|||||||
|
//binary data writer tuned for creating
|
||||||
|
//postgres message packets as effeciently as possible by reusing the
|
||||||
|
//same buffer to avoid memcpy and limit memory allocations
|
||||||
|
var Writer = module.exports = function (size) { |
||||||
|
this.size = size || 1024; |
||||||
|
this.buffer = Buffer.alloc(this.size + 5); |
||||||
|
this.offset = 5; |
||||||
|
this.headerPosition = 0; |
||||||
|
}; |
||||||
|
|
||||||
|
//resizes internal buffer if not enough size left
|
||||||
|
Writer.prototype._ensure = function (size) { |
||||||
|
var remaining = this.buffer.length - this.offset; |
||||||
|
if (remaining < size) { |
||||||
|
var oldBuffer = this.buffer; |
||||||
|
// exponential growth factor of around ~ 1.5
|
||||||
|
// https://stackoverflow.com/questions/2269063/buffer-growth-strategy
|
||||||
|
var newSize = oldBuffer.length + (oldBuffer.length >> 1) + size; |
||||||
|
this.buffer = Buffer.alloc(newSize); |
||||||
|
oldBuffer.copy(this.buffer); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.addInt32 = function (num) { |
||||||
|
this._ensure(4); |
||||||
|
this.buffer[this.offset++] = (num >>> 24 & 0xFF); |
||||||
|
this.buffer[this.offset++] = (num >>> 16 & 0xFF); |
||||||
|
this.buffer[this.offset++] = (num >>> 8 & 0xFF); |
||||||
|
this.buffer[this.offset++] = (num >>> 0 & 0xFF); |
||||||
|
return this; |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.addInt16 = function (num) { |
||||||
|
this._ensure(2); |
||||||
|
this.buffer[this.offset++] = (num >>> 8 & 0xFF); |
||||||
|
this.buffer[this.offset++] = (num >>> 0 & 0xFF); |
||||||
|
return this; |
||||||
|
}; |
||||||
|
|
||||||
|
//for versions of node requiring 'length' as 3rd argument to buffer.write
|
||||||
|
var writeString = function (buffer, string, offset, len) { |
||||||
|
buffer.write(string, offset, len); |
||||||
|
}; |
||||||
|
|
||||||
|
//overwrite function for older versions of node
|
||||||
|
if (Buffer.prototype.write.length === 3) { |
||||||
|
writeString = function (buffer, string, offset, len) { |
||||||
|
buffer.write(string, offset); |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
Writer.prototype.addCString = function (string) { |
||||||
|
//just write a 0 for empty or null strings
|
||||||
|
if (!string) { |
||||||
|
this._ensure(1); |
||||||
|
} else { |
||||||
|
var len = Buffer.byteLength(string); |
||||||
|
this._ensure(len + 1); //+1 for null terminator
|
||||||
|
writeString(this.buffer, string, this.offset, len); |
||||||
|
this.offset += len; |
||||||
|
} |
||||||
|
|
||||||
|
this.buffer[this.offset++] = 0; // null terminator
|
||||||
|
return this; |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.addChar = function (c) { |
||||||
|
this._ensure(1); |
||||||
|
writeString(this.buffer, c, this.offset, 1); |
||||||
|
this.offset++; |
||||||
|
return this; |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.addString = function (string) { |
||||||
|
string = string || ""; |
||||||
|
var len = Buffer.byteLength(string); |
||||||
|
this._ensure(len); |
||||||
|
this.buffer.write(string, this.offset); |
||||||
|
this.offset += len; |
||||||
|
return this; |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.getByteLength = function () { |
||||||
|
return this.offset - 5; |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.add = function (otherBuffer) { |
||||||
|
this._ensure(otherBuffer.length); |
||||||
|
otherBuffer.copy(this.buffer, this.offset); |
||||||
|
this.offset += otherBuffer.length; |
||||||
|
return this; |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.clear = function () { |
||||||
|
this.offset = 5; |
||||||
|
this.headerPosition = 0; |
||||||
|
this.lastEnd = 0; |
||||||
|
}; |
||||||
|
|
||||||
|
//appends a header block to all the written data since the last
|
||||||
|
//subsequent header or to the beginning if there is only one data block
|
||||||
|
Writer.prototype.addHeader = function (code, last) { |
||||||
|
var origOffset = this.offset; |
||||||
|
this.offset = this.headerPosition; |
||||||
|
this.buffer[this.offset++] = code; |
||||||
|
//length is everything in this packet minus the code
|
||||||
|
this.addInt32(origOffset - (this.headerPosition + 1)); |
||||||
|
//set next header position
|
||||||
|
this.headerPosition = origOffset; |
||||||
|
//make space for next header
|
||||||
|
this.offset = origOffset; |
||||||
|
if (!last) { |
||||||
|
this._ensure(5); |
||||||
|
this.offset += 5; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.join = function (code) { |
||||||
|
if (code) { |
||||||
|
this.addHeader(code, true); |
||||||
|
} |
||||||
|
return this.buffer.slice(code ? 0 : 5, this.offset); |
||||||
|
}; |
||||||
|
|
||||||
|
Writer.prototype.flush = function (code) { |
||||||
|
var result = this.join(code); |
||||||
|
this.clear(); |
||||||
|
return result; |
||||||
|
}; |
@ -0,0 +1,57 @@ |
|||||||
|
{ |
||||||
|
"_from": "buffer-writer@2.0.0", |
||||||
|
"_id": "buffer-writer@2.0.0", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==", |
||||||
|
"_location": "/buffer-writer", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "version", |
||||||
|
"registry": true, |
||||||
|
"raw": "buffer-writer@2.0.0", |
||||||
|
"name": "buffer-writer", |
||||||
|
"escapedName": "buffer-writer", |
||||||
|
"rawSpec": "2.0.0", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "2.0.0" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/pg" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", |
||||||
|
"_shasum": "ce7eb81a38f7829db09c873f2fbb792c0c98ec04", |
||||||
|
"_spec": "buffer-writer@2.0.0", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\pg", |
||||||
|
"author": { |
||||||
|
"name": "Brian M. Carlson" |
||||||
|
}, |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/brianc/node-buffer-writer/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"deprecated": false, |
||||||
|
"description": "a fast, efficient buffer writer", |
||||||
|
"devDependencies": { |
||||||
|
"mocha": "5.2.0" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">=4" |
||||||
|
}, |
||||||
|
"homepage": "https://github.com/brianc/node-buffer-writer#readme", |
||||||
|
"keywords": [ |
||||||
|
"buffer", |
||||||
|
"writer", |
||||||
|
"builder" |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"main": "index.js", |
||||||
|
"name": "buffer-writer", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git://github.com/brianc/node-buffer-writer.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"test": "mocha --throw-deprecation" |
||||||
|
}, |
||||||
|
"version": "2.0.0" |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
--ui tdd |
@ -0,0 +1,218 @@ |
|||||||
|
var Writer = require(__dirname + "/../"); |
||||||
|
|
||||||
|
var assert = require('assert'); |
||||||
|
var util = require('util'); |
||||||
|
|
||||||
|
assert.equalBuffers = function (actual, expected) { |
||||||
|
var spit = function (actual, expected) { |
||||||
|
console.log(""); |
||||||
|
console.log("actual " + util.inspect(actual)); |
||||||
|
console.log("expect " + util.inspect(expected)); |
||||||
|
console.log(""); |
||||||
|
}; |
||||||
|
if (actual.length != expected.length) { |
||||||
|
spit(actual, expected); |
||||||
|
assert.strictEqual(actual.length, expected.length); |
||||||
|
} |
||||||
|
for (var i = 0; i < actual.length; i++) { |
||||||
|
if (actual[i] != expected[i]) { |
||||||
|
spit(actual, expected); |
||||||
|
} |
||||||
|
assert.strictEqual(actual[i], expected[i]); |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
suite('adding int32', function () { |
||||||
|
var testAddingInt32 = function (int, expectedBuffer) { |
||||||
|
test('writes ' + int, function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addInt32(int).join(); |
||||||
|
assert.equalBuffers(result, expectedBuffer); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
testAddingInt32(0, [0, 0, 0, 0]); |
||||||
|
testAddingInt32(1, [0, 0, 0, 1]); |
||||||
|
testAddingInt32(256, [0, 0, 1, 0]); |
||||||
|
test('writes largest int32', function () { |
||||||
|
//todo need to find largest int32 when I have internet access
|
||||||
|
return false; |
||||||
|
}); |
||||||
|
|
||||||
|
test('writing multiple int32s', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addInt32(1).addInt32(10).addInt32(0).join(); |
||||||
|
assert.equalBuffers(result, [0, 0, 0, 1, 0, 0, 0, 0x0a, 0, 0, 0, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
suite('having to resize the buffer', function () { |
||||||
|
test('after resize correct result returned', function () { |
||||||
|
var subject = new Writer(10); |
||||||
|
subject.addInt32(1).addInt32(1).addInt32(1); |
||||||
|
assert.equalBuffers(subject.join(), [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]); |
||||||
|
}); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
suite('int16', function () { |
||||||
|
test('writes 0', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addInt16(0).join(); |
||||||
|
assert.equalBuffers(result, [0, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('writes 400', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addInt16(400).join(); |
||||||
|
assert.equalBuffers(result, [1, 0x90]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('writes many', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addInt16(0).addInt16(1).addInt16(2).join(); |
||||||
|
assert.equalBuffers(result, [0, 0, 0, 1, 0, 2]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('resizes if internal buffer fills up', function () { |
||||||
|
var subject = new Writer(3); |
||||||
|
var result = subject.addInt16(2).addInt16(3).join(); |
||||||
|
assert.equalBuffers(result, [0, 2, 0, 3]); |
||||||
|
}); |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
suite('cString', function () { |
||||||
|
test('writes empty cstring', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addCString().join(); |
||||||
|
assert.equalBuffers(result, [0]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('writes two empty cstrings', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addCString("").addCString("").join(); |
||||||
|
assert.equalBuffers(result, [0, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
|
||||||
|
test('writes non-empty cstring', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addCString("!!!").join(); |
||||||
|
assert.equalBuffers(result, [33, 33, 33, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('resizes if reached end', function () { |
||||||
|
var subject = new Writer(3); |
||||||
|
var result = subject.addCString("!!!").join(); |
||||||
|
assert.equalBuffers(result, [33, 33, 33, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('writes multiple cstrings', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
var result = subject.addCString("!").addCString("!").join(); |
||||||
|
assert.equalBuffers(result, [33, 0, 33, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
test('writes char', function () { |
||||||
|
var subject = new Writer(2); |
||||||
|
var result = subject.addChar('a').addChar('b').addChar('c').join(); |
||||||
|
assert.equalBuffers(result, [0x61, 0x62, 0x63]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('gets correct byte length', function () { |
||||||
|
var subject = new Writer(5); |
||||||
|
assert.strictEqual(subject.getByteLength(), 0); |
||||||
|
subject.addInt32(0); |
||||||
|
assert.strictEqual(subject.getByteLength(), 4); |
||||||
|
subject.addCString("!"); |
||||||
|
assert.strictEqual(subject.getByteLength(), 6); |
||||||
|
}); |
||||||
|
|
||||||
|
test('can add arbitrary buffer to the end', function () { |
||||||
|
var subject = new Writer(4); |
||||||
|
subject.addCString("!!!") |
||||||
|
var result = subject.add(Buffer.from("@@@")).join(); |
||||||
|
assert.equalBuffers(result, [33, 33, 33, 0, 0x40, 0x40, 0x40]); |
||||||
|
}); |
||||||
|
|
||||||
|
suite('can write normal string', function () { |
||||||
|
var subject = new Writer(4); |
||||||
|
var result = subject.addString("!").join(); |
||||||
|
assert.equalBuffers(result, [33]); |
||||||
|
test('can write cString too', function () { |
||||||
|
var result = subject.addCString("!").join(); |
||||||
|
assert.equalBuffers(result, [33, 33, 0]); |
||||||
|
}); |
||||||
|
test('can resize', function () { |
||||||
|
var result = subject.addString("!!").join(); |
||||||
|
assert.equalBuffers(result, [33, 33, 0, 33, 33]); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
|
||||||
|
suite('clearing', function () { |
||||||
|
var subject = new Writer(); |
||||||
|
subject.addCString("@!!#!#"); |
||||||
|
subject.addInt32(10401); |
||||||
|
test('clears', function () { |
||||||
|
subject.clear(); |
||||||
|
assert.equalBuffers(subject.join(), []); |
||||||
|
}); |
||||||
|
test('writing more', function () { |
||||||
|
var joinedResult = subject.addCString("!").addInt32(9).addInt16(2).join(); |
||||||
|
assert.equalBuffers(joinedResult, [33, 0, 0, 0, 0, 9, 0, 2]); |
||||||
|
}); |
||||||
|
test('returns result', function () { |
||||||
|
var flushedResult = subject.flush(); |
||||||
|
assert.equalBuffers(flushedResult, [33, 0, 0, 0, 0, 9, 0, 2]) |
||||||
|
}); |
||||||
|
test('clears the writer', function () { |
||||||
|
assert.equalBuffers(subject.join(), []) |
||||||
|
assert.equalBuffers(subject.flush(), []) |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
test("resizing to much larger", function () { |
||||||
|
var subject = new Writer(2); |
||||||
|
var string = "!!!!!!!!"; |
||||||
|
var result = subject.addCString(string).flush(); |
||||||
|
assert.equalBuffers(result, [33, 33, 33, 33, 33, 33, 33, 33, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
suite("flush", function () { |
||||||
|
test('added as a hex code to a full writer', function () { |
||||||
|
var subject = new Writer(2); |
||||||
|
var result = subject.addCString("!").flush(0x50); |
||||||
|
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('added as a hex code to a non-full writer', function () { |
||||||
|
var subject = new Writer(10).addCString("!"); |
||||||
|
var joinedResult = subject.join(0x50); |
||||||
|
var result = subject.flush(0x50); |
||||||
|
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0]); |
||||||
|
}); |
||||||
|
|
||||||
|
test('added as a hex code to a buffer which requires resizing', function () { |
||||||
|
var result = new Writer(2).addCString("!!!!!!!!").flush(0x50); |
||||||
|
assert.equalBuffers(result, [0x50, 0, 0, 0, 0x0D, 33, 33, 33, 33, 33, 33, 33, 33, 0]); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
suite("header", function () { |
||||||
|
test('adding two packets with headers', function () { |
||||||
|
var subject = new Writer(10).addCString("!"); |
||||||
|
subject.addHeader(0x50); |
||||||
|
subject.addCString("!!"); |
||||||
|
subject.addHeader(0x40); |
||||||
|
subject.addCString("!"); |
||||||
|
var result = subject.flush(0x10); |
||||||
|
assert.equalBuffers(result, [0x50, 0, 0, 0, 6, 33, 0, 0x40, 0, 0, 0, 7, 33, 33, 0, 0x10, 0, 0, 0, 6, 33, 0]); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,87 @@ |
|||||||
|
3.1.0 / 2019-01-22 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add petabyte (`pb`) support |
||||||
|
|
||||||
|
3.0.0 / 2017-08-31 |
||||||
|
================== |
||||||
|
|
||||||
|
* Change "kB" to "KB" in format output |
||||||
|
* Remove support for Node.js 0.6 |
||||||
|
* Remove support for ComponentJS |
||||||
|
|
||||||
|
2.5.0 / 2017-03-24 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add option "unit" |
||||||
|
|
||||||
|
2.4.0 / 2016-06-01 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add option "unitSeparator" |
||||||
|
|
||||||
|
2.3.0 / 2016-02-15 |
||||||
|
================== |
||||||
|
|
||||||
|
* Drop partial bytes on all parsed units |
||||||
|
* Fix non-finite numbers to `.format` to return `null` |
||||||
|
* Fix parsing byte string that looks like hex |
||||||
|
* perf: hoist regular expressions |
||||||
|
|
||||||
|
2.2.0 / 2015-11-13 |
||||||
|
================== |
||||||
|
|
||||||
|
* add option "decimalPlaces" |
||||||
|
* add option "fixedDecimals" |
||||||
|
|
||||||
|
2.1.0 / 2015-05-21 |
||||||
|
================== |
||||||
|
|
||||||
|
* add `.format` export |
||||||
|
* add `.parse` export |
||||||
|
|
||||||
|
2.0.2 / 2015-05-20 |
||||||
|
================== |
||||||
|
|
||||||
|
* remove map recreation |
||||||
|
* remove unnecessary object construction |
||||||
|
|
||||||
|
2.0.1 / 2015-05-07 |
||||||
|
================== |
||||||
|
|
||||||
|
* fix browserify require |
||||||
|
* remove node.extend dependency |
||||||
|
|
||||||
|
2.0.0 / 2015-04-12 |
||||||
|
================== |
||||||
|
|
||||||
|
* add option "case" |
||||||
|
* add option "thousandsSeparator" |
||||||
|
* return "null" on invalid parse input |
||||||
|
* support proper round-trip: bytes(bytes(num)) === num |
||||||
|
* units no longer case sensitive when parsing |
||||||
|
|
||||||
|
1.0.0 / 2014-05-05 |
||||||
|
================== |
||||||
|
|
||||||
|
* add negative support. fixes #6 |
||||||
|
|
||||||
|
0.3.0 / 2014-03-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* added terabyte support |
||||||
|
|
||||||
|
0.2.1 / 2013-04-01 |
||||||
|
================== |
||||||
|
|
||||||
|
* add .component |
||||||
|
|
||||||
|
0.2.0 / 2012-10-28 |
||||||
|
================== |
||||||
|
|
||||||
|
* bytes(200).should.eql('200b') |
||||||
|
|
||||||
|
0.1.0 / 2012-07-04 |
||||||
|
================== |
||||||
|
|
||||||
|
* add bytes to string conversion [yields] |
@ -0,0 +1,23 @@ |
|||||||
|
(The MIT License) |
||||||
|
|
||||||
|
Copyright (c) 2012-2014 TJ Holowaychuk <tj@vision-media.ca> |
||||||
|
Copyright (c) 2015 Jed Watson <jed.watson@me.com> |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,126 @@ |
|||||||
|
# Bytes utility |
||||||
|
|
||||||
|
[![NPM Version][npm-image]][npm-url] |
||||||
|
[![NPM Downloads][downloads-image]][downloads-url] |
||||||
|
[![Build Status][travis-image]][travis-url] |
||||||
|
[![Test Coverage][coveralls-image]][coveralls-url] |
||||||
|
|
||||||
|
Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa. |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
This is a [Node.js](https://nodejs.org/en/) module available through the |
||||||
|
[npm registry](https://www.npmjs.com/). Installation is done using the |
||||||
|
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): |
||||||
|
|
||||||
|
```bash |
||||||
|
$ npm install bytes |
||||||
|
``` |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
```js |
||||||
|
var bytes = require('bytes'); |
||||||
|
``` |
||||||
|
|
||||||
|
#### bytes.format(number value, [options]): string|null |
||||||
|
|
||||||
|
Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is |
||||||
|
rounded. |
||||||
|
|
||||||
|
**Arguments** |
||||||
|
|
||||||
|
| Name | Type | Description | |
||||||
|
|---------|----------|--------------------| |
||||||
|
| value | `number` | Value in bytes | |
||||||
|
| options | `Object` | Conversion options | |
||||||
|
|
||||||
|
**Options** |
||||||
|
|
||||||
|
| Property | Type | Description | |
||||||
|
|-------------------|--------|-----------------------------------------------------------------------------------------| |
||||||
|
| decimalPlaces | `number`|`null` | Maximum number of decimal places to include in output. Default value to `2`. | |
||||||
|
| fixedDecimals | `boolean`|`null` | Whether to always display the maximum number of decimal places. Default value to `false` | |
||||||
|
| thousandsSeparator | `string`|`null` | Example of values: `' '`, `','` and `.`... Default value to `''`. | |
||||||
|
| unit | `string`|`null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). | |
||||||
|
| unitSeparator | `string`|`null` | Separator to use between number and unit. Default value to `''`. | |
||||||
|
|
||||||
|
**Returns** |
||||||
|
|
||||||
|
| Name | Type | Description | |
||||||
|
|---------|------------------|-------------------------------------------------| |
||||||
|
| results | `string`|`null` | Return null upon error. String value otherwise. | |
||||||
|
|
||||||
|
**Example** |
||||||
|
|
||||||
|
```js |
||||||
|
bytes(1024); |
||||||
|
// output: '1KB' |
||||||
|
|
||||||
|
bytes(1000); |
||||||
|
// output: '1000B' |
||||||
|
|
||||||
|
bytes(1000, {thousandsSeparator: ' '}); |
||||||
|
// output: '1 000B' |
||||||
|
|
||||||
|
bytes(1024 * 1.7, {decimalPlaces: 0}); |
||||||
|
// output: '2KB' |
||||||
|
|
||||||
|
bytes(1024, {unitSeparator: ' '}); |
||||||
|
// output: '1 KB' |
||||||
|
|
||||||
|
``` |
||||||
|
|
||||||
|
#### bytes.parse(string|number value): number|null |
||||||
|
|
||||||
|
Parse the string value into an integer in bytes. If no unit is given, or `value` |
||||||
|
is a number, it is assumed the value is in bytes. |
||||||
|
|
||||||
|
Supported units and abbreviations are as follows and are case-insensitive: |
||||||
|
|
||||||
|
* `b` for bytes |
||||||
|
* `kb` for kilobytes |
||||||
|
* `mb` for megabytes |
||||||
|
* `gb` for gigabytes |
||||||
|
* `tb` for terabytes |
||||||
|
* `pb` for petabytes |
||||||
|
|
||||||
|
The units are in powers of two, not ten. This means 1kb = 1024b according to this parser. |
||||||
|
|
||||||
|
**Arguments** |
||||||
|
|
||||||
|
| Name | Type | Description | |
||||||
|
|---------------|--------|--------------------| |
||||||
|
| value | `string`|`number` | String to parse, or number in bytes. | |
||||||
|
|
||||||
|
**Returns** |
||||||
|
|
||||||
|
| Name | Type | Description | |
||||||
|
|---------|-------------|-------------------------| |
||||||
|
| results | `number`|`null` | Return null upon error. Value in bytes otherwise. | |
||||||
|
|
||||||
|
**Example** |
||||||
|
|
||||||
|
```js |
||||||
|
bytes('1KB'); |
||||||
|
// output: 1024 |
||||||
|
|
||||||
|
bytes('1024'); |
||||||
|
// output: 1024 |
||||||
|
|
||||||
|
bytes(1024); |
||||||
|
// output: 1KB |
||||||
|
``` |
||||||
|
|
||||||
|
## License |
||||||
|
|
||||||
|
[MIT](LICENSE) |
||||||
|
|
||||||
|
[coveralls-image]: https://badgen.net/coveralls/c/github/visionmedia/bytes.js/master |
||||||
|
[coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master |
||||||
|
[downloads-image]: https://badgen.net/npm/dm/bytes |
||||||
|
[downloads-url]: https://npmjs.org/package/bytes |
||||||
|
[npm-image]: https://badgen.net/npm/node/bytes |
||||||
|
[npm-url]: https://npmjs.org/package/bytes |
||||||
|
[travis-image]: https://badgen.net/travis/visionmedia/bytes.js/master |
||||||
|
[travis-url]: https://travis-ci.org/visionmedia/bytes.js |
@ -0,0 +1,162 @@ |
|||||||
|
/*! |
||||||
|
* bytes |
||||||
|
* Copyright(c) 2012-2014 TJ Holowaychuk |
||||||
|
* Copyright(c) 2015 Jed Watson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
module.exports = bytes; |
||||||
|
module.exports.format = format; |
||||||
|
module.exports.parse = parse; |
||||||
|
|
||||||
|
/** |
||||||
|
* Module variables. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g; |
||||||
|
|
||||||
|
var formatDecimalsRegExp = /(?:\.0*|(\.[^0]+)0+)$/; |
||||||
|
|
||||||
|
var map = { |
||||||
|
b: 1, |
||||||
|
kb: 1 << 10, |
||||||
|
mb: 1 << 20, |
||||||
|
gb: 1 << 30, |
||||||
|
tb: Math.pow(1024, 4), |
||||||
|
pb: Math.pow(1024, 5), |
||||||
|
}; |
||||||
|
|
||||||
|
var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i; |
||||||
|
|
||||||
|
/** |
||||||
|
* Convert the given value in bytes into a string or parse to string to an integer in bytes. |
||||||
|
* |
||||||
|
* @param {string|number} value |
||||||
|
* @param {{ |
||||||
|
* case: [string], |
||||||
|
* decimalPlaces: [number] |
||||||
|
* fixedDecimals: [boolean] |
||||||
|
* thousandsSeparator: [string] |
||||||
|
* unitSeparator: [string] |
||||||
|
* }} [options] bytes options. |
||||||
|
* |
||||||
|
* @returns {string|number|null} |
||||||
|
*/ |
||||||
|
|
||||||
|
function bytes(value, options) { |
||||||
|
if (typeof value === 'string') { |
||||||
|
return parse(value); |
||||||
|
} |
||||||
|
|
||||||
|
if (typeof value === 'number') { |
||||||
|
return format(value, options); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Format the given value in bytes into a string. |
||||||
|
* |
||||||
|
* If the value is negative, it is kept as such. If it is a float, |
||||||
|
* it is rounded. |
||||||
|
* |
||||||
|
* @param {number} value |
||||||
|
* @param {object} [options] |
||||||
|
* @param {number} [options.decimalPlaces=2] |
||||||
|
* @param {number} [options.fixedDecimals=false] |
||||||
|
* @param {string} [options.thousandsSeparator=] |
||||||
|
* @param {string} [options.unit=] |
||||||
|
* @param {string} [options.unitSeparator=] |
||||||
|
* |
||||||
|
* @returns {string|null} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function format(value, options) { |
||||||
|
if (!Number.isFinite(value)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
var mag = Math.abs(value); |
||||||
|
var thousandsSeparator = (options && options.thousandsSeparator) || ''; |
||||||
|
var unitSeparator = (options && options.unitSeparator) || ''; |
||||||
|
var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2; |
||||||
|
var fixedDecimals = Boolean(options && options.fixedDecimals); |
||||||
|
var unit = (options && options.unit) || ''; |
||||||
|
|
||||||
|
if (!unit || !map[unit.toLowerCase()]) { |
||||||
|
if (mag >= map.pb) { |
||||||
|
unit = 'PB'; |
||||||
|
} else if (mag >= map.tb) { |
||||||
|
unit = 'TB'; |
||||||
|
} else if (mag >= map.gb) { |
||||||
|
unit = 'GB'; |
||||||
|
} else if (mag >= map.mb) { |
||||||
|
unit = 'MB'; |
||||||
|
} else if (mag >= map.kb) { |
||||||
|
unit = 'KB'; |
||||||
|
} else { |
||||||
|
unit = 'B'; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var val = value / map[unit.toLowerCase()]; |
||||||
|
var str = val.toFixed(decimalPlaces); |
||||||
|
|
||||||
|
if (!fixedDecimals) { |
||||||
|
str = str.replace(formatDecimalsRegExp, '$1'); |
||||||
|
} |
||||||
|
|
||||||
|
if (thousandsSeparator) { |
||||||
|
str = str.replace(formatThousandsRegExp, thousandsSeparator); |
||||||
|
} |
||||||
|
|
||||||
|
return str + unitSeparator + unit; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Parse the string value into an integer in bytes. |
||||||
|
* |
||||||
|
* If no unit is given, it is assumed the value is in bytes. |
||||||
|
* |
||||||
|
* @param {number|string} val |
||||||
|
* |
||||||
|
* @returns {number|null} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function parse(val) { |
||||||
|
if (typeof val === 'number' && !isNaN(val)) { |
||||||
|
return val; |
||||||
|
} |
||||||
|
|
||||||
|
if (typeof val !== 'string') { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
// Test if the string passed is valid
|
||||||
|
var results = parseRegExp.exec(val); |
||||||
|
var floatValue; |
||||||
|
var unit = 'b'; |
||||||
|
|
||||||
|
if (!results) { |
||||||
|
// Nothing could be extracted from the given string
|
||||||
|
floatValue = parseInt(val, 10); |
||||||
|
unit = 'b' |
||||||
|
} else { |
||||||
|
// Retrieve the value and the unit
|
||||||
|
floatValue = parseFloat(results[1]); |
||||||
|
unit = results[4].toLowerCase(); |
||||||
|
} |
||||||
|
|
||||||
|
return Math.floor(map[unit] * floatValue); |
||||||
|
} |
@ -0,0 +1,84 @@ |
|||||||
|
{ |
||||||
|
"_from": "bytes@3.1.0", |
||||||
|
"_id": "bytes@3.1.0", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==", |
||||||
|
"_location": "/bytes", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "version", |
||||||
|
"registry": true, |
||||||
|
"raw": "bytes@3.1.0", |
||||||
|
"name": "bytes", |
||||||
|
"escapedName": "bytes", |
||||||
|
"rawSpec": "3.1.0", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "3.1.0" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/body-parser", |
||||||
|
"/raw-body" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", |
||||||
|
"_shasum": "f6cf7933a360e0588fa9fde85651cdc7f805d1f6", |
||||||
|
"_spec": "bytes@3.1.0", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\body-parser", |
||||||
|
"author": { |
||||||
|
"name": "TJ Holowaychuk", |
||||||
|
"email": "tj@vision-media.ca", |
||||||
|
"url": "http://tjholowaychuk.com" |
||||||
|
}, |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/visionmedia/bytes.js/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"contributors": [ |
||||||
|
{ |
||||||
|
"name": "Jed Watson", |
||||||
|
"email": "jed.watson@me.com" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"name": "Théo FIDRY", |
||||||
|
"email": "theo.fidry@gmail.com" |
||||||
|
} |
||||||
|
], |
||||||
|
"deprecated": false, |
||||||
|
"description": "Utility to parse a string bytes to bytes and vice-versa", |
||||||
|
"devDependencies": { |
||||||
|
"eslint": "5.12.1", |
||||||
|
"mocha": "5.2.0", |
||||||
|
"nyc": "13.1.0" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">= 0.8" |
||||||
|
}, |
||||||
|
"files": [ |
||||||
|
"History.md", |
||||||
|
"LICENSE", |
||||||
|
"Readme.md", |
||||||
|
"index.js" |
||||||
|
], |
||||||
|
"homepage": "https://github.com/visionmedia/bytes.js#readme", |
||||||
|
"keywords": [ |
||||||
|
"byte", |
||||||
|
"bytes", |
||||||
|
"utility", |
||||||
|
"parse", |
||||||
|
"parser", |
||||||
|
"convert", |
||||||
|
"converter" |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"name": "bytes", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/visionmedia/bytes.js.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"lint": "eslint .", |
||||||
|
"test": "mocha --check-leaks --reporter spec", |
||||||
|
"test-ci": "nyc --reporter=text npm test", |
||||||
|
"test-cov": "nyc --reporter=html --reporter=text npm test" |
||||||
|
}, |
||||||
|
"version": "3.1.0" |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
Copyright © 2011, Paul Vorbach. All rights reserved. |
||||||
|
Copyright © 2009, Jeff Mott. All rights reserved. |
||||||
|
|
||||||
|
All rights reserved. |
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, |
||||||
|
are permitted provided that the following conditions are met: |
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this |
||||||
|
list of conditions and the following disclaimer. |
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this |
||||||
|
list of conditions and the following disclaimer in the documentation and/or |
||||||
|
other materials provided with the distribution. |
||||||
|
* Neither the name Crypto-JS nor the names of its contributors may be used to |
||||||
|
endorse or promote products derived from this software without specific prior |
||||||
|
written permission. |
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
@ -0,0 +1 @@ |
|||||||
|
**enc** provides crypto character encoding utilities. |
@ -0,0 +1,33 @@ |
|||||||
|
var charenc = { |
||||||
|
// UTF-8 encoding
|
||||||
|
utf8: { |
||||||
|
// Convert a string to a byte array
|
||||||
|
stringToBytes: function(str) { |
||||||
|
return charenc.bin.stringToBytes(unescape(encodeURIComponent(str))); |
||||||
|
}, |
||||||
|
|
||||||
|
// Convert a byte array to a string
|
||||||
|
bytesToString: function(bytes) { |
||||||
|
return decodeURIComponent(escape(charenc.bin.bytesToString(bytes))); |
||||||
|
} |
||||||
|
}, |
||||||
|
|
||||||
|
// Binary encoding
|
||||||
|
bin: { |
||||||
|
// Convert a string to a byte array
|
||||||
|
stringToBytes: function(str) { |
||||||
|
for (var bytes = [], i = 0; i < str.length; i++) |
||||||
|
bytes.push(str.charCodeAt(i) & 0xFF); |
||||||
|
return bytes; |
||||||
|
}, |
||||||
|
|
||||||
|
// Convert a byte array to a string
|
||||||
|
bytesToString: function(bytes) { |
||||||
|
for (var str = [], i = 0; i < bytes.length; i++) |
||||||
|
str.push(String.fromCharCode(bytes[i])); |
||||||
|
return str.join(''); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
module.exports = charenc; |
@ -0,0 +1,54 @@ |
|||||||
|
{ |
||||||
|
"_from": "charenc@0.0.2", |
||||||
|
"_id": "charenc@0.0.2", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=", |
||||||
|
"_location": "/charenc", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "version", |
||||||
|
"registry": true, |
||||||
|
"raw": "charenc@0.0.2", |
||||||
|
"name": "charenc", |
||||||
|
"escapedName": "charenc", |
||||||
|
"rawSpec": "0.0.2", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "0.0.2" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/md5" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz", |
||||||
|
"_shasum": "c0a1d2f3a7092e03774bfa83f14c0fc5790a8667", |
||||||
|
"_spec": "charenc@0.0.2", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\md5", |
||||||
|
"author": { |
||||||
|
"name": "Paul Vorbach", |
||||||
|
"email": "paul@vorb.de", |
||||||
|
"url": "http://vorb.de" |
||||||
|
}, |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/pvorb/node-charenc/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"deprecated": false, |
||||||
|
"description": "character encoding utilities", |
||||||
|
"engines": { |
||||||
|
"node": "*" |
||||||
|
}, |
||||||
|
"homepage": "https://github.com/pvorb/node-charenc#readme", |
||||||
|
"license": "BSD-3-Clause", |
||||||
|
"main": "charenc.js", |
||||||
|
"name": "charenc", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git://github.com/pvorb/node-charenc.git" |
||||||
|
}, |
||||||
|
"tags": [ |
||||||
|
"utf8", |
||||||
|
"binary", |
||||||
|
"byte", |
||||||
|
"string" |
||||||
|
], |
||||||
|
"version": "0.0.2" |
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
0.5.3 / 2018-12-17 |
||||||
|
================== |
||||||
|
|
||||||
|
* Use `safe-buffer` for improved Buffer API |
||||||
|
|
||||||
|
0.5.2 / 2016-12-08 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix `parse` to accept any linear whitespace character |
||||||
|
|
||||||
|
0.5.1 / 2016-01-17 |
||||||
|
================== |
||||||
|
|
||||||
|
* perf: enable strict mode |
||||||
|
|
||||||
|
0.5.0 / 2014-10-11 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add `parse` function |
||||||
|
|
||||||
|
0.4.0 / 2014-09-21 |
||||||
|
================== |
||||||
|
|
||||||
|
* Expand non-Unicode `filename` to the full ISO-8859-1 charset |
||||||
|
|
||||||
|
0.3.0 / 2014-09-20 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add `fallback` option |
||||||
|
* Add `type` option |
||||||
|
|
||||||
|
0.2.0 / 2014-09-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* Reduce ambiguity of file names with hex escape in buggy browsers |
||||||
|
|
||||||
|
0.1.2 / 2014-09-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix periodic invalid Unicode filename header |
||||||
|
|
||||||
|
0.1.1 / 2014-09-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix invalid characters appearing in `filename*` parameter |
||||||
|
|
||||||
|
0.1.0 / 2014-09-18 |
||||||
|
================== |
||||||
|
|
||||||
|
* Make the `filename` argument optional |
||||||
|
|
||||||
|
0.0.0 / 2014-09-18 |
||||||
|
================== |
||||||
|
|
||||||
|
* Initial release |
@ -0,0 +1,22 @@ |
|||||||
|
(The MIT License) |
||||||
|
|
||||||
|
Copyright (c) 2014-2017 Douglas Christopher Wilson |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,148 @@ |
|||||||
|
# content-disposition |
||||||
|
|
||||||
|
[![NPM Version][npm-image]][npm-url] |
||||||
|
[![NPM Downloads][downloads-image]][downloads-url] |
||||||
|
[![Node.js Version][node-version-image]][node-version-url] |
||||||
|
[![Build Status][travis-image]][travis-url] |
||||||
|
[![Test Coverage][coveralls-image]][coveralls-url] |
||||||
|
|
||||||
|
Create and parse HTTP `Content-Disposition` header |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
```sh |
||||||
|
$ npm install content-disposition |
||||||
|
``` |
||||||
|
|
||||||
|
## API |
||||||
|
|
||||||
|
<!-- eslint-disable no-unused-vars --> |
||||||
|
|
||||||
|
```js |
||||||
|
var contentDisposition = require('content-disposition') |
||||||
|
``` |
||||||
|
|
||||||
|
### contentDisposition(filename, options) |
||||||
|
|
||||||
|
Create an attachment `Content-Disposition` header value using the given file name, |
||||||
|
if supplied. The `filename` is optional and if no file name is desired, but you |
||||||
|
want to specify `options`, set `filename` to `undefined`. |
||||||
|
|
||||||
|
<!-- eslint-disable no-undef --> |
||||||
|
|
||||||
|
```js |
||||||
|
res.setHeader('Content-Disposition', contentDisposition('∫ maths.pdf')) |
||||||
|
``` |
||||||
|
|
||||||
|
**note** HTTP headers are of the ISO-8859-1 character set. If you are writing this |
||||||
|
header through a means different from `setHeader` in Node.js, you'll want to specify |
||||||
|
the `'binary'` encoding in Node.js. |
||||||
|
|
||||||
|
#### Options |
||||||
|
|
||||||
|
`contentDisposition` accepts these properties in the options object. |
||||||
|
|
||||||
|
##### fallback |
||||||
|
|
||||||
|
If the `filename` option is outside ISO-8859-1, then the file name is actually |
||||||
|
stored in a supplemental field for clients that support Unicode file names and |
||||||
|
a ISO-8859-1 version of the file name is automatically generated. |
||||||
|
|
||||||
|
This specifies the ISO-8859-1 file name to override the automatic generation or |
||||||
|
disables the generation all together, defaults to `true`. |
||||||
|
|
||||||
|
- A string will specify the ISO-8859-1 file name to use in place of automatic |
||||||
|
generation. |
||||||
|
- `false` will disable including a ISO-8859-1 file name and only include the |
||||||
|
Unicode version (unless the file name is already ISO-8859-1). |
||||||
|
- `true` will enable automatic generation if the file name is outside ISO-8859-1. |
||||||
|
|
||||||
|
If the `filename` option is ISO-8859-1 and this option is specified and has a |
||||||
|
different value, then the `filename` option is encoded in the extended field |
||||||
|
and this set as the fallback field, even though they are both ISO-8859-1. |
||||||
|
|
||||||
|
##### type |
||||||
|
|
||||||
|
Specifies the disposition type, defaults to `"attachment"`. This can also be |
||||||
|
`"inline"`, or any other value (all values except inline are treated like |
||||||
|
`attachment`, but can convey additional information if both parties agree to |
||||||
|
it). The type is normalized to lower-case. |
||||||
|
|
||||||
|
### contentDisposition.parse(string) |
||||||
|
|
||||||
|
<!-- eslint-disable no-undef, no-unused-vars --> |
||||||
|
|
||||||
|
```js |
||||||
|
var disposition = contentDisposition.parse('attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt') |
||||||
|
``` |
||||||
|
|
||||||
|
Parse a `Content-Disposition` header string. This automatically handles extended |
||||||
|
("Unicode") parameters by decoding them and providing them under the standard |
||||||
|
parameter name. This will return an object with the following properties (examples |
||||||
|
are shown for the string `'attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt'`): |
||||||
|
|
||||||
|
- `type`: The disposition type (always lower case). Example: `'attachment'` |
||||||
|
|
||||||
|
- `parameters`: An object of the parameters in the disposition (name of parameter |
||||||
|
always lower case and extended versions replace non-extended versions). Example: |
||||||
|
`{filename: "€ rates.txt"}` |
||||||
|
|
||||||
|
## Examples |
||||||
|
|
||||||
|
### Send a file for download |
||||||
|
|
||||||
|
```js |
||||||
|
var contentDisposition = require('content-disposition') |
||||||
|
var destroy = require('destroy') |
||||||
|
var fs = require('fs') |
||||||
|
var http = require('http') |
||||||
|
var onFinished = require('on-finished') |
||||||
|
|
||||||
|
var filePath = '/path/to/public/plans.pdf' |
||||||
|
|
||||||
|
http.createServer(function onRequest (req, res) { |
||||||
|
// set headers |
||||||
|
res.setHeader('Content-Type', 'application/pdf') |
||||||
|
res.setHeader('Content-Disposition', contentDisposition(filePath)) |
||||||
|
|
||||||
|
// send file |
||||||
|
var stream = fs.createReadStream(filePath) |
||||||
|
stream.pipe(res) |
||||||
|
onFinished(res, function () { |
||||||
|
destroy(stream) |
||||||
|
}) |
||||||
|
}) |
||||||
|
``` |
||||||
|
|
||||||
|
## Testing |
||||||
|
|
||||||
|
```sh |
||||||
|
$ npm test |
||||||
|
``` |
||||||
|
|
||||||
|
## References |
||||||
|
|
||||||
|
- [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1][rfc-2616] |
||||||
|
- [RFC 5987: Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters][rfc-5987] |
||||||
|
- [RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)][rfc-6266] |
||||||
|
- [Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987][tc-2231] |
||||||
|
|
||||||
|
[rfc-2616]: https://tools.ietf.org/html/rfc2616 |
||||||
|
[rfc-5987]: https://tools.ietf.org/html/rfc5987 |
||||||
|
[rfc-6266]: https://tools.ietf.org/html/rfc6266 |
||||||
|
[tc-2231]: http://greenbytes.de/tech/tc2231/ |
||||||
|
|
||||||
|
## License |
||||||
|
|
||||||
|
[MIT](LICENSE) |
||||||
|
|
||||||
|
[npm-image]: https://img.shields.io/npm/v/content-disposition.svg |
||||||
|
[npm-url]: https://npmjs.org/package/content-disposition |
||||||
|
[node-version-image]: https://img.shields.io/node/v/content-disposition.svg |
||||||
|
[node-version-url]: https://nodejs.org/en/download |
||||||
|
[travis-image]: https://img.shields.io/travis/jshttp/content-disposition.svg |
||||||
|
[travis-url]: https://travis-ci.org/jshttp/content-disposition |
||||||
|
[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-disposition.svg |
||||||
|
[coveralls-url]: https://coveralls.io/r/jshttp/content-disposition?branch=master |
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/content-disposition.svg |
||||||
|
[downloads-url]: https://npmjs.org/package/content-disposition |
@ -0,0 +1,458 @@ |
|||||||
|
/*! |
||||||
|
* content-disposition |
||||||
|
* Copyright(c) 2014-2017 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
module.exports = contentDisposition |
||||||
|
module.exports.parse = parse |
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var basename = require('path').basename |
||||||
|
var Buffer = require('safe-buffer').Buffer |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match non attr-char, *after* encodeURIComponent (i.e. not including "%") |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g // eslint-disable-line no-control-regex
|
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match percent encoding escape. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/ |
||||||
|
var HEX_ESCAPE_REPLACE_REGEXP = /%([0-9A-Fa-f]{2})/g |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match non-latin1 characters. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match quoted-pair in RFC 2616 |
||||||
|
* |
||||||
|
* quoted-pair = "\" CHAR |
||||||
|
* CHAR = <any US-ASCII character (octets 0 - 127)> |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var QESC_REGEXP = /\\([\u0000-\u007f])/g // eslint-disable-line no-control-regex
|
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match chars that must be quoted-pair in RFC 2616 |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var QUOTE_REGEXP = /([\\"])/g |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp for various RFC 2616 grammar |
||||||
|
* |
||||||
|
* parameter = token "=" ( token | quoted-string ) |
||||||
|
* token = 1*<any CHAR except CTLs or separators> |
||||||
|
* separators = "(" | ")" | "<" | ">" | "@" |
||||||
|
* | "," | ";" | ":" | "\" | <"> |
||||||
|
* | "/" | "[" | "]" | "?" | "=" |
||||||
|
* | "{" | "}" | SP | HT |
||||||
|
* quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) |
||||||
|
* qdtext = <any TEXT except <">> |
||||||
|
* quoted-pair = "\" CHAR |
||||||
|
* CHAR = <any US-ASCII character (octets 0 - 127)> |
||||||
|
* TEXT = <any OCTET except CTLs, but including LWS> |
||||||
|
* LWS = [CRLF] 1*( SP | HT ) |
||||||
|
* CRLF = CR LF |
||||||
|
* CR = <US-ASCII CR, carriage return (13)> |
||||||
|
* LF = <US-ASCII LF, linefeed (10)> |
||||||
|
* SP = <US-ASCII SP, space (32)> |
||||||
|
* HT = <US-ASCII HT, horizontal-tab (9)> |
||||||
|
* CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)> |
||||||
|
* OCTET = <any 8-bit sequence of data> |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var PARAM_REGEXP = /;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g // eslint-disable-line no-control-regex
|
||||||
|
var TEXT_REGEXP = /^[\x20-\x7e\x80-\xff]+$/ |
||||||
|
var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/ |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp for various RFC 5987 grammar |
||||||
|
* |
||||||
|
* ext-value = charset "'" [ language ] "'" value-chars |
||||||
|
* charset = "UTF-8" / "ISO-8859-1" / mime-charset |
||||||
|
* mime-charset = 1*mime-charsetc |
||||||
|
* mime-charsetc = ALPHA / DIGIT |
||||||
|
* / "!" / "#" / "$" / "%" / "&" |
||||||
|
* / "+" / "-" / "^" / "_" / "`" |
||||||
|
* / "{" / "}" / "~" |
||||||
|
* language = ( 2*3ALPHA [ extlang ] ) |
||||||
|
* / 4ALPHA |
||||||
|
* / 5*8ALPHA |
||||||
|
* extlang = *3( "-" 3ALPHA ) |
||||||
|
* value-chars = *( pct-encoded / attr-char ) |
||||||
|
* pct-encoded = "%" HEXDIG HEXDIG |
||||||
|
* attr-char = ALPHA / DIGIT |
||||||
|
* / "!" / "#" / "$" / "&" / "+" / "-" / "." |
||||||
|
* / "^" / "_" / "`" / "|" / "~" |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/ |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp for various RFC 6266 grammar |
||||||
|
* |
||||||
|
* disposition-type = "inline" | "attachment" | disp-ext-type |
||||||
|
* disp-ext-type = token |
||||||
|
* disposition-parm = filename-parm | disp-ext-parm |
||||||
|
* filename-parm = "filename" "=" value |
||||||
|
* | "filename*" "=" ext-value |
||||||
|
* disp-ext-parm = token "=" value |
||||||
|
* | ext-token "=" ext-value |
||||||
|
* ext-token = <the characters in token, followed by "*"> |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/ // eslint-disable-line no-control-regex
|
||||||
|
|
||||||
|
/** |
||||||
|
* Create an attachment Content-Disposition header. |
||||||
|
* |
||||||
|
* @param {string} [filename] |
||||||
|
* @param {object} [options] |
||||||
|
* @param {string} [options.type=attachment] |
||||||
|
* @param {string|boolean} [options.fallback=true] |
||||||
|
* @return {string} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function contentDisposition (filename, options) { |
||||||
|
var opts = options || {} |
||||||
|
|
||||||
|
// get type
|
||||||
|
var type = opts.type || 'attachment' |
||||||
|
|
||||||
|
// get parameters
|
||||||
|
var params = createparams(filename, opts.fallback) |
||||||
|
|
||||||
|
// format into string
|
||||||
|
return format(new ContentDisposition(type, params)) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create parameters object from filename and fallback. |
||||||
|
* |
||||||
|
* @param {string} [filename] |
||||||
|
* @param {string|boolean} [fallback=true] |
||||||
|
* @return {object} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function createparams (filename, fallback) { |
||||||
|
if (filename === undefined) { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
var params = {} |
||||||
|
|
||||||
|
if (typeof filename !== 'string') { |
||||||
|
throw new TypeError('filename must be a string') |
||||||
|
} |
||||||
|
|
||||||
|
// fallback defaults to true
|
||||||
|
if (fallback === undefined) { |
||||||
|
fallback = true |
||||||
|
} |
||||||
|
|
||||||
|
if (typeof fallback !== 'string' && typeof fallback !== 'boolean') { |
||||||
|
throw new TypeError('fallback must be a string or boolean') |
||||||
|
} |
||||||
|
|
||||||
|
if (typeof fallback === 'string' && NON_LATIN1_REGEXP.test(fallback)) { |
||||||
|
throw new TypeError('fallback must be ISO-8859-1 string') |
||||||
|
} |
||||||
|
|
||||||
|
// restrict to file base name
|
||||||
|
var name = basename(filename) |
||||||
|
|
||||||
|
// determine if name is suitable for quoted string
|
||||||
|
var isQuotedString = TEXT_REGEXP.test(name) |
||||||
|
|
||||||
|
// generate fallback name
|
||||||
|
var fallbackName = typeof fallback !== 'string' |
||||||
|
? fallback && getlatin1(name) |
||||||
|
: basename(fallback) |
||||||
|
var hasFallback = typeof fallbackName === 'string' && fallbackName !== name |
||||||
|
|
||||||
|
// set extended filename parameter
|
||||||
|
if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) { |
||||||
|
params['filename*'] = name |
||||||
|
} |
||||||
|
|
||||||
|
// set filename parameter
|
||||||
|
if (isQuotedString || hasFallback) { |
||||||
|
params.filename = hasFallback |
||||||
|
? fallbackName |
||||||
|
: name |
||||||
|
} |
||||||
|
|
||||||
|
return params |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Format object to Content-Disposition header. |
||||||
|
* |
||||||
|
* @param {object} obj |
||||||
|
* @param {string} obj.type |
||||||
|
* @param {object} [obj.parameters] |
||||||
|
* @return {string} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function format (obj) { |
||||||
|
var parameters = obj.parameters |
||||||
|
var type = obj.type |
||||||
|
|
||||||
|
if (!type || typeof type !== 'string' || !TOKEN_REGEXP.test(type)) { |
||||||
|
throw new TypeError('invalid type') |
||||||
|
} |
||||||
|
|
||||||
|
// start with normalized type
|
||||||
|
var string = String(type).toLowerCase() |
||||||
|
|
||||||
|
// append parameters
|
||||||
|
if (parameters && typeof parameters === 'object') { |
||||||
|
var param |
||||||
|
var params = Object.keys(parameters).sort() |
||||||
|
|
||||||
|
for (var i = 0; i < params.length; i++) { |
||||||
|
param = params[i] |
||||||
|
|
||||||
|
var val = param.substr(-1) === '*' |
||||||
|
? ustring(parameters[param]) |
||||||
|
: qstring(parameters[param]) |
||||||
|
|
||||||
|
string += '; ' + param + '=' + val |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return string |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Decode a RFC 6987 field value (gracefully). |
||||||
|
* |
||||||
|
* @param {string} str |
||||||
|
* @return {string} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function decodefield (str) { |
||||||
|
var match = EXT_VALUE_REGEXP.exec(str) |
||||||
|
|
||||||
|
if (!match) { |
||||||
|
throw new TypeError('invalid extended field value') |
||||||
|
} |
||||||
|
|
||||||
|
var charset = match[1].toLowerCase() |
||||||
|
var encoded = match[2] |
||||||
|
var value |
||||||
|
|
||||||
|
// to binary string
|
||||||
|
var binary = encoded.replace(HEX_ESCAPE_REPLACE_REGEXP, pdecode) |
||||||
|
|
||||||
|
switch (charset) { |
||||||
|
case 'iso-8859-1': |
||||||
|
value = getlatin1(binary) |
||||||
|
break |
||||||
|
case 'utf-8': |
||||||
|
value = Buffer.from(binary, 'binary').toString('utf8') |
||||||
|
break |
||||||
|
default: |
||||||
|
throw new TypeError('unsupported charset in extended field') |
||||||
|
} |
||||||
|
|
||||||
|
return value |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get ISO-8859-1 version of string. |
||||||
|
* |
||||||
|
* @param {string} val |
||||||
|
* @return {string} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function getlatin1 (val) { |
||||||
|
// simple Unicode -> ISO-8859-1 transformation
|
||||||
|
return String(val).replace(NON_LATIN1_REGEXP, '?') |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Parse Content-Disposition header string. |
||||||
|
* |
||||||
|
* @param {string} string |
||||||
|
* @return {object} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function parse (string) { |
||||||
|
if (!string || typeof string !== 'string') { |
||||||
|
throw new TypeError('argument string is required') |
||||||
|
} |
||||||
|
|
||||||
|
var match = DISPOSITION_TYPE_REGEXP.exec(string) |
||||||
|
|
||||||
|
if (!match) { |
||||||
|
throw new TypeError('invalid type format') |
||||||
|
} |
||||||
|
|
||||||
|
// normalize type
|
||||||
|
var index = match[0].length |
||||||
|
var type = match[1].toLowerCase() |
||||||
|
|
||||||
|
var key |
||||||
|
var names = [] |
||||||
|
var params = {} |
||||||
|
var value |
||||||
|
|
||||||
|
// calculate index to start at
|
||||||
|
index = PARAM_REGEXP.lastIndex = match[0].substr(-1) === ';' |
||||||
|
? index - 1 |
||||||
|
: index |
||||||
|
|
||||||
|
// match parameters
|
||||||
|
while ((match = PARAM_REGEXP.exec(string))) { |
||||||
|
if (match.index !== index) { |
||||||
|
throw new TypeError('invalid parameter format') |
||||||
|
} |
||||||
|
|
||||||
|
index += match[0].length |
||||||
|
key = match[1].toLowerCase() |
||||||
|
value = match[2] |
||||||
|
|
||||||
|
if (names.indexOf(key) !== -1) { |
||||||
|
throw new TypeError('invalid duplicate parameter') |
||||||
|
} |
||||||
|
|
||||||
|
names.push(key) |
||||||
|
|
||||||
|
if (key.indexOf('*') + 1 === key.length) { |
||||||
|
// decode extended value
|
||||||
|
key = key.slice(0, -1) |
||||||
|
value = decodefield(value) |
||||||
|
|
||||||
|
// overwrite existing value
|
||||||
|
params[key] = value |
||||||
|
continue |
||||||
|
} |
||||||
|
|
||||||
|
if (typeof params[key] === 'string') { |
||||||
|
continue |
||||||
|
} |
||||||
|
|
||||||
|
if (value[0] === '"') { |
||||||
|
// remove quotes and escapes
|
||||||
|
value = value |
||||||
|
.substr(1, value.length - 2) |
||||||
|
.replace(QESC_REGEXP, '$1') |
||||||
|
} |
||||||
|
|
||||||
|
params[key] = value |
||||||
|
} |
||||||
|
|
||||||
|
if (index !== -1 && index !== string.length) { |
||||||
|
throw new TypeError('invalid parameter format') |
||||||
|
} |
||||||
|
|
||||||
|
return new ContentDisposition(type, params) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Percent decode a single character. |
||||||
|
* |
||||||
|
* @param {string} str |
||||||
|
* @param {string} hex |
||||||
|
* @return {string} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function pdecode (str, hex) { |
||||||
|
return String.fromCharCode(parseInt(hex, 16)) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Percent encode a single character. |
||||||
|
* |
||||||
|
* @param {string} char |
||||||
|
* @return {string} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function pencode (char) { |
||||||
|
return '%' + String(char) |
||||||
|
.charCodeAt(0) |
||||||
|
.toString(16) |
||||||
|
.toUpperCase() |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Quote a string for HTTP. |
||||||
|
* |
||||||
|
* @param {string} val |
||||||
|
* @return {string} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function qstring (val) { |
||||||
|
var str = String(val) |
||||||
|
|
||||||
|
return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"' |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Encode a Unicode string for HTTP (RFC 5987). |
||||||
|
* |
||||||
|
* @param {string} val |
||||||
|
* @return {string} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function ustring (val) { |
||||||
|
var str = String(val) |
||||||
|
|
||||||
|
// percent encode as UTF-8
|
||||||
|
var encoded = encodeURIComponent(str) |
||||||
|
.replace(ENCODE_URL_ATTR_CHAR_REGEXP, pencode) |
||||||
|
|
||||||
|
return 'UTF-8\'\'' + encoded |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Class for parsed Content-Disposition header for v8 optimization |
||||||
|
* |
||||||
|
* @public |
||||||
|
* @param {string} type |
||||||
|
* @param {object} parameters |
||||||
|
* @constructor |
||||||
|
*/ |
||||||
|
|
||||||
|
function ContentDisposition (type, parameters) { |
||||||
|
this.type = type |
||||||
|
this.parameters = parameters |
||||||
|
} |
@ -0,0 +1,79 @@ |
|||||||
|
{ |
||||||
|
"_from": "content-disposition@0.5.3", |
||||||
|
"_id": "content-disposition@0.5.3", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", |
||||||
|
"_location": "/content-disposition", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "version", |
||||||
|
"registry": true, |
||||||
|
"raw": "content-disposition@0.5.3", |
||||||
|
"name": "content-disposition", |
||||||
|
"escapedName": "content-disposition", |
||||||
|
"rawSpec": "0.5.3", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "0.5.3" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/express" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", |
||||||
|
"_shasum": "e130caf7e7279087c5616c2007d0485698984fbd", |
||||||
|
"_spec": "content-disposition@0.5.3", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\express", |
||||||
|
"author": { |
||||||
|
"name": "Douglas Christopher Wilson", |
||||||
|
"email": "doug@somethingdoug.com" |
||||||
|
}, |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/jshttp/content-disposition/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"dependencies": { |
||||||
|
"safe-buffer": "5.1.2" |
||||||
|
}, |
||||||
|
"deprecated": false, |
||||||
|
"description": "Create and parse Content-Disposition header", |
||||||
|
"devDependencies": { |
||||||
|
"deep-equal": "1.0.1", |
||||||
|
"eslint": "5.10.0", |
||||||
|
"eslint-config-standard": "12.0.0", |
||||||
|
"eslint-plugin-import": "2.14.0", |
||||||
|
"eslint-plugin-markdown": "1.0.0-rc.1", |
||||||
|
"eslint-plugin-node": "7.0.1", |
||||||
|
"eslint-plugin-promise": "4.0.1", |
||||||
|
"eslint-plugin-standard": "4.0.0", |
||||||
|
"istanbul": "0.4.5", |
||||||
|
"mocha": "5.2.0" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">= 0.6" |
||||||
|
}, |
||||||
|
"files": [ |
||||||
|
"LICENSE", |
||||||
|
"HISTORY.md", |
||||||
|
"README.md", |
||||||
|
"index.js" |
||||||
|
], |
||||||
|
"homepage": "https://github.com/jshttp/content-disposition#readme", |
||||||
|
"keywords": [ |
||||||
|
"content-disposition", |
||||||
|
"http", |
||||||
|
"rfc6266", |
||||||
|
"res" |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"name": "content-disposition", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/jshttp/content-disposition.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"lint": "eslint --plugin markdown --ext js,md .", |
||||||
|
"test": "mocha --reporter spec --bail --check-leaks test/", |
||||||
|
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", |
||||||
|
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" |
||||||
|
}, |
||||||
|
"version": "0.5.3" |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
1.0.4 / 2017-09-11 |
||||||
|
================== |
||||||
|
|
||||||
|
* perf: skip parameter parsing when no parameters |
||||||
|
|
||||||
|
1.0.3 / 2017-09-10 |
||||||
|
================== |
||||||
|
|
||||||
|
* perf: remove argument reassignment |
||||||
|
|
||||||
|
1.0.2 / 2016-05-09 |
||||||
|
================== |
||||||
|
|
||||||
|
* perf: enable strict mode |
||||||
|
|
||||||
|
1.0.1 / 2015-02-13 |
||||||
|
================== |
||||||
|
|
||||||
|
* Improve missing `Content-Type` header error message |
||||||
|
|
||||||
|
1.0.0 / 2015-02-01 |
||||||
|
================== |
||||||
|
|
||||||
|
* Initial implementation, derived from `media-typer@0.3.0` |
@ -0,0 +1,22 @@ |
|||||||
|
(The MIT License) |
||||||
|
|
||||||
|
Copyright (c) 2015 Douglas Christopher Wilson |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,92 @@ |
|||||||
|
# content-type |
||||||
|
|
||||||
|
[![NPM Version][npm-image]][npm-url] |
||||||
|
[![NPM Downloads][downloads-image]][downloads-url] |
||||||
|
[![Node.js Version][node-version-image]][node-version-url] |
||||||
|
[![Build Status][travis-image]][travis-url] |
||||||
|
[![Test Coverage][coveralls-image]][coveralls-url] |
||||||
|
|
||||||
|
Create and parse HTTP Content-Type header according to RFC 7231 |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
```sh |
||||||
|
$ npm install content-type |
||||||
|
``` |
||||||
|
|
||||||
|
## API |
||||||
|
|
||||||
|
```js |
||||||
|
var contentType = require('content-type') |
||||||
|
``` |
||||||
|
|
||||||
|
### contentType.parse(string) |
||||||
|
|
||||||
|
```js |
||||||
|
var obj = contentType.parse('image/svg+xml; charset=utf-8') |
||||||
|
``` |
||||||
|
|
||||||
|
Parse a content type string. This will return an object with the following |
||||||
|
properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`): |
||||||
|
|
||||||
|
- `type`: The media type (the type and subtype, always lower case). |
||||||
|
Example: `'image/svg+xml'` |
||||||
|
|
||||||
|
- `parameters`: An object of the parameters in the media type (name of parameter |
||||||
|
always lower case). Example: `{charset: 'utf-8'}` |
||||||
|
|
||||||
|
Throws a `TypeError` if the string is missing or invalid. |
||||||
|
|
||||||
|
### contentType.parse(req) |
||||||
|
|
||||||
|
```js |
||||||
|
var obj = contentType.parse(req) |
||||||
|
``` |
||||||
|
|
||||||
|
Parse the `content-type` header from the given `req`. Short-cut for |
||||||
|
`contentType.parse(req.headers['content-type'])`. |
||||||
|
|
||||||
|
Throws a `TypeError` if the `Content-Type` header is missing or invalid. |
||||||
|
|
||||||
|
### contentType.parse(res) |
||||||
|
|
||||||
|
```js |
||||||
|
var obj = contentType.parse(res) |
||||||
|
``` |
||||||
|
|
||||||
|
Parse the `content-type` header set on the given `res`. Short-cut for |
||||||
|
`contentType.parse(res.getHeader('content-type'))`. |
||||||
|
|
||||||
|
Throws a `TypeError` if the `Content-Type` header is missing or invalid. |
||||||
|
|
||||||
|
### contentType.format(obj) |
||||||
|
|
||||||
|
```js |
||||||
|
var str = contentType.format({type: 'image/svg+xml'}) |
||||||
|
``` |
||||||
|
|
||||||
|
Format an object into a content type string. This will return a string of the |
||||||
|
content type for the given object with the following properties (examples are |
||||||
|
shown that produce the string `'image/svg+xml; charset=utf-8'`): |
||||||
|
|
||||||
|
- `type`: The media type (will be lower-cased). Example: `'image/svg+xml'` |
||||||
|
|
||||||
|
- `parameters`: An object of the parameters in the media type (name of the |
||||||
|
parameter will be lower-cased). Example: `{charset: 'utf-8'}` |
||||||
|
|
||||||
|
Throws a `TypeError` if the object contains an invalid type or parameter names. |
||||||
|
|
||||||
|
## License |
||||||
|
|
||||||
|
[MIT](LICENSE) |
||||||
|
|
||||||
|
[npm-image]: https://img.shields.io/npm/v/content-type.svg |
||||||
|
[npm-url]: https://npmjs.org/package/content-type |
||||||
|
[node-version-image]: https://img.shields.io/node/v/content-type.svg |
||||||
|
[node-version-url]: http://nodejs.org/download/ |
||||||
|
[travis-image]: https://img.shields.io/travis/jshttp/content-type/master.svg |
||||||
|
[travis-url]: https://travis-ci.org/jshttp/content-type |
||||||
|
[coveralls-image]: https://img.shields.io/coveralls/jshttp/content-type/master.svg |
||||||
|
[coveralls-url]: https://coveralls.io/r/jshttp/content-type |
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/content-type.svg |
||||||
|
[downloads-url]: https://npmjs.org/package/content-type |
@ -0,0 +1,222 @@ |
|||||||
|
/*! |
||||||
|
* content-type |
||||||
|
* Copyright(c) 2015 Douglas Christopher Wilson |
||||||
|
* MIT Licensed |
||||||
|
*/ |
||||||
|
|
||||||
|
'use strict' |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1 |
||||||
|
* |
||||||
|
* parameter = token "=" ( token / quoted-string ) |
||||||
|
* token = 1*tchar |
||||||
|
* tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" |
||||||
|
* / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" |
||||||
|
* / DIGIT / ALPHA |
||||||
|
* ; any VCHAR, except delimiters |
||||||
|
* quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE |
||||||
|
* qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text |
||||||
|
* obs-text = %x80-FF |
||||||
|
* quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) |
||||||
|
*/ |
||||||
|
var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g |
||||||
|
var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/ |
||||||
|
var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/ |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match quoted-pair in RFC 7230 sec 3.2.6 |
||||||
|
* |
||||||
|
* quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) |
||||||
|
* obs-text = %x80-FF |
||||||
|
*/ |
||||||
|
var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match chars that must be quoted-pair in RFC 7230 sec 3.2.6 |
||||||
|
*/ |
||||||
|
var QUOTE_REGEXP = /([\\"])/g |
||||||
|
|
||||||
|
/** |
||||||
|
* RegExp to match type in RFC 7231 sec 3.1.1.1 |
||||||
|
* |
||||||
|
* media-type = type "/" subtype |
||||||
|
* type = token |
||||||
|
* subtype = token |
||||||
|
*/ |
||||||
|
var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Module exports. |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
exports.format = format |
||||||
|
exports.parse = parse |
||||||
|
|
||||||
|
/** |
||||||
|
* Format object to media type. |
||||||
|
* |
||||||
|
* @param {object} obj |
||||||
|
* @return {string} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function format (obj) { |
||||||
|
if (!obj || typeof obj !== 'object') { |
||||||
|
throw new TypeError('argument obj is required') |
||||||
|
} |
||||||
|
|
||||||
|
var parameters = obj.parameters |
||||||
|
var type = obj.type |
||||||
|
|
||||||
|
if (!type || !TYPE_REGEXP.test(type)) { |
||||||
|
throw new TypeError('invalid type') |
||||||
|
} |
||||||
|
|
||||||
|
var string = type |
||||||
|
|
||||||
|
// append parameters
|
||||||
|
if (parameters && typeof parameters === 'object') { |
||||||
|
var param |
||||||
|
var params = Object.keys(parameters).sort() |
||||||
|
|
||||||
|
for (var i = 0; i < params.length; i++) { |
||||||
|
param = params[i] |
||||||
|
|
||||||
|
if (!TOKEN_REGEXP.test(param)) { |
||||||
|
throw new TypeError('invalid parameter name') |
||||||
|
} |
||||||
|
|
||||||
|
string += '; ' + param + '=' + qstring(parameters[param]) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return string |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Parse media type to object. |
||||||
|
* |
||||||
|
* @param {string|object} string |
||||||
|
* @return {Object} |
||||||
|
* @public |
||||||
|
*/ |
||||||
|
|
||||||
|
function parse (string) { |
||||||
|
if (!string) { |
||||||
|
throw new TypeError('argument string is required') |
||||||
|
} |
||||||
|
|
||||||
|
// support req/res-like objects as argument
|
||||||
|
var header = typeof string === 'object' |
||||||
|
? getcontenttype(string) |
||||||
|
: string |
||||||
|
|
||||||
|
if (typeof header !== 'string') { |
||||||
|
throw new TypeError('argument string is required to be a string') |
||||||
|
} |
||||||
|
|
||||||
|
var index = header.indexOf(';') |
||||||
|
var type = index !== -1 |
||||||
|
? header.substr(0, index).trim() |
||||||
|
: header.trim() |
||||||
|
|
||||||
|
if (!TYPE_REGEXP.test(type)) { |
||||||
|
throw new TypeError('invalid media type') |
||||||
|
} |
||||||
|
|
||||||
|
var obj = new ContentType(type.toLowerCase()) |
||||||
|
|
||||||
|
// parse parameters
|
||||||
|
if (index !== -1) { |
||||||
|
var key |
||||||
|
var match |
||||||
|
var value |
||||||
|
|
||||||
|
PARAM_REGEXP.lastIndex = index |
||||||
|
|
||||||
|
while ((match = PARAM_REGEXP.exec(header))) { |
||||||
|
if (match.index !== index) { |
||||||
|
throw new TypeError('invalid parameter format') |
||||||
|
} |
||||||
|
|
||||||
|
index += match[0].length |
||||||
|
key = match[1].toLowerCase() |
||||||
|
value = match[2] |
||||||
|
|
||||||
|
if (value[0] === '"') { |
||||||
|
// remove quotes and escapes
|
||||||
|
value = value |
||||||
|
.substr(1, value.length - 2) |
||||||
|
.replace(QESC_REGEXP, '$1') |
||||||
|
} |
||||||
|
|
||||||
|
obj.parameters[key] = value |
||||||
|
} |
||||||
|
|
||||||
|
if (index !== header.length) { |
||||||
|
throw new TypeError('invalid parameter format') |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return obj |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get content-type from req/res objects. |
||||||
|
* |
||||||
|
* @param {object} |
||||||
|
* @return {Object} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function getcontenttype (obj) { |
||||||
|
var header |
||||||
|
|
||||||
|
if (typeof obj.getHeader === 'function') { |
||||||
|
// res-like
|
||||||
|
header = obj.getHeader('content-type') |
||||||
|
} else if (typeof obj.headers === 'object') { |
||||||
|
// req-like
|
||||||
|
header = obj.headers && obj.headers['content-type'] |
||||||
|
} |
||||||
|
|
||||||
|
if (typeof header !== 'string') { |
||||||
|
throw new TypeError('content-type header is missing from object') |
||||||
|
} |
||||||
|
|
||||||
|
return header |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Quote a string if necessary. |
||||||
|
* |
||||||
|
* @param {string} val |
||||||
|
* @return {string} |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
|
||||||
|
function qstring (val) { |
||||||
|
var str = String(val) |
||||||
|
|
||||||
|
// no need to quote tokens
|
||||||
|
if (TOKEN_REGEXP.test(str)) { |
||||||
|
return str |
||||||
|
} |
||||||
|
|
||||||
|
if (str.length > 0 && !TEXT_REGEXP.test(str)) { |
||||||
|
throw new TypeError('invalid parameter value') |
||||||
|
} |
||||||
|
|
||||||
|
return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"' |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Class to represent a content type. |
||||||
|
* @private |
||||||
|
*/ |
||||||
|
function ContentType (type) { |
||||||
|
this.parameters = Object.create(null) |
||||||
|
this.type = type |
||||||
|
} |
@ -0,0 +1,76 @@ |
|||||||
|
{ |
||||||
|
"_from": "content-type@~1.0.4", |
||||||
|
"_id": "content-type@1.0.4", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==", |
||||||
|
"_location": "/content-type", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "range", |
||||||
|
"registry": true, |
||||||
|
"raw": "content-type@~1.0.4", |
||||||
|
"name": "content-type", |
||||||
|
"escapedName": "content-type", |
||||||
|
"rawSpec": "~1.0.4", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "~1.0.4" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/body-parser", |
||||||
|
"/express" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", |
||||||
|
"_shasum": "e138cc75e040c727b1966fe5e5f8c9aee256fe3b", |
||||||
|
"_spec": "content-type@~1.0.4", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\express", |
||||||
|
"author": { |
||||||
|
"name": "Douglas Christopher Wilson", |
||||||
|
"email": "doug@somethingdoug.com" |
||||||
|
}, |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/jshttp/content-type/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"deprecated": false, |
||||||
|
"description": "Create and parse HTTP Content-Type header", |
||||||
|
"devDependencies": { |
||||||
|
"eslint": "3.19.0", |
||||||
|
"eslint-config-standard": "10.2.1", |
||||||
|
"eslint-plugin-import": "2.7.0", |
||||||
|
"eslint-plugin-node": "5.1.1", |
||||||
|
"eslint-plugin-promise": "3.5.0", |
||||||
|
"eslint-plugin-standard": "3.0.1", |
||||||
|
"istanbul": "0.4.5", |
||||||
|
"mocha": "~1.21.5" |
||||||
|
}, |
||||||
|
"engines": { |
||||||
|
"node": ">= 0.6" |
||||||
|
}, |
||||||
|
"files": [ |
||||||
|
"LICENSE", |
||||||
|
"HISTORY.md", |
||||||
|
"README.md", |
||||||
|
"index.js" |
||||||
|
], |
||||||
|
"homepage": "https://github.com/jshttp/content-type#readme", |
||||||
|
"keywords": [ |
||||||
|
"content-type", |
||||||
|
"http", |
||||||
|
"req", |
||||||
|
"res", |
||||||
|
"rfc7231" |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"name": "content-type", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/jshttp/content-type.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"lint": "eslint .", |
||||||
|
"test": "mocha --reporter spec --check-leaks --bail test/", |
||||||
|
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", |
||||||
|
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/" |
||||||
|
}, |
||||||
|
"version": "1.0.4" |
||||||
|
} |
@ -0,0 +1,4 @@ |
|||||||
|
support |
||||||
|
test |
||||||
|
examples |
||||||
|
*.sock |
@ -0,0 +1,38 @@ |
|||||||
|
1.0.6 / 2015-02-03 |
||||||
|
================== |
||||||
|
|
||||||
|
* use `npm test` instead of `make test` to run tests |
||||||
|
* clearer assertion messages when checking input |
||||||
|
|
||||||
|
|
||||||
|
1.0.5 / 2014-09-05 |
||||||
|
================== |
||||||
|
|
||||||
|
* add license to package.json |
||||||
|
|
||||||
|
1.0.4 / 2014-06-25 |
||||||
|
================== |
||||||
|
|
||||||
|
* corrected avoidance of timing attacks (thanks @tenbits!) |
||||||
|
|
||||||
|
1.0.3 / 2014-01-28 |
||||||
|
================== |
||||||
|
|
||||||
|
* [incorrect] fix for timing attacks |
||||||
|
|
||||||
|
1.0.2 / 2014-01-28 |
||||||
|
================== |
||||||
|
|
||||||
|
* fix missing repository warning |
||||||
|
* fix typo in test |
||||||
|
|
||||||
|
1.0.1 / 2013-04-15 |
||||||
|
================== |
||||||
|
|
||||||
|
* Revert "Changed underlying HMAC algo. to sha512." |
||||||
|
* Revert "Fix for timing attacks on MAC verification." |
||||||
|
|
||||||
|
0.0.1 / 2010-01-03 |
||||||
|
================== |
||||||
|
|
||||||
|
* Initial release |
@ -0,0 +1,42 @@ |
|||||||
|
|
||||||
|
# cookie-signature |
||||||
|
|
||||||
|
Sign and unsign cookies. |
||||||
|
|
||||||
|
## Example |
||||||
|
|
||||||
|
```js |
||||||
|
var cookie = require('cookie-signature'); |
||||||
|
|
||||||
|
var val = cookie.sign('hello', 'tobiiscool'); |
||||||
|
val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); |
||||||
|
|
||||||
|
var val = cookie.sign('hello', 'tobiiscool'); |
||||||
|
cookie.unsign(val, 'tobiiscool').should.equal('hello'); |
||||||
|
cookie.unsign(val, 'luna').should.be.false; |
||||||
|
``` |
||||||
|
|
||||||
|
## License |
||||||
|
|
||||||
|
(The MIT License) |
||||||
|
|
||||||
|
Copyright (c) 2012 LearnBoost <tj@learnboost.com> |
||||||
|
|
||||||
|
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. |
@ -0,0 +1,51 @@ |
|||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
*/ |
||||||
|
|
||||||
|
var crypto = require('crypto'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Sign the given `val` with `secret`. |
||||||
|
* |
||||||
|
* @param {String} val |
||||||
|
* @param {String} secret |
||||||
|
* @return {String} |
||||||
|
* @api private |
||||||
|
*/ |
||||||
|
|
||||||
|
exports.sign = function(val, secret){ |
||||||
|
if ('string' != typeof val) throw new TypeError("Cookie value must be provided as a string."); |
||||||
|
if ('string' != typeof secret) throw new TypeError("Secret string must be provided."); |
||||||
|
return val + '.' + crypto |
||||||
|
.createHmac('sha256', secret) |
||||||
|
.update(val) |
||||||
|
.digest('base64') |
||||||
|
.replace(/\=+$/, ''); |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Unsign and decode the given `val` with `secret`, |
||||||
|
* returning `false` if the signature is invalid. |
||||||
|
* |
||||||
|
* @param {String} val |
||||||
|
* @param {String} secret |
||||||
|
* @return {String|Boolean} |
||||||
|
* @api private |
||||||
|
*/ |
||||||
|
|
||||||
|
exports.unsign = function(val, secret){ |
||||||
|
if ('string' != typeof val) throw new TypeError("Signed cookie string must be provided."); |
||||||
|
if ('string' != typeof secret) throw new TypeError("Secret string must be provided."); |
||||||
|
var str = val.slice(0, val.lastIndexOf('.')) |
||||||
|
, mac = exports.sign(str, secret); |
||||||
|
|
||||||
|
return sha1(mac) == sha1(val) ? str : false; |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Private |
||||||
|
*/ |
||||||
|
|
||||||
|
function sha1(str){ |
||||||
|
return crypto.createHash('sha1').update(str).digest('hex'); |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
{ |
||||||
|
"_from": "cookie-signature@1.0.6", |
||||||
|
"_id": "cookie-signature@1.0.6", |
||||||
|
"_inBundle": false, |
||||||
|
"_integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=", |
||||||
|
"_location": "/cookie-signature", |
||||||
|
"_phantomChildren": {}, |
||||||
|
"_requested": { |
||||||
|
"type": "version", |
||||||
|
"registry": true, |
||||||
|
"raw": "cookie-signature@1.0.6", |
||||||
|
"name": "cookie-signature", |
||||||
|
"escapedName": "cookie-signature", |
||||||
|
"rawSpec": "1.0.6", |
||||||
|
"saveSpec": null, |
||||||
|
"fetchSpec": "1.0.6" |
||||||
|
}, |
||||||
|
"_requiredBy": [ |
||||||
|
"/express" |
||||||
|
], |
||||||
|
"_resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", |
||||||
|
"_shasum": "e303a882b342cc3ee8ca513a79999734dab3ae2c", |
||||||
|
"_spec": "cookie-signature@1.0.6", |
||||||
|
"_where": "C:\\Users\\sigon\\OneDrive\\Documents\\vaccine-tracker\\server\\node_modules\\express", |
||||||
|
"author": { |
||||||
|
"name": "TJ Holowaychuk", |
||||||
|
"email": "tj@learnboost.com" |
||||||
|
}, |
||||||
|
"bugs": { |
||||||
|
"url": "https://github.com/visionmedia/node-cookie-signature/issues" |
||||||
|
}, |
||||||
|
"bundleDependencies": false, |
||||||
|
"dependencies": {}, |
||||||
|
"deprecated": false, |
||||||
|
"description": "Sign and unsign cookies", |
||||||
|
"devDependencies": { |
||||||
|
"mocha": "*", |
||||||
|
"should": "*" |
||||||
|
}, |
||||||
|
"homepage": "https://github.com/visionmedia/node-cookie-signature#readme", |
||||||
|
"keywords": [ |
||||||
|
"cookie", |
||||||
|
"sign", |
||||||
|
"unsign" |
||||||
|
], |
||||||
|
"license": "MIT", |
||||||
|
"main": "index", |
||||||
|
"name": "cookie-signature", |
||||||
|
"repository": { |
||||||
|
"type": "git", |
||||||
|
"url": "git+https://github.com/visionmedia/node-cookie-signature.git" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"test": "mocha --require should --reporter spec" |
||||||
|
}, |
||||||
|
"version": "1.0.6" |
||||||
|
} |
@ -0,0 +1,123 @@ |
|||||||
|
0.4.0 / 2019-05-15 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add `SameSite=None` support |
||||||
|
|
||||||
|
0.3.1 / 2016-05-26 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix `sameSite: true` to work with draft-7 clients |
||||||
|
- `true` now sends `SameSite=Strict` instead of `SameSite` |
||||||
|
|
||||||
|
0.3.0 / 2016-05-26 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add `sameSite` option |
||||||
|
- Replaces `firstPartyOnly` option, never implemented by browsers |
||||||
|
* Improve error message when `encode` is not a function |
||||||
|
* Improve error message when `expires` is not a `Date` |
||||||
|
|
||||||
|
0.2.4 / 2016-05-20 |
||||||
|
================== |
||||||
|
|
||||||
|
* perf: enable strict mode |
||||||
|
* perf: use for loop in parse |
||||||
|
* perf: use string concatination for serialization |
||||||
|
|
||||||
|
0.2.3 / 2015-10-25 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix cookie `Max-Age` to never be a floating point number |
||||||
|
|
||||||
|
0.2.2 / 2015-09-17 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix regression when setting empty cookie value |
||||||
|
- Ease the new restriction, which is just basic header-level validation |
||||||
|
* Fix typo in invalid value errors |
||||||
|
|
||||||
|
0.2.1 / 2015-09-17 |
||||||
|
================== |
||||||
|
|
||||||
|
* Throw on invalid values provided to `serialize` |
||||||
|
- Ensures the resulting string is a valid HTTP header value |
||||||
|
|
||||||
|
0.2.0 / 2015-08-13 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add `firstPartyOnly` option |
||||||
|
* Throw better error for invalid argument to parse |
||||||
|
* perf: hoist regular expression |
||||||
|
|
||||||
|
0.1.5 / 2015-09-17 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix regression when setting empty cookie value |
||||||
|
- Ease the new restriction, which is just basic header-level validation |
||||||
|
* Fix typo in invalid value errors |
||||||
|
|
||||||
|
0.1.4 / 2015-09-17 |
||||||
|
================== |
||||||
|
|
||||||
|
* Throw better error for invalid argument to parse |
||||||
|
* Throw on invalid values provided to `serialize` |
||||||
|
- Ensures the resulting string is a valid HTTP header value |
||||||
|
|
||||||
|
0.1.3 / 2015-05-19 |
||||||
|
================== |
||||||
|
|
||||||
|
* Reduce the scope of try-catch deopt |
||||||
|
* Remove argument reassignments |
||||||
|
|
||||||
|
0.1.2 / 2014-04-16 |
||||||
|
================== |
||||||
|
|
||||||
|
* Remove unnecessary files from npm package |
||||||
|
|
||||||
|
0.1.1 / 2014-02-23 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix bad parse when cookie value contained a comma |
||||||
|
* Fix support for `maxAge` of `0` |
||||||
|
|
||||||
|
0.1.0 / 2013-05-01 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add `decode` option |
||||||
|
* Add `encode` option |
||||||
|
|
||||||
|
0.0.6 / 2013-04-08 |
||||||
|
================== |
||||||
|
|
||||||
|
* Ignore cookie parts missing `=` |
||||||
|
|
||||||
|
0.0.5 / 2012-10-29 |
||||||
|
================== |
||||||
|
|
||||||
|
* Return raw cookie value if value unescape errors |
||||||
|
|
||||||
|
0.0.4 / 2012-06-21 |
||||||
|
================== |
||||||
|
|
||||||
|
* Use encode/decodeURIComponent for cookie encoding/decoding |
||||||
|
- Improve server/client interoperability |
||||||
|
|
||||||
|
0.0.3 / 2012-06-06 |
||||||
|
================== |
||||||
|
|
||||||
|
* Only escape special characters per the cookie RFC |
||||||
|
|
||||||
|
0.0.2 / 2012-06-01 |
||||||
|
================== |
||||||
|
|
||||||
|
* Fix `maxAge` option to not throw error |
||||||
|
|
||||||
|
0.0.1 / 2012-05-28 |
||||||
|
================== |
||||||
|
|
||||||
|
* Add more tests |
||||||
|
|
||||||
|
0.0.0 / 2012-05-28 |
||||||
|
================== |
||||||
|
|
||||||
|
* Initial release |
@ -0,0 +1,24 @@ |
|||||||
|
(The MIT License) |
||||||
|
|
||||||
|
Copyright (c) 2012-2014 Roman Shtylman <shtylman@gmail.com> |
||||||
|
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com> |
||||||
|
|
||||||
|
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. |
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue