put HTTP requests in a tasks-queue to execute them sequentially but not too often
Install the module with:
npm install request-queue
The class for the HTTP request queue. Inherits from TasksQueue.
It hides the methods
TasksQueue.prototype.pushTask
and TasksQueue.prototype.unshiftTask
. Use
RequestQueue.prototype.pushRequest()
and RequestQueue.prototype.unshiftRequest()
methods instead.
RequestQueue
depends on the following modules:
Set default options for the request.
See request.defaults()
. See also Encoding issue below.
Add scripts paths or URLs that are passed to jsdom.env as
scripts
option.
Return an array of paths added with addScripts(paths)
.
Insert a request to the queue.
pushRequest(t, o)
is equivalent to addRequesr('tail', t, o)
.
unshiftRequest(t, o)
is equivalent to addRequesr('head', t, o)
.
If where
equals to 'head', addRequest()
prepends the request
to the head of the queue, otherwise it appends it to the
tail.
requestType
is a string, used to distinguish the different
types of requests. Don't use strings that start with double colon
("::type").
requestOptions
are passed to
request(requestOptions, callback) that
does the actual http request.
The requestType
event is emitted when the response is retrieved
and the DOM construction is done. Listeners are called with three arguments:
- Jinn instance (See tasks-queue)
- errors (See jsdom.env callback arguments)
- window (See jsdom.env callback arguments)
request
fails to work with encodings that are not supported by
ReadebleStream.
request-queue uses iconv to solve that. It uses
the response header "content-type" to detect the encoding name. If no charset is
specified in "content-type" header, 'utf8' is used. Optionally you may
override the encoding, using queue.setRequestDefaults({encoding:<your encoding>});
.
Note, that <your encoding>
is used by iconv, while {encoding:"binary"}
option
is passed to request
.
See examples directory
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
-
April 17, 2013. V. 0.0.2 Fixed encoding issue
-
April 1, 2013. V. 0.0.1. Basic functionality
Copyright (c) 2013 Andrei V. Toutoukine Licensed under the MIT license.