This commit is contained in:
Lukian LEIZOUR 2022-11-26 15:56:34 +01:00
parent 70e2f7a8aa
commit 008d2f30d7
675 changed files with 189892 additions and 0 deletions

11
node_modules/requests/.min-wd generated vendored Normal file
View file

@ -0,0 +1,11 @@
{
"hostname": "localhost",
"port": 4444,
"browsers": [{
"name": "firefox",
"url": "http://localhost:8080/test"
}, {
"name": "phantomjs",
"url": "http://localhost:8080/test"
}]
}

27
node_modules/requests/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,27 @@
sudo: false
language: node_js
matrix:
fast_finish: true
include:
- node_js: "4"
env: TASK=test-node
- node_js: "3"
env: TASK=test-node
- node_js: "2"
env: TASK=test-node
- node_js: "1"
env: TASK=test-node
- node_js: "0.12"
env: TASK=test-node
- node_js: "0.10"
env: TASK=test-node
script:
- "npm run ${TASK}"
after_script:
- 'if [ "${TASK}" == "test-node" ]; then npm i coveralls@2 && cat coverage/lcov.info | coveralls; fi'
notifications:
irc:
channels:
- "irc.freenode.org#unshift"
on_success: change
on_failure: change

22
node_modules/requests/LICENSE generated vendored Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors.
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.

106
node_modules/requests/README.md generated vendored Normal file
View file

@ -0,0 +1,106 @@
# requests
[![Made by unshift][made-by]](http://unshift.io)[![Version npm][version]](http://browsenpm.org/package/requests)[![Build Status][build]](https://travis-ci.org/unshiftio/requests)[![Dependencies][david]](https://david-dm.org/unshiftio/requests)[![Coverage Status][cover]](https://coveralls.io/r/unshiftio/requests?branch=master)[![IRC channel][irc]](http://webchat.freenode.net/?channels=unshift)
[made-by]: https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square
[version]: https://img.shields.io/npm/v/requests.svg?style=flat-square
[build]: https://img.shields.io/travis/unshiftio/requests/master.svg?style=flat-square
[david]: https://img.shields.io/david/unshiftio/requests.svg?style=flat-square
[cover]: https://img.shields.io/coveralls/unshiftio/requests/master.svg?style=flat-square
[irc]: https://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square
Requests is a small library that implements fully and true streaming XHR for
browsers that support these methods. It uses a variety of proprietary
`responseType` properties to force a streaming connection, even for binary data.
For browsers that don't support this we will simply fallback to a regular but
**async** XHR 1/2 request or ActiveXObject in even older deprecated browsers.
- Internet Explorer >= 10: `ms-stream`
- FireFox >= 9: `moz-chunked`
- FireFox < 20: `multipart`
This module comes with build-in protection against ActiveX blocking that is
frequently used in firewalls & virus scanners.
## Installation
The module is released in the public npm registry and can be installed using:
```
npm install --save requests
```
## Usage
The API is a mix between the Fetch API, mixed with EventEmitter API for the
event handling.
```js
'use strict';
var requests = require('requests');
```
Now that we've included the library we can start making requests. The exported
method accepts 2 arguments:
- **url** Required URL that you want to have requested.
- **options** Optional object with additional configuration options:
- **streaming** Should we use streaming API's to fetch the data, defaults to
`false`.
- **method** The HTTP method that should be used to get the contents, defaults
to `GET`.
- **mode** The request mode, defaults to `cors`
- **headers** Object with header name/value that we need to send to the server.
- **timeout** The timeout in ms before we should abort the request.
- **manual** Manually `open` the request, defaults to `false`.
```js
requests('https://google.com/foo/bar', { streaming })
.on('data', function (chunk) {
console.log(chunk)
})
.on('end', function (err) {
if (err) return console.log('connection closed due to errors', err);
console.log('end');
});
```
## Events
In the example above you can see the that we're listing to various of events.
The following events are emitted:
- `data` A new chunk of data has been received. It can be a small chunk but also
the full response depending on the environment it's loaded in.
- `destroy` The request instance has been fully destroyed.
- `error` An error occurred while requesting the given URL.
- `end` Done with requesting the URL. An error argument can be supplied if the
connection was closed due to an error.
- `before` Emitted before we send the actual request.
- `send` Emitted after we've succesfully started the sending of the data.
### requests#destroy
Destroy the running XHR request and release all the references that the
`requests` instance holds. It returns a boolean as indication of a successful
destruction.
```js
requests.destroy();
```
### Requests.requested
The total amount of requests that we've made in this library. It also serves as
unique id for each request that we store in `.active`.
### Requests.active
An object that contains all running and active requests. Namespaced under
`request.requested` id and the requests instance.
## License
MIT

324
node_modules/requests/index.js generated vendored Normal file
View file

@ -0,0 +1,324 @@
'use strict';
var Requested = require('./requested')
, listeners = require('loads')
, send = require('xhr-send')
, hang = require('hang')
, AXO = require('axo')
, XMLHttpRequest = require('node-http-xhr');
/**
* RequestS(tream).
*
* Options:
*
* - streaming: Should the request be streaming.
* - method: Which HTTP method should be used.
* - headers: Additional request headers.
* - mode: Enable CORS mode.
* - body: The payload for the request.
*
* @constructor
* @param {String} url The URL we want to request.
* @param {Object} options Various of request options.
* @api public
*/
var Requests = module.exports = Requested.extend({
constructor: function bobthebuilder(url, options) {
if (!(this instanceof Requests)) return new Requests(url, options);
Requested.apply(this, arguments);
},
/**
* The offset of data that we've already previously read
*
* @type {Number}
* @private
*/
offset: 0,
/**
* The requests instance has been fully initialized.
*
* @param {String} url The URL we need to connect to.
* @api private
*/
initialize: function initialize(url) {
this.socket = Requests[Requests.method](this);
//
// Open the socket BEFORE adding any properties to the instance as this might
// trigger a thrown `InvalidStateError: An attempt was made to use an object
// that is not, or is no longer, usable` error in FireFox:
//
// @see https://bugzilla.mozilla.org/show_bug.cgi?id=707484
//
this.socket.open(this.method.toUpperCase(), url, true);
//
// Register this as an active HTTP request.
//
Requests.active[this.id] = this;
},
/**
* Initialize and start requesting the supplied resource.
*
* @param {Object} options Passed in defaults.
* @api private
*/
open: function open() {
var what
, slice = true
, requests = this
, socket = requests.socket;
requests.on('stream', function stream(data) {
if (!slice) {
return requests.emit('data', data);
}
//
// Please note that we need to use a method here that works on both string
// as well as ArrayBuffer's as we have no certainty that we're receiving
// text.
//
var chunk = data.slice(requests.offset);
requests.offset = data.length;
requests.emit('data', chunk);
});
requests.on('end', function cleanup() {
delete Requests.active[requests.id];
});
if (this.timeout) {
socket.timeout = +this.timeout;
}
if ('cors' === this.mode.toLowerCase() && 'withCredentials' in socket) {
socket.withCredentials = true;
}
//
// ActiveXObject will throw an `Type Mismatch` exception when setting the to
// an null-value and to be consistent with all XHR implementations we're going
// to cast the value to a string.
//
// While we don't technically support the XDomainRequest of IE, we do want to
// double check that the setRequestHeader is available before adding headers.
//
// Chrome has a bug where it will actually append values to the header instead
// of overriding it. So if you do a double setRequestHeader(Content-Type) with
// text/plain and with text/plain again, it will end up as `text/plain,
// text/plain` as header value. This is why use a headers object as it
// already eliminates duplicate headers.
//
for (what in this.headers) {
if (this.headers[what] !== undefined && this.socket.setRequestHeader) {
this.socket.setRequestHeader(what, this.headers[what] +'');
}
}
//
// Set the correct responseType method.
//
if (requests.streaming) {
if (!this.body || 'string' === typeof this.body) {
if ('multipart' in socket) {
socket.multipart = true;
slice = false;
} else if (Requests.type.mozchunkedtext) {
socket.responseType = 'moz-chunked-text';
slice = false;
}
} else {
if (Requests.type.mozchunkedarraybuffer) {
socket.responseType = 'moz-chunked-arraybuffer';
} else if (Requests.type.msstream) {
socket.responseType = 'ms-stream';
}
}
}
listeners(socket, requests, requests.streaming);
requests.emit('before', socket);
send(socket, this.body, hang(function send(err) {
if (err) {
requests.emit('error', err);
requests.emit('end', err);
}
requests.emit('send');
}));
},
/**
* Completely destroy the running XHR and release of the internal references.
*
* @returns {Boolean} Successful destruction
* @api public
*/
destroy: function destroy() {
if (!this.socket) return false;
this.emit('destroy');
this.socket.abort();
this.removeAllListeners();
this.headers = {};
this.socket = null;
this.body = null;
delete Requests.active[this.id];
return true;
}
});
/**
* Create a new XMLHttpRequest.
*
* @returns {XMLHttpRequest}
* @api private
*/
Requests.XHR = function create() {
try { return new XMLHttpRequest(); }
catch (e) {}
};
/**
* Create a new ActiveXObject which can be used for XHR.
*
* @returns {ActiveXObject}
* @api private
*/
Requests.AXO = function create() {
var ids = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'Microsoft.XMLHTTP']
, id;
while (ids.length) {
id = ids.shift();
try { return new AXO(id); }
catch (e) {}
}
};
/**
* Requests that are currently running.
*
* @type {Object}
* @private
*/
Requests.active = {};
/**
* The type of technology we are using to establish a working Ajax connection.
* This can either be:
*
* - XHR: XMLHttpRequest
* - AXO: ActiveXObject
*
* This is also used as internal optimization so we can easily get the correct
* constructor as we've already feature detected it.
*
* @type {String}
* @public
*/
Requests.method = !!Requests.XHR() ? 'XHR' : (!!Requests.AXO() ? 'AXO' : '');
/**
* Boolean indicating
*
* @type {Boolean}
* @public
*/
Requests.supported = !!Requests.method;
/**
* The different type of `responseType` parsers that are supported in this XHR
* implementation.
*
* @type {Object}
* @public
*/
Requests.type = 'XHR' === Requests.method ? (function detect() {
var types = 'arraybuffer,blob,document,json,text,moz-blob,moz-chunked-text,moz-chunked-arraybuffer,ms-stream'.split(',')
, supported = {}
, type, xhr, prop;
while (types.length) {
type = types.pop();
prop = type.replace(/-/g, '');
xhr = Requests.XHR();
//
// Older versions of Firefox/IE11 will throw an error because previous
// version of the specification do not support setting `responseType`
// before the request is opened. Thus, we open the request here.
//
// Note that `open()` does not actually open any connections; it just
// initializes the request object.
//
try {
// Try opening a request to current page.
xhr.open('get', '/', true);
} catch (e) {
// In JSDOM the above will fail because it only supports full URLs, so
// try opening a request to localhost.
try {
xhr.open('get', 'http://localhost/', true);
} catch (err) {
supported[prop] = false;
continue;
}
}
try {
xhr.responseType = type;
supported[prop] = 'response' in xhr && xhr.responseType === type;
} catch (e) {
supported[prop] = false;
}
xhr = null;
}
return supported;
}()) : {};
/**
* Do we support streaming response parsing.
*
* @type {Boolean}
* @private
*/
Requests.streaming = 'XHR' === Requests.method && (
'multipart' in XMLHttpRequest.prototype
|| Requests.type.mozchunkedarraybuffer
|| Requests.type.mozchunkedtext
|| Requests.type.msstream
|| Requests.type.mozblob
);
//
// IE has a bug which causes IE10 to freeze when close WebPage during an XHR
// request: https://support.microsoft.com/kb/2856746
//
// The solution is to completely clean up all active running requests.
//
if (global.attachEvent) global.attachEvent('onunload', function reap() {
for (var id in Requests.active) {
Requests.active[id].destroy();
}
});
//
// Expose the Requests library.
//
module.exports = Requests;

74
node_modules/requests/package.json generated vendored Normal file
View file

@ -0,0 +1,74 @@
{
"name": "requests",
"version": "0.3.0",
"description": "An streaming XHR abstraction that works in browsers and node.js",
"main": "index.js",
"scripts": {
"100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
"wd": "node test/index.js --wd",
"test": "node test/index.js",
"static": "node test/static.js",
"node": "mocha test/requests.test.js",
"watch": "mocha --watch ./test/requests.test.js",
"all": "npm run test && npm run node",
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- test/requests.test.js",
"test-node": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test/requests.test.js",
"compile": "mkdir -p dist && browserify browser.js -o dist/requests.js --standalone Requests",
"pre-publish": "npm run compile",
"start": "node test/development.js"
},
"repository": {
"type": "git",
"url": "https://github.com/unshiftio/requests"
},
"keywords": [
"request",
"xhr",
"requests",
"http",
"xml",
"xmlhttp",
"xmlhttprequest"
],
"author": "Arnout Kazemier",
"license": "MIT",
"bugs": {
"url": "https://github.com/unshiftio/requests/issues"
},
"homepage": "https://github.com/unshiftio/requests",
"dependencies": {
"axo": "0.0.x",
"eventemitter3": "~4.0.0",
"extendible": "0.1.x",
"hang": "1.0.x",
"loads": "0.0.x",
"node-http-xhr": "~1.3.0",
"xhr-send": "1.0.x"
},
"devDependencies": {
"argh": "0.1.x",
"assume": "~2.0.0",
"async-each": "~1.0.1",
"browserify": "^16.0.0",
"http-proxy": "~1.17.0",
"istanbul": "~0.4.5",
"mocha": "~3.5.0",
"mochify": "~2.18.1",
"pre-commit": "~1.2.0",
"setheader": "~1.0.0"
},
"testling": {
"files": "test/*.browser.js",
"harness": "mocha-bdd",
"browsers": [
"ie/6..latest",
"chrome/22..latest",
"firefox/16..latest",
"safari/latest",
"opera/11.0..latest",
"iphone/latest",
"ipad/latest",
"android-browser/latest"
]
}
}

110
node_modules/requests/requested.js generated vendored Normal file
View file

@ -0,0 +1,110 @@
'use strict';
var EventEmitter = require('eventemitter3');
function Requested(url, options) {
EventEmitter.call(this);
//
// All properties/options that should be introduced on the prototype.
//
this.merge(this, Requested.defaults, options || {});
//
// Private properties that should not be overridden by developers.
//
this.id = ++Requested.requested;
//
// We want to implement a stream like interface on top of this module so it
// can be used to read streaming data in node as well as through browserify.
//
this.readable = true;
this.writable = false;
if (this.initialize) this.initialize(url);
if (!this.manual && this.open) this.open(url);
}
Requested.extend = require('extendible');
Requested.prototype = new EventEmitter();
Requested.prototype.constructor = Requested;
/**
* Accurate type discovery.
*
* @param {Mixed} what What ever needs to be figured out.
* @returns {String} Name of the type.
* @api private
*/
Requested.prototype.typeof = function type(what) {
return Object.prototype.toString.call(what).slice(8, -1).toLowerCase();
};
/**
* Deeply assign and merge objects together.
*
* @param {Object} target The target object that should receive the merged data.
* @returns {Object} The merged target object.
* @api private
*/
Requested.prototype.merge = function merge(target) {
var i = 1
, arg, key;
for (; i < arguments.length; i++) {
arg = arguments[i];
for (key in arg) {
if (!Object.prototype.hasOwnProperty.call(arg, key)) continue;
if ('object' === this.typeof(arg[key])) {
target[key] = this.merge('object' === this.typeof(target[key]) ? target[key] : {}, arg[key]);
} else {
target[key] = arg[key];
}
}
}
return target;
};
/**
* The defaults for the Requests. These values will be used if no options object
* or matching key is provided. It can be override globally if needed but this
* is not advised as it can have some potential side affects for other libraries
* that use this module.
*
* @type {Object}
* @public
*/
Requested.defaults = {
streaming: false,
manual: false,
method: 'GET',
mode: 'cors',
headers: {
//
// We're forcing text/plain mode by default to ensure that regular
// requests can benefit from CORS requests without an OPTIONS request. It's
// shared between server and client implementations to ensure that requests
// are handled in exactly the same way.
//
'Content-Type': 'text/plain'
}
};
/**
* Unique id and also an indication on how many XHR requests we've made using
* this library.
*
* @type {Number}
* @private
*/
Requested.requested = 0;
//
// Expose the module interface.
//
module.exports = Requested;

59
node_modules/requests/test/development.js generated vendored Normal file
View file

@ -0,0 +1,59 @@
'use strict';
var browserify = require('browserify')
, path = require('path')
, fs = require('fs');
require('http').createServer(function statical(req, res) {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
switch (req.url) {
case '/':
req.url = '/index.html';
break;
case '/dist/requests.js':
var compiler
, stream;
res.setHeader('Content-Type', 'text/javascript');
compiler = browserify({ debug: true, standalone: 'Requests' });
compiler.add(path.join(__dirname, '..', 'browser.js'));
stream = compiler.bundle();
stream.pipe(res);
stream.pipe(fs.createWriteStream(path.join(__dirname, '..', req.url)));
return;
case '/stream':
res.write('[first chunk]');
setTimeout(function () {
res.write('[second chunk]');
setTimeout(function () {
res.end('[final chunk]');
}, 10000);
}, 100);
return;
}
if (!fs.existsSync(__dirname + req.url)) {
res.write('<script src="/dist/requests.js"></script>');
return res.end('Nope, doesn\'t exist.');
}
require('fs').createReadStream(__dirname + req.url).pipe(res);
}).on('connection', function connection(socket) {
//
// Force buffer flusing when we call our write.
//
socket.setNoDelay(true);
}).listen(+process.argv[2] || 8080, function listening() {
console.log('Development server is now running on:');
console.log('');
console.log(' http://localhost:'+ this.address().port);
console.log('');
});

26
node_modules/requests/test/index.html generated vendored Normal file
View file

@ -0,0 +1,26 @@
<div id="output">
<h2>Progress log</h2>
</div>
<script src="/dist/requests.js"></script>
<script>
/**
* Poor mans cross browser logger.
*
* @param {String} line The message that needs to be logged
* @api private
*/
function log(line) {
document.getElementById('output').innerHTML += line +'<br />';
}
var r = new Requests('/stream', { streaming: true });
r.on('data', function (data) {
log('<strong>received chunk:</strong> <code>'+ data +'</code>');
});
r.on('end', function () {
log('<strong>request has ended</strong>');
});
</script>

107
node_modules/requests/test/index.js generated vendored Normal file
View file

@ -0,0 +1,107 @@
'use strict';
var path = require('path')
, Mocha = require('mocha')
, argv = require('argh').argv
, mochify = require('mochify');
argv.reporter = argv.reporter || 'spec';
argv.ui = argv.ui || 'bdd';
argv.wd = argv.wd || false;
/**
* Poor mans kill switch. Kills all active hooks.
*
* @api private
*/
function kill() {
require('async-each')(kill.hooks, function each(fn, next) {
fn(next);
}, function done(err) {
if (err) return process.exit(1);
process.exit(0);
});
}
/**
* All the hooks that need destruction.
*
* @type {Array}
* @private
*/
kill.hooks = [];
//
// This is the magical test runner that setup's all the things and runs various
// of test suites until something starts failing.
//
(function runner(steps) {
if (!steps.length) return kill(), runner;
var step = steps.shift();
step(function unregister(fn) {
kill.hooks.push(fn);
}, function register(err) {
if (err) throw err;
runner(steps);
});
return runner;
})([
//
// Run the normal node tests.
//
function creamy(kill, next) {
var mocha = new Mocha();
mocha.reporter(argv.reporter);
mocha.ui(argv.ui);
//
// The next bulk of logic is required to correctly glob and lookup all the
// files required for testing.
//
mocha.files = [
'./test/*.test.js'
].map(function lookup(glob) {
return Mocha.utils.lookupFiles(glob, ['js']);
}).reduce(function flatten(arr, what) {
Array.prototype.push.apply(arr, what);
return arr;
}, []).map(function resolve(file) {
return path.resolve(file);
});
//
// Run the mocha test suite inside this node process with a custom callback
// so we don't accidentally exit the process and forget to run the test of the
// tests.
//
mocha.run(function ran(err) {
if (err) err = new Error('Something failed in the mocha test suite');
next(err);
});
},
//
// Start-up a small static file server so we can download files and fixtures
// inside our PhantomJS test.
//
require('./static'),
//
// Run the PhantomJS tests now that we have a small static server setup.
//
function phantomjs(kill, next) {
mochify('./test/*.browser.js', {
reporter: argv.reporter,
cover: argv.cover,
wd: argv.wd,
ui: argv.ui
})
.bundle(next);
}
]);

79794
node_modules/requests/test/large.js generated vendored Normal file

File diff suppressed because it is too large Load diff

56
node_modules/requests/test/requested.js generated vendored Normal file
View file

@ -0,0 +1,56 @@
describe('Requested', function () {
'use strict';
var Requested = require('../requested')
, assume = require('assume')
, r;
it('is exported as a function', function () {
assume(Requested).is.a('function');
});
describe('#typeof', function () {
it('knows the difference between an array and object', function () {
var r = new Requested();
assume(r.typeof({})).equals('object');
assume(r.typeof([])).equals('array');
});
});
describe('#merge', function () {
before(function () {
r = new Requested();
});
it('returns the merge', function () {
var x = { foo: 'foo' }
, y = { bar: 'bar' }
, z = r.merge(x, y);
assume(z).equals(x);
assume(x.bar).equals('bar');
});
it('merges multiple objects', function () {
var xyz = r.merge({}, { foo: 'foo' }, { bar: 'bar' }, { hello: 'world' });
assume(xyz.foo).equals('foo');
assume(xyz.bar).equals('bar');
assume(xyz.hello).equals('world');
});
it('can deep merge without modification', function () {
var x = { foo: 'foo' }
, y = { deep: { nested: 'object' } }
, z = { deep: { another: 'key' } }
, xyz = r.merge(x, y, z);
assume(x.deep).is.a('object');
assume(x.deep).does.not.equal(y.deep);
assume(x.deep).does.not.equal(z.deep);
assume(x.deep.nested).equals('object');
assume(x.deep.another).equals('key');
});
});
});

103
node_modules/requests/test/requests.browser.js generated vendored Normal file
View file

@ -0,0 +1,103 @@
describe('requests', function () {
'use strict';
//
// Include the Base class that we inherit from to ensure that it's also
// included in the test run as it should run on both browsers and node.js
//
require('./requested');
var Requested = require('../requested')
, requests = require('..')
, assume = require('assume')
, req;
beforeEach(function () {
req = requests(unique('http://localhost:8080'), { manual: true });
});
afterEach(function () {
req.destroy();
});
/**
* Make a URL unique so we can bust the browser cache which could affect
*
* @param {String} url Transform to an URL.
* @returns {String}
* @api private
*/
function unique(url) {
return url + '?t='+ (+ new Date());
}
it('is exported as function', function () {
assume(requests).is.a('function');
});
it('increments the internal `.id` for each instance', function () {
var id = req.id;
assume(id).equals(Requested.requested);
req.destroy();
req = requests(unique('http://localhost:8080'), { manual: true });
assume(req.id).is.above(id);
assume(Requested.requested).is.above(id);
});
it('sets the stream\'s booleans', function () {
assume(req.readable).is.true();
assume(req.writable).is.false();
});
it('stores active requests', function () {
assume(requests.active[req.id]).equals(req);
});
it('does not receive content for 204 requests', function (done) {
req.destroy();
req = requests(unique('http://localhost:8080/204'));
req.on('data', function () {
throw new Error('I should never be called');
});
req.on('end', done);
});
it('can handle large files with streaming', function (done) {
this.timeout(3E4);
req = requests(unique('http://localhost:8080/unshiftio/requests/master/test/large.js'), {
streaming: true
});
var buffer = [];
req.on('data', function received(chunk) {
buffer.push(chunk);
});
req.on('error', done);
req.once('end', function end(err, status) {
assume(buffer.length).to.be.above(1);
assume(buffer.join('').length).equals(2127897);
assume(status.code).to.equal(200);
assume(status.text).to.equal('OK');
buffer = null;
done();
});
});
describe('#destroy', function () {
it('removes the .active instance', function () {
assume(requests.active[req.id]).equals(req);
req.destroy();
assume(requests.active[req.id]).is.undefined();
});
});
});

100
node_modules/requests/test/requests.test.js generated vendored Normal file
View file

@ -0,0 +1,100 @@
'use strict';
var path = require('path');
var fs = require('fs');
var assume = require('assume');
var requests = require('../');
var staticserver = require('./static');
/**
* Make a URL unique so we can bust the browser cache which could affect
*
* @param {String} url Transform to an URL.
* @returns {String} A unique URL.
* @api private
*/
function unique(url) {
return url + '?t=' + (+new Date());
}
describe('requests', function () {
var closeServer;
var req;
before(function (done) {
//
// Start-up a small static file server so we can download files and fixtures
// inside our tests.
//
staticserver(function (close) {
closeServer = close;
}, done);
});
after(function (done) {
closeServer(done);
});
beforeEach(function () {
req = requests(unique('http://localhost:8080/index.html'), { manual: true });
});
afterEach(function () {
req.destroy();
});
it('is exported as function', function () {
assume(requests).is.a('function');
});
it('sets the stream\'s booleans', function () {
assume(req.readable).is.true();
assume(req.writable).is.false();
});
it('stores active requests', function () {
assume(requests.active[req.id]).equals(req);
});
it('successfully makes a request', function (done) {
var resp = '';
req.on('data', function (data) {
resp += data;
});
req.on('end', function () {
fs.readFile(
path.resolve(__dirname, 'index.html'),
{ encoding: 'utf8' },
function (err, file) {
if (err) {
throw err;
}
assume(resp).equals(file);
done();
}
);
});
req.open();
});
it('does not receive content for 204 requests', function (done) {
req.destroy();
req = requests(unique('http://localhost:8080/204'));
req.on('data', function () {
throw new Error('I should never be called');
});
req.on('end', done);
});
describe('#destroy', function () {
it('removes the .active instance', function () {
assume(requests.active[req.id]).equals(req);
req.destroy();
assume(requests.active[req.id]).is.undefined();
});
});
});

50
node_modules/requests/test/static.js generated vendored Normal file
View file

@ -0,0 +1,50 @@
'use strict';
var fs = require('fs')
, url = require('url')
, path = require('path')
, http = require('http')
, setHeader = require('setheader')
, httpProxy = require('http-proxy');
module.exports = function staticserver(kill, next) {
var proxy = httpProxy.createProxyServer({});
var server = http.createServer(function serve(req, res) {
var file = path.join(__dirname, url.parse(req.url).pathname);
setHeader(res, 'Access-Control-Allow-Origin', req.headers.origin || '*');
setHeader(res, 'Access-Control-Allow-Credentials', 'true');
if (~req.url.indexOf('/204')) {
res.statusCode = 204;
return res.end('');
}
if (!fs.existsSync(file)) {
req.headers.host = '';
setHeader(res, 'Content-Security-Policy', 'removed');
return proxy.web(req, res, { target: 'https://raw.githubusercontent.com' });
}
res.statusCode = 200;
fs.createReadStream(file).pipe(res);
});
kill(function close(next) {
server.close(next);
proxy.close();
});
server.listen(8080, next);
};
//
// Static server loaded directly.
//
if (require.main === module) module.exports(function kill() {
}, function next(err) {
if (err) throw err;
console.log('static server listening on ', this.address());
});