Commit d98e7fb1a9732d2f10cc09e6c0d806d37ae84bf5

Authored by Tarpit Grover
1 parent f32b8539
Exists in master

Made Cross Domain Compatible

Dont even try yogendra. ;)
node_modules/cors/.npmignore 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +.DS_Store
  2 +node_modules
  3 +npm-debug.log
... ...
node_modules/cors/.travis.yml 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +language: node_js
  2 +node_js:
  3 + - 0.10
... ...
node_modules/cors/CONTRIBUTING.md 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +# contributing to `cors`
  2 +
  3 +CORS is a node.js package for providing a [connect](http://www.senchalabs.org/connect/)/[express](http://expressjs.com/) middleware that can be used to enable [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) with various options. Learn more about the project in [the README](README.md).
  4 +
  5 +[![build status](https://secure.travis-ci.org/TroyGoode/node-cors.png)](http://travis-ci.org/TroyGoode/node-cors)
  6 +
  7 +## The CORS Spec
  8 +
  9 +[http://www.w3.org/TR/cors/](http://www.w3.org/TR/cors/)
  10 +
  11 +## Pull Requests Welcome
  12 +
  13 +* Include `'use strict';` in every javascript file.
  14 +* 2 space indentation.
  15 +* Please run the testing steps below before submitting.
  16 +
  17 +## Testing
  18 +
  19 +```bash
  20 +$ npm install
  21 +$ npm test
  22 +$ npm run lint
  23 +```
  24 +
  25 +## Interactive Testing Harness
  26 +
  27 +[http://node-cors-client.herokuapp.com](http://node-cors-client.herokuapp.com)
  28 +
  29 +Related git repositories:
  30 +
  31 +* [https://github.com/TroyGoode/node-cors-server](https://github.com/TroyGoode/node-cors-server)
  32 +* [https://github.com/TroyGoode/node-cors-client](https://github.com/TroyGoode/node-cors-client)
  33 +
  34 +## License
  35 +
  36 +[MIT License](http://www.opensource.org/licenses/mit-license.php)
... ...
node_modules/cors/LICENSE 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +The MIT License (MIT)
  2 +
  3 +Copyright (c) 2013 Troy Goode <troygoode@gmail.com>
  4 +
  5 +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:
  6 +
  7 +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  8 +
  9 +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.
... ...
node_modules/cors/README.md 0 → 100644
... ... @@ -0,0 +1,191 @@
  1 +# `cors`
  2 +
  3 +CORS is a node.js package for providing a [Connect](http://www.senchalabs.org/connect/)/[Express](http://expressjs.com/) middleware that can be used to enable [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) with various options.
  4 +
  5 +**[Follow me (@troygoode) on Twitter!](https://twitter.com/intent/user?screen_name=troygoode)**
  6 +
  7 +[![NPM](https://nodei.co/npm/cors.png?downloads=true&stars=true)](https://nodei.co/npm/cors/)
  8 +
  9 +[![build status](https://secure.travis-ci.org/troygoode/node-cors.png)](http://travis-ci.org/troygoode/node-cors)
  10 +* [Installation](#installation)
  11 +* [Usage](#usage)
  12 + * [Simple Usage](#simple-usage-enable-all-cors-requests)
  13 + * [Enable CORS for a Single Route](#enable-cors-for-a-single-route)
  14 + * [Configuring CORS](#configuring-cors)
  15 + * [Configuring CORS Asynchronously](#configuring-cors-asynchronously)
  16 + * [Enabling CORS Pre-Flight](#enabling-cors-pre-flight)
  17 +* [Configuration Options](#configuration-options)
  18 +* [Demo](#demo)
  19 +* [License](#license)
  20 +* [Author](#author)
  21 +
  22 +## Installation (via [npm](https://npmjs.org/package/cors))
  23 +
  24 +```bash
  25 +$ npm install cors
  26 +```
  27 +
  28 +## Usage
  29 +
  30 +### Simple Usage (Enable *All* CORS Requests)
  31 +
  32 +```javascript
  33 +var express = require('express')
  34 + , cors = require('cors')
  35 + , app = express();
  36 +
  37 +app.use(cors());
  38 +
  39 +app.get('/products/:id', function(req, res, next){
  40 + res.json({msg: 'This is CORS-enabled for all origins!'});
  41 +});
  42 +
  43 +app.listen(80, function(){
  44 + console.log('CORS-enabled web server listening on port 80');
  45 +});
  46 +```
  47 +
  48 +### Enable CORS for a Single Route
  49 +
  50 +```javascript
  51 +var express = require('express')
  52 + , cors = require('cors')
  53 + , app = express();
  54 +
  55 +app.get('/products/:id', cors(), function(req, res, next){
  56 + res.json({msg: 'This is CORS-enabled for all origins!'});
  57 +});
  58 +
  59 +app.listen(80, function(){
  60 + console.log('CORS-enabled web server listening on port 80');
  61 +});
  62 +```
  63 +
  64 +### Configuring CORS
  65 +
  66 +```javascript
  67 +var express = require('express')
  68 + , cors = require('cors')
  69 + , app = express();
  70 +
  71 +var corsOptions = {
  72 + origin: 'http://example.com'
  73 +};
  74 +
  75 +app.get('/products/:id', cors(corsOptions), function(req, res, next){
  76 + res.json({msg: 'This is CORS-enabled for only example.com.'});
  77 +});
  78 +
  79 +app.listen(80, function(){
  80 + console.log('CORS-enabled web server listening on port 80');
  81 +});
  82 +```
  83 +
  84 +### Configuring CORS w/ Dynamic Origin
  85 +
  86 +```javascript
  87 +var express = require('express')
  88 + , cors = require('cors')
  89 + , app = express();
  90 +
  91 +var whitelist = ['http://example1.com', 'http://example2.com'];
  92 +var corsOptions = {
  93 + origin: function(origin, callback){
  94 + var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
  95 + callback(null, originIsWhitelisted);
  96 + }
  97 +};
  98 +
  99 +app.get('/products/:id', cors(corsOptions), function(req, res, next){
  100 + res.json({msg: 'This is CORS-enabled for a whitelisted domain.'});
  101 +});
  102 +
  103 +app.listen(80, function(){
  104 + console.log('CORS-enabled web server listening on port 80');
  105 +});
  106 +```
  107 +
  108 +### Enabling CORS Pre-Flight
  109 +
  110 +Certain CORS requests are considered 'complex' and require an initial
  111 +`OPTIONS` request (called the "pre-flight request"). An example of a
  112 +'complex' CORS request is one that uses an HTTP verb other than
  113 +GET/HEAD/POST (such as DELETE) or that uses custom headers. To enable
  114 +pre-flighting, you must add a new OPTIONS handler for the route you want
  115 +to support:
  116 +
  117 +```javascript
  118 +var express = require('express')
  119 + , cors = require('cors')
  120 + , app = express();
  121 +
  122 +app.options('/products/:id', cors()); // enable pre-flight request for DELETE request
  123 +app.del('/products/:id', cors(), function(req, res, next){
  124 + res.json({msg: 'This is CORS-enabled for all origins!'});
  125 +});
  126 +
  127 +app.listen(80, function(){
  128 + console.log('CORS-enabled web server listening on port 80');
  129 +});
  130 +```
  131 +
  132 +You can also enable pre-flight across-the-board like so:
  133 +
  134 +```
  135 +app.options('*', cors()); // include before other routes
  136 +```
  137 +
  138 +### Configuring CORS Asynchronously
  139 +
  140 +```javascript
  141 +var express = require('express')
  142 + , cors = require('cors')
  143 + , app = express();
  144 +
  145 +var whitelist = ['http://example1.com', 'http://example2.com'];
  146 +var corsOptionsDelegate = function(req, callback){
  147 + var corsOptions;
  148 + if(whitelist.indexOf(req.header('Origin')) !== -1){
  149 + corsOptions = { origin: true }; // reflect (enable) the requested origin in the CORS response
  150 + }else{
  151 + corsOptions = { origin: false }; // disable CORS for this request
  152 + }
  153 + callback(null, corsOptions); // callback expects two parameters: error and options
  154 +};
  155 +
  156 +app.get('/products/:id', cors(corsOptionsDelegate), function(req, res, next){
  157 + res.json({msg: 'This is CORS-enabled for a whitelisted domain.'});
  158 +});
  159 +
  160 +app.listen(80, function(){
  161 + console.log('CORS-enabled web server listening on port 80');
  162 +});
  163 +```
  164 +
  165 +## Configuration Options
  166 +
  167 +* `origin`: Configures the **Access-Control-Allow-Origin** CORS header. Expects a string (ex: "http://example.com"). Set to `true` to reflect the [request origin](http://tools.ietf.org/html/draft-abarth-origin-09), as defined by `req.header('Origin')`. Set to `false` to disable CORS. Can also be set to a function, which takes the request origin as the first parameter and a callback (which expects the signature `err [object], allow [bool]`) as the second.
  168 +* `methods`: Configures the **Access-Control-Allow-Methods** CORS header. Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: `['GET', 'PUT', 'POST']`).
  169 +* `allowedHeaders`: Configures the **Access-Control-Allow-Headers** CORS header. Expects a comma-delimited string (ex: 'Content-Type,Authorization') or an array (ex: `['Content-Type', 'Authorization]`). If not specified, defaults to reflecting the headers specified in the request's **Access-Control-Request-Headers** header.
  170 +* `exposedHeaders`: Configures the **Access-Control-Expose-Headers** CORS header. Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range') or an array (ex: `['Content-Range', 'X-Content-Range]`). If not specified, no custom headers are exposed.
  171 +* `credentials`: Configures the **Access-Control-Allow-Credentials** CORS header. Set to `true` to pass the header, otherwise it is omitted.
  172 +* `maxAge`: Configures the **Access-Control-Allow-Max-Age** CORS header. Set to an integer to pass the header, otherwise it is omitted.
  173 +
  174 +For details on the effect of each CORS header, [read this article on HTML5 Rocks](http://www.html5rocks.com/en/tutorials/cors/).
  175 +
  176 +## Demo
  177 +
  178 +A demo that illustrates CORS working (and not working) using jQuery is available here: [http://node-cors-client.herokuapp.com/](http://node-cors-client.herokuapp.com/)
  179 +
  180 +Code for that demo can be found here:
  181 +
  182 +* Client: [https://github.com/TroyGoode/node-cors-client](https://github.com/TroyGoode/node-cors-client)
  183 +* Server: [https://github.com/TroyGoode/node-cors-server](https://github.com/TroyGoode/node-cors-server)
  184 +
  185 +## License
  186 +
  187 +[MIT License](http://www.opensource.org/licenses/mit-license.php)
  188 +
  189 +## Author
  190 +
  191 +[Troy Goode](https://github.com/TroyGoode) ([troygoode@gmail.com](mailto:troygoode@gmail.com))
... ...
node_modules/cors/lib/index.js 0 → 100644
... ... @@ -0,0 +1,198 @@
  1 +/*jslint indent: 2*/
  2 +/*global require: true, module: true*/
  3 +
  4 +(function () {
  5 +
  6 + 'use strict';
  7 +
  8 + var vary = require('vary'),
  9 + defaults = {
  10 + origin: '*',
  11 + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE'
  12 + };
  13 +
  14 + function configureOrigin(options, req) {
  15 + if (!options.origin) {
  16 + return {
  17 + key: 'Access-Control-Allow-Origin',
  18 + value: '*'
  19 + };
  20 + } else {
  21 + return [
  22 + {
  23 + key: 'Access-Control-Allow-Origin',
  24 + value: options.origin === true ? req.headers.origin : options.origin
  25 + },
  26 + {
  27 + key: 'Vary',
  28 + value: 'Origin'
  29 + }
  30 + ];
  31 + }
  32 + }
  33 +
  34 + function configureMethods(options) {
  35 + var methods = options.methods || defaults.methods;
  36 + if (methods.join) {
  37 + methods = options.methods.join(','); // .methods is an array, so turn it into a string
  38 + }
  39 + return {
  40 + key: 'Access-Control-Allow-Methods',
  41 + value: methods
  42 + };
  43 + }
  44 +
  45 + function configureCredentials(options) {
  46 + if (options.credentials === true) {
  47 + return {
  48 + key: 'Access-Control-Allow-Credentials',
  49 + value: 'true'
  50 + };
  51 + }
  52 + return null;
  53 + }
  54 +
  55 + function configureAllowedHeaders(options, req) {
  56 + var headers = options.allowedHeaders || options.headers;
  57 + if (!headers) {
  58 + headers = req.headers['access-control-request-headers']; // .headers wasn't specified, so reflect the request headers
  59 + } else if (headers.join) {
  60 + headers = headers.join(','); // .headers is an array, so turn it into a string
  61 + }
  62 + if (headers && headers.length) {
  63 + return {
  64 + key: 'Access-Control-Allow-Headers',
  65 + value: headers
  66 + };
  67 + }
  68 + return null;
  69 + }
  70 +
  71 + function configureExposedHeaders(options, req) {
  72 + var headers = options.exposedHeaders;
  73 + if (!headers) {
  74 + return null;
  75 + } else if (headers.join) {
  76 + headers = headers.join(','); // .headers is an array, so turn it into a string
  77 + }
  78 + if (headers && headers.length) {
  79 + return {
  80 + key: 'Access-Control-Expose-Headers',
  81 + value: headers
  82 + };
  83 + }
  84 + return null;
  85 + }
  86 +
  87 + function configureMaxAge(options) {
  88 + var maxAge = options.maxAge && options.maxAge.toString();
  89 + if (maxAge && maxAge.length) {
  90 + return {
  91 + key: 'Access-Control-Max-Age',
  92 + value: maxAge
  93 + };
  94 + }
  95 + return null;
  96 + }
  97 +
  98 + function applyHeaders(headers, res) {
  99 + for (var i = 0, n = headers.length; i < n; i++) {
  100 + var header = headers[i];
  101 + if (header) {
  102 + if (Array.isArray(header)) {
  103 + applyHeaders(header, res);
  104 + } else if (header.key === 'Vary' && header.value) {
  105 + vary(res, header.value);
  106 + } else if (header.value) {
  107 + res.setHeader(header.key, header.value);
  108 + }
  109 + }
  110 + }
  111 + }
  112 +
  113 + function cors(options, req, res, next) {
  114 + var headers = [],
  115 + method = req.method && req.method.toUpperCase && req.method.toUpperCase();
  116 +
  117 + if (method === 'OPTIONS') {
  118 + // preflight
  119 + headers.push(configureOrigin(options, req));
  120 + headers.push(configureCredentials(options, req));
  121 + headers.push(configureMethods(options, req));
  122 + headers.push(configureAllowedHeaders(options, req));
  123 + headers.push(configureMaxAge(options, req));
  124 + applyHeaders(headers, res);
  125 + res.statusCode = 204;
  126 + res.end();
  127 + } else {
  128 + // actual response
  129 + headers.push(configureOrigin(options, req));
  130 + headers.push(configureCredentials(options, req));
  131 + headers.push(configureExposedHeaders(options, req));
  132 + applyHeaders(headers, res);
  133 + next();
  134 + }
  135 + }
  136 +
  137 + function middlewareWrapper(o) {
  138 + // if no options were passed in, use the defaults
  139 + if (!o) {
  140 + o = {};
  141 + }
  142 + if (o.origin === undefined) {
  143 + o.origin = defaults.origin;
  144 + }
  145 + if (o.methods === undefined) {
  146 + o.methods = defaults.methods;
  147 + }
  148 +
  149 + // if options are static (either via defaults or custom options passed in), wrap in a function
  150 + var optionsCallback = null;
  151 + if (typeof o === 'function') {
  152 + optionsCallback = o;
  153 + } else {
  154 + /*jslint unparam: true*/ // `req` is part of the signature, but isn't used for this stub
  155 + optionsCallback = function (req, cb) {
  156 + cb(null, o);
  157 + };
  158 + /*jslint unparam: false*/
  159 + }
  160 +
  161 + return function (req, res, next) {
  162 + optionsCallback(req, function (err, options) {
  163 + if (err) {
  164 + next(err);
  165 + } else {
  166 + var originCallback = null;
  167 + if (options.origin && typeof options.origin === 'function') {
  168 + originCallback = options.origin;
  169 + } else if (options.origin) {
  170 + /*jslint unparam: true*/ // `origin` is part of the signature, but isn't used for this stub
  171 + originCallback = function (origin, cb) {
  172 + cb(null, options.origin);
  173 + };
  174 + /*jslint unparam: false*/
  175 + }
  176 +
  177 + if (originCallback) {
  178 + originCallback(req.headers.origin, function (err, origin) {
  179 + if (err || !origin) {
  180 + next(err);
  181 + } else {
  182 + var corsOptions = Object.create(options);
  183 + corsOptions.origin = origin;
  184 + cors(corsOptions, req, res, next);
  185 + }
  186 + });
  187 + } else {
  188 + next();
  189 + }
  190 + }
  191 + });
  192 + };
  193 + }
  194 +
  195 + // can pass either an options hash, an options delegate, or nothing
  196 + module.exports = middlewareWrapper;
  197 +
  198 +}());
... ...
node_modules/cors/node_modules/vary/.npmignore 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +coverage/
  2 +test/
  3 +.travis.yml
... ...
node_modules/cors/node_modules/vary/History.md 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +1.0.0 / 2014-08-10
  2 +==================
  3 +
  4 + * Accept valid `Vary` header string as `field`
  5 + * Add `vary.append` for low-level string manipulation
  6 + * Move to `jshttp` orgainzation
  7 +
  8 +0.1.0 / 2014-06-05
  9 +==================
  10 +
  11 + * Support array of fields to set
  12 +
  13 +0.0.0 / 2014-06-04
  14 +==================
  15 +
  16 + * Initial release
... ...
node_modules/cors/node_modules/vary/LICENSE 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +(The MIT License)
  2 +
  3 +Copyright (c) 2014 Douglas Christopher Wilson
  4 +
  5 +Permission is hereby granted, free of charge, to any person obtaining
  6 +a copy of this software and associated documentation files (the
  7 +'Software'), to deal in the Software without restriction, including
  8 +without limitation the rights to use, copy, modify, merge, publish,
  9 +distribute, sublicense, and/or sell copies of the Software, and to
  10 +permit persons to whom the Software is furnished to do so, subject to
  11 +the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be
  14 +included in all copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20 +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
... ...
node_modules/cors/node_modules/vary/README.md 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +# vary
  2 +
  3 +[![NPM Version](http://img.shields.io/npm/v/vary.svg?style=flat)](https://www.npmjs.org/package/vary)
  4 +[![Node.js Version](http://img.shields.io/badge/node.js->=_0.8-blue.svg?style=flat)](http://nodejs.org/download/)
  5 +[![Build Status](http://img.shields.io/travis/jshttp/vary.svg?style=flat)](https://travis-ci.org/jshttp/vary)
  6 +[![Coverage Status](https://img.shields.io/coveralls/jshttp/vary.svg?style=flat)](https://coveralls.io/r/jshttp/vary)
  7 +[![Gittip](http://img.shields.io/gittip/dougwilson.svg?style=flat)](https://www.gittip.com/dougwilson/)
  8 +
  9 +Manipulate the HTTP Vary header
  10 +
  11 +## Install
  12 +
  13 +```sh
  14 +$ npm install vary
  15 +```
  16 +
  17 +## API
  18 +
  19 +```js
  20 +var vary = require('vary')
  21 +```
  22 +
  23 +### vary(res, field)
  24 +
  25 +Adds the given header `field` to the `Vary` response header of `res`.
  26 +This can be a string of a single field, a string of a valid `Vary`
  27 +header, or an array of multiple fields.
  28 +
  29 +This will append the header if not already listed, otherwise leaves
  30 +it listed in the current location.
  31 +
  32 +```js
  33 +// Append "Origin" to the Vary header of the response
  34 +vary(res, 'Origin')
  35 +```
  36 +
  37 +### vary.append(header, field)
  38 +
  39 +Adds the given header `field` to the `Vary` response header string `header`.
  40 +This can be a string of a single field, a string of a valid `Vary` header,
  41 +or an array of multiple fields.
  42 +
  43 +This will append the header if not already listed, otherwise leaves
  44 +it listed in the current location. The new header string is returned.
  45 +
  46 +```js
  47 +// Get header string appending "Origin" to "Accept, User-Agent"
  48 +vary.append('Accept, User-Agent', 'Origin')
  49 +```
  50 +
  51 +## Testing
  52 +
  53 +```sh
  54 +$ npm test
  55 +```
  56 +
  57 +## License
  58 +
  59 +[MIT](LICENSE)
... ...
node_modules/cors/node_modules/vary/index.js 0 → 100644
... ... @@ -0,0 +1,112 @@
  1 +/*!
  2 + * vary
  3 + * Copyright(c) 2014 Douglas Christopher Wilson
  4 + * MIT Licensed
  5 + */
  6 +
  7 +/**
  8 + * Module exports.
  9 + */
  10 +
  11 +module.exports = vary;
  12 +module.exports.append = append;
  13 +
  14 +/**
  15 + * Variables.
  16 + */
  17 +
  18 +var separators = /[\(\)<>@,;:\\"\/\[\]\?=\{\}\u0020\u0009]/;
  19 +
  20 +/**
  21 + * Append a field to a vary header.
  22 + *
  23 + * @param {String} header
  24 + * @param {String|Array} field
  25 + * @return {String}
  26 + * @api public
  27 + */
  28 +
  29 +function append(header, field) {
  30 + if (typeof header !== 'string') {
  31 + throw new TypeError('header argument is required');
  32 + }
  33 +
  34 + if (!field) {
  35 + throw new TypeError('field argument is required');
  36 + }
  37 +
  38 + // get fields array
  39 + var fields = !Array.isArray(field)
  40 + ? parse(String(field))
  41 + : field;
  42 +
  43 + // assert on invalid fields
  44 + for (var i = 0; i < fields.length; i++) {
  45 + if (separators.test(fields[i])) {
  46 + throw new TypeError('field argument contains an invalid header');
  47 + }
  48 + }
  49 +
  50 + // existing, unspecified vary
  51 + if (header === '*') {
  52 + return header;
  53 + }
  54 +
  55 + // enumerate current values
  56 + var vals = parse(header.toLowerCase());
  57 +
  58 + // unspecified vary
  59 + if (fields.indexOf('*') !== -1 || vals.indexOf('*') !== -1) {
  60 + return '*';
  61 + }
  62 +
  63 + for (var i = 0; i < fields.length; i++) {
  64 + field = fields[i].toLowerCase();
  65 +
  66 + // append value (case-preserving)
  67 + if (vals.indexOf(field) === -1) {
  68 + vals.push(field);
  69 + header = header
  70 + ? header + ', ' + fields[i]
  71 + : fields[i];
  72 + }
  73 + }
  74 +
  75 + return header;
  76 +}
  77 +
  78 +/**
  79 + * Parse a vary header into an array.
  80 + *
  81 + * @param {String} header
  82 + * @return {Array}
  83 + * @api private
  84 + */
  85 +
  86 +function parse(header) {
  87 + return header.trim().split(/ *, */);
  88 +}
  89 +
  90 +/**
  91 + * Mark that a request is varied on a header field.
  92 + *
  93 + * @param {Object} res
  94 + * @param {String|Array} field
  95 + * @api public
  96 + */
  97 +
  98 +function vary(res, field) {
  99 + if (!res || !res.getHeader || !res.setHeader) {
  100 + // quack quack
  101 + throw new TypeError('res argument is required');
  102 + }
  103 +
  104 + // get existing header
  105 + var val = res.getHeader('Vary') || ''
  106 + var header = Array.isArray(val)
  107 + ? val.join(', ')
  108 + : String(val);
  109 +
  110 + // set new header
  111 + res.setHeader('Vary', append(header, field));
  112 +}
... ...
node_modules/cors/node_modules/vary/package.json 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +{
  2 + "name": "vary",
  3 + "description": "Manipulate the HTTP Vary header",
  4 + "version": "1.0.0",
  5 + "author": {
  6 + "name": "Douglas Christopher Wilson",
  7 + "email": "doug@somethingdoug.com"
  8 + },
  9 + "license": "MIT",
  10 + "keywords": [
  11 + "http",
  12 + "res",
  13 + "vary"
  14 + ],
  15 + "repository": {
  16 + "type": "git",
  17 + "url": "https://github.com/jshttp/vary"
  18 + },
  19 + "devDependencies": {
  20 + "istanbul": "0.3.0",
  21 + "mocha": "~1.21.4",
  22 + "should": "~4.0.4",
  23 + "supertest": "~0.13.0"
  24 + },
  25 + "engines": {
  26 + "node": ">= 0.8.0"
  27 + },
  28 + "scripts": {
  29 + "test": "mocha --reporter spec --bail --check-leaks test/",
  30 + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
  31 + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
  32 + },
  33 + "gitHead": "56acecd9fa20888132563b00576625ea02a69a35",
  34 + "bugs": {
  35 + "url": "https://github.com/jshttp/vary/issues"
  36 + },
  37 + "homepage": "https://github.com/jshttp/vary",
  38 + "_id": "vary@1.0.0",
  39 + "_shasum": "c5e76cec20d3820d8f2a96e7bee38731c34da1e7",
  40 + "_from": "vary@^1",
  41 + "_npmVersion": "1.4.21",
  42 + "_npmUser": {
  43 + "name": "dougwilson",
  44 + "email": "doug@somethingdoug.com"
  45 + },
  46 + "maintainers": [
  47 + {
  48 + "name": "dougwilson",
  49 + "email": "doug@somethingdoug.com"
  50 + },
  51 + {
  52 + "name": "jongleberry",
  53 + "email": "jonathanrichardong@gmail.com"
  54 + },
  55 + {
  56 + "name": "fishrock123",
  57 + "email": "fishrock123@rocketmail.com"
  58 + },
  59 + {
  60 + "name": "shtylman",
  61 + "email": "shtylman@gmail.com"
  62 + }
  63 + ],
  64 + "dist": {
  65 + "shasum": "c5e76cec20d3820d8f2a96e7bee38731c34da1e7",
  66 + "tarball": "http://registry.npmjs.org/vary/-/vary-1.0.0.tgz"
  67 + },
  68 + "directories": {},
  69 + "_resolved": "https://registry.npmjs.org/vary/-/vary-1.0.0.tgz"
  70 +}
... ...
node_modules/cors/package.json 0 → 100644
... ... @@ -0,0 +1,79 @@
  1 +{
  2 + "name": "cors",
  3 + "version": "2.5.3",
  4 + "author": {
  5 + "name": "Troy Goode",
  6 + "email": "troygoode@gmail.com",
  7 + "url": "https://github.com/troygoode/"
  8 + },
  9 + "description": "middleware for dynamically or statically enabling CORS in express/connect applications",
  10 + "keywords": [
  11 + "cors",
  12 + "express",
  13 + "connect",
  14 + "middleware"
  15 + ],
  16 + "homepage": "https://github.com/troygoode/node-cors/",
  17 + "repository": {
  18 + "type": "git",
  19 + "url": "git://github.com/troygoode/node-cors.git"
  20 + },
  21 + "contributors": [
  22 + {
  23 + "name": "Troy Goode",
  24 + "email": "troygoode@gmail.com",
  25 + "url": "https://github.com/troygoode/"
  26 + }
  27 + ],
  28 + "licenses": [
  29 + {
  30 + "type": "MIT",
  31 + "url": "http://www.opensource.org/licenses/mit-license.php"
  32 + }
  33 + ],
  34 + "bugs": {
  35 + "url": "https://github.com/troygoode/node-cors/issues"
  36 + },
  37 + "main": "./lib/index.js",
  38 + "engines": {
  39 + "node": ">=0.10.0"
  40 + },
  41 + "dependencies": {
  42 + "vary": "^1"
  43 + },
  44 + "devDependencies": {
  45 + "basic-auth-connect": "^1",
  46 + "body-parser": "^1.4.3",
  47 + "express": "^4",
  48 + "lint": "^1.1.2",
  49 + "mocha": "^1.18.2",
  50 + "should": "^3.3.1",
  51 + "supertest": "^0.12"
  52 + },
  53 + "scripts": {
  54 + "test": "./node_modules/mocha/bin/mocha",
  55 + "lint": "./node_modules/lint/bin/node-lint lib test"
  56 + },
  57 + "gitHead": "9959d2e4301bfb76e150c1c65e5ecd28924269fb",
  58 + "_id": "cors@2.5.3",
  59 + "_shasum": "0d70a211ec3b6cc9824e6cdc299c0630ef69c392",
  60 + "_from": "cors@",
  61 + "_npmVersion": "2.1.10",
  62 + "_nodeVersion": "0.10.26",
  63 + "_npmUser": {
  64 + "name": "troygoode",
  65 + "email": "troygoode@gmail.com"
  66 + },
  67 + "maintainers": [
  68 + {
  69 + "name": "troygoode",
  70 + "email": "troygoode@gmail.com"
  71 + }
  72 + ],
  73 + "dist": {
  74 + "shasum": "0d70a211ec3b6cc9824e6cdc299c0630ef69c392",
  75 + "tarball": "http://registry.npmjs.org/cors/-/cors-2.5.3.tgz"
  76 + },
  77 + "directories": {},
  78 + "_resolved": "https://registry.npmjs.org/cors/-/cors-2.5.3.tgz"
  79 +}
... ...
node_modules/cors/test/basic-auth.js 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +/*jslint indent: 2*/
  2 +/*global require: true, module: true, describe: true, it: true, setTimeout: true*/
  3 +
  4 +(function () {
  5 +
  6 + 'use strict';
  7 +
  8 + var should = require('should'),
  9 + express = require('express'),
  10 + supertest = require('supertest'),
  11 + basicAuth = require('basic-auth-connect'),
  12 + cors = require('../lib'),
  13 + app;
  14 +
  15 + /* -------------------------------------------------------------------------- */
  16 +
  17 + app = express();
  18 + app.use(basicAuth('username', 'password'));
  19 + app.use(cors());
  20 + /*jslint unparam: true*/ // `req` is part of the signature, but not used in these routes
  21 + app.post('/', function (req, res) {
  22 + res.send('hello world');
  23 + });
  24 + /*jslint unparam: false*/
  25 +
  26 + /* -------------------------------------------------------------------------- */
  27 +
  28 + describe('basic auth', function () {
  29 + it('POST works', function (done) {
  30 + supertest(app)
  31 + .post('/')
  32 + .auth('username', 'password')
  33 + .expect(200)
  34 + .end(function (err, res) {
  35 + should.not.exist(err);
  36 + res.headers['access-control-allow-origin'].should.eql('*');
  37 + res.text.should.eql('hello world');
  38 + done();
  39 + });
  40 + });
  41 + });
  42 +
  43 +}());
  44 +
... ...
node_modules/cors/test/body-events.js 0 → 100644
... ... @@ -0,0 +1,87 @@
  1 +/*jslint indent: 2*/
  2 +/*global require: true, module: true, describe: true, it: true, setTimeout: true*/
  3 +
  4 +(function () {
  5 +
  6 + 'use strict';
  7 +
  8 + var should = require('should'),
  9 + express = require('express'),
  10 + supertest = require('supertest'),
  11 + bodyParser = require('body-parser'),
  12 + cors = require('../lib'),
  13 + dynamicOrigin,
  14 + app1,
  15 + app2,
  16 + text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed justo turpis, tempor id sem fringilla, cursus tristique purus. Mauris a sollicitudin magna. Etiam dui lacus, vehicula non dictum at, cursus vitae libero. Curabitur lorem nulla, sollicitudin id enim ut, vehicula rhoncus felis. Ut nec iaculis velit. Vivamus at augue nulla. Fusce at molestie arcu. Duis at dui at tellus mattis tincidunt. Vestibulum sit amet dictum metus. Curabitur nec pretium ante. Proin vulputate elit ac lorem gravida, sit amet placerat lorem fringilla. Mauris fermentum, diam et volutpat auctor, ante enim imperdiet purus, sit amet tincidunt ipsum nulla nec est. Fusce id ipsum in sem malesuada laoreet vitae non magna. Praesent commodo turpis in nulla egestas, eu posuere magna venenatis. Integer in aliquam sem. Fusce quis lorem tincidunt eros rutrum lobortis.\n\nNam aliquam cursus ipsum, a hendrerit purus. Cras ultrices viverra nunc ac lacinia. Sed sed diam orci. Vestibulum ut orci a nibh scelerisque pretium. Sed suscipit vestibulum metus, ac ultricies leo sodales a. Aliquam erat volutpat. Vestibulum mauris massa, luctus et libero vel, cursus suscipit nulla. Cras sed erat quis massa fermentum congue. Mauris ultrices sem ligula, id malesuada lectus tincidunt eget. Donec sed nisl elit. Aenean ac lobortis massa. Phasellus felis nisl, dictum a dui volutpat, dictum sagittis diam. Vestibulum lacinia tellus vel commodo consequat.\n\nNulla at varius nibh, non posuere enim. Curabitur urna est, ultrices vel sem nec, consequat molestie nisi. Aliquam sed augue sit amet ante viverra pretium. Cras aliquam turpis vitae eros gravida egestas. Etiam quis dolor non quam suscipit iaculis. Sed euismod est libero, ac ullamcorper elit hendrerit vitae. Vivamus sollicitudin nulla dolor, vitae porta lacus suscipit ac.\n\nSed volutpat, magna in scelerisque dapibus, eros ante volutpat nisi, ac condimentum diam sem sed justo. Aenean justo risus, bibendum vitae blandit ac, mattis quis nunc. Quisque non felis nec justo auctor accumsan non id odio. Mauris vel dui feugiat dolor dapibus convallis in et neque. Phasellus fermentum sollicitudin tortor ac pretium. Proin tristique accumsan nulla eu venenatis. Cras porta lorem ac arcu accumsan pulvinar. Sed dignissim leo augue, a pretium ante viverra id. Phasellus blandit at purus a malesuada. Nam et cursus mauris. Vivamus accumsan augue laoreet lectus lacinia eleifend. Fusce sit amet felis nunc. Pellentesque eu turpis nisl.\n\nPellentesque vitae quam feugiat, volutpat lectus et, faucibus massa. Maecenas consectetur quis nisi eu aliquam. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam laoreet condimentum laoreet. Praesent sit amet massa sit amet dui porta condimentum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed volutpat massa nec risus malesuada hendrerit.';
  17 +
  18 + /* -------------------------------------------------------------------------- */
  19 +
  20 + dynamicOrigin = function (origin, cb) {
  21 + setTimeout(function () {
  22 + cb(null, true);
  23 + }, 200);
  24 + };
  25 +
  26 + /* -------------------------------------------------------------------------- */
  27 +
  28 + app1 = express();
  29 + app1.use(cors({origin: dynamicOrigin}));
  30 + app1.use(bodyParser.json());
  31 + /*jslint unparam: true*/ // `req` is part of the signature, but not used in these routes
  32 + app1.post('/', function (req, res) {
  33 + res.send(req.body);
  34 + });
  35 + /*jslint unparam: false*/
  36 +
  37 + /* -------------------------------------------------------------------------- */
  38 +
  39 + app2 = express();
  40 + app2.use(bodyParser.json());
  41 + app2.use(cors({origin: dynamicOrigin}));
  42 + /*jslint unparam: true*/ // `req` is part of the signature, but not used in these routes
  43 + app2.post('/', function (req, res) {
  44 + res.send(req.body);
  45 + });
  46 + /*jslint unparam: false*/
  47 +
  48 + /* -------------------------------------------------------------------------- */
  49 +
  50 + describe('body-parser-events', function () {
  51 + describe('app1 (cors before bodyparser)', function () {
  52 + it('POST works', function (done) {
  53 + var body = {
  54 + example: text
  55 + };
  56 + supertest(app1)
  57 + .post('/')
  58 + .send(body)
  59 + .expect(200)
  60 + .end(function (err, res) {
  61 + should.not.exist(err);
  62 + res.body.should.eql(body);
  63 + done();
  64 + });
  65 + });
  66 + });
  67 +
  68 + describe('app2 (bodyparser before cors)', function () {
  69 + it('POST works', function (done) {
  70 + var body = {
  71 + example: text
  72 + };
  73 + supertest(app2)
  74 + .post('/')
  75 + .send(body)
  76 + .expect(200)
  77 + .end(function (err, res) {
  78 + should.not.exist(err);
  79 + res.body.should.eql(body);
  80 + done();
  81 + });
  82 + });
  83 + });
  84 + });
  85 +
  86 +}());
  87 +
... ...
node_modules/cors/test/cors.js 0 → 100644
... ... @@ -0,0 +1,600 @@
  1 +/*jslint indent: 2*/
  2 +/*global require: true, module: true, describe: true, it: true*/
  3 +
  4 +(function () {
  5 +
  6 + 'use strict';
  7 +
  8 + var should = require('should'),
  9 + cors = require('../lib'),
  10 + fakeRequest = function (headers) {
  11 + return {
  12 + headers: headers || {
  13 + 'origin': 'request.com',
  14 + 'access-control-request-headers': 'requestedHeader1,requestedHeader2'
  15 + },
  16 + pause: function () {
  17 + // do nothing
  18 + return;
  19 + },
  20 + resume: function () {
  21 + // do nothing
  22 + return;
  23 + }
  24 + };
  25 + },
  26 + fakeResponse = function () {
  27 + var headers = {};
  28 + return {
  29 + allHeaders: function () {
  30 + return headers;
  31 + },
  32 + getHeader: function (key) {
  33 + return headers[key];
  34 + },
  35 + setHeader: function (key, value) {
  36 + headers[key] = value;
  37 + return;
  38 + },
  39 + get: function (key) {
  40 + return headers[key];
  41 + }
  42 + };
  43 + };
  44 +
  45 + describe('cors', function () {
  46 + it('passes control to next middleware', function (done) {
  47 + // arrange
  48 + var req, res, next;
  49 + req = fakeRequest();
  50 + res = fakeResponse();
  51 + next = function () {
  52 + done();
  53 + };
  54 +
  55 + // act
  56 + cors()(req, res, next);
  57 + });
  58 +
  59 + it('shortcircuits preflight requests', function (done) {
  60 + // arrange
  61 + var req, res, next;
  62 + req = fakeRequest();
  63 + req.method = 'OPTIONS';
  64 + res = fakeResponse();
  65 + res.end = function () {
  66 + // assert
  67 + res.statusCode.should.equal(204);
  68 + done();
  69 + };