Skip to content

Commit

Permalink
v3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvachon committed Aug 21, 2016
1 parent a9ab243 commit 2b314e8
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 56 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ new RequestQueue(options, handlers);
Removes a queue item from the queue. Use of this function is likely not needed as items are auto-dequeued when their turn is reached. Returns `true` on success or an `Error` on failure.

### `.enqueue(input)`
Adds a URL to the queue. `input` can either be a URL `String` or a [`URL`](https://developer.mozilla.org/en/docs/Web/API/URL/)-compatible `Object`. Returns a queue ID on success or an `Error` on failure.
Adds a URL to the queue. `input` can either be a URL `String` or a configuration `Object`. Returns a queue ID on success or an `Error` on failure.

If `input` is an `Object`, it will acccept the following keys:
If `input` is an `Object`, it will accept the following keys:

* `url`: a URL `String` or `URL`-compatible `Object`.
* `url`: a URL `String`, [`URL`](https://developer.mozilla.org/en/docs/Web/API/URL/) or [Node URL](https://nodejs.org/api/url.html#url_url_strings_and_url_objects)-compatible `Object`.
* `data`: additional data to be stored in the queue item.
* `id`: a unique ID (`String` or `Number`). If not defined, one will be generated.

Expand Down
2 changes: 1 addition & 1 deletion browser/requestqueue.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/defaultOptions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
var defaultOptions =
{
defaultPorts: {ftp:21, http:80, https:443},
defaultPorts: {ftp:21, http:80, https:443}, // TODO :: empty this when removing node.js url support
ignorePorts: true,
ignoreSchemes: true,
ignoreSubdomains: true,
Expand Down
8 changes: 7 additions & 1 deletion lib/getHostKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ function getHostKey(url, options)
{
var key,port,protocol,urlDomain;

if (isString(url) === true)
if (url == null)
{
return false;
}
else if (isString(url) === true)
{
try
{
Expand All @@ -38,6 +42,7 @@ function getHostKey(url, options)

protocol = url.protocol;

// TODO :: remove support for node-js url.parse objects
if (isEmptyString(protocol)===true || isEmptyString(url.hostname)===true)
{
return false;
Expand All @@ -52,6 +57,7 @@ function getHostKey(url, options)
port = url.port;

// Get default port
// TODO :: remove support for node-js url.parse objects
if (isEmptyStringOrNumber(port)===true && options.defaultPorts[protocol]!==undefined)
{
port = options.defaultPorts[protocol];
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ RequestQueue.prototype.enqueue = function(input)
var idOrError;

// enqueue("url")
if (isString(input) === true)
if (input==null || isString(input)===true)
{
input = { url:input };
}
Expand Down
21 changes: 5 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
{
"name": "limited-request-queue",
"description": "Interactively manage concurrency for outbound requests.",
"version": "3.0.2",
"version": "3.0.3",
"license": "MIT",
"homepage": "https://github.com/stevenvachon/limited-request-queue",
"author": {
"name": "Steven Vachon",
"email": "[email protected]",
"url": "http://www.svachon.com/"
},
"author": "Steven Vachon <[email protected]> (https://www.svachon.com/)",
"main": "lib",
"repository": {
"type": "git",
"url": "git://github.com/stevenvachon/limited-request-queue.git"
},
"bugs": {
"url": "https://github.com/stevenvachon/limited-request-queue/issues"
},
"repository": "stevenvachon/limited-request-queue",
"dependencies": {
"is-browser": "^2.0.1",
"is-string": "^1.0.4",
Expand All @@ -29,8 +18,8 @@
"mocha": "^3.0.2",
"mocha-phantomjs": "4.1.0",
"object.assign": "^4.0.4",
"phantomjs-prebuilt": "^2.1.11",
"uglify-js": "^2.7.0"
"phantomjs-prebuilt": "^2.1.12",
"uglify-js": "^2.7.3"
},
"engines": {
"node": ">= 4"
Expand Down
89 changes: 60 additions & 29 deletions test/server/0.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ var getHostKey = require("../../lib/getHostKey");
var helpers = require("./helpers");

var expect = require("chai").expect;
var parseUrl = require("url").parse;
var URL = require("whatwg-url").URL;



describe("Internal API", () =>
describe("Internal API", function()
{
describe("getHostKey", () =>
describe("getHostKey", function()
{
it("works", () =>
it("supports String input", function()
{
var options = helpers.options();

Expand All @@ -20,53 +22,82 @@ describe("Internal API", () =>



it("supports options.ignorePorts=true", () =>
it("supports URL input", function()
{
var options = helpers.options({ ignorePorts:true });
var options = helpers.options();

expect( getHostKey("https://www.google.com:8080/",options) ).to.equal("https://www.google.com/");
expect( getHostKey("https://127.0.0.1/",options) ).to.equal("https://127.0.0.1/");
expect( getHostKey( new URL("https://www.google.com:8080/"),options) ).to.equal("https://www.google.com:8080/");
expect( getHostKey( new URL("https://127.0.0.1:8080/"),options) ).to.equal("https://127.0.0.1:8080/");
});



it("supports options.ignoreSchemes=true", () =>
it("supports Node URL input", function()
{
var options = helpers.options({ ignoreSchemes:true });
var options = helpers.options();

expect( getHostKey("https://www.google.com:8080/",options) ).to.equal("www.google.com:8080/");
expect( getHostKey("https://127.0.0.1:8080/",options) ).to.equal("127.0.0.1:8080/");
expect( getHostKey( parseUrl("https://www.google.com:8080/"),options) ).to.equal("https://www.google.com:8080/");
expect( getHostKey( parseUrl("https://127.0.0.1:8080/"),options) ).to.equal("https://127.0.0.1:8080/");
});



it("supports options.ignoreSubdomains=true", () =>
it("rejects invalid input", function()
{
var options = helpers.options({ ignoreSubdomains:true });
var options = helpers.options();

expect( getHostKey("https://www.google.com:8080/",options) ).to.equal("https://google.com:8080/");
expect( getHostKey("https://127.0.0.1:8080/",options) ).to.equal("https://127.0.0.1:8080/");
expect( getHostKey("/path/",options) ).to.be.false;
expect( getHostKey("resource.html",options) ).to.be.false;
expect( getHostKey("",options) ).to.be.false;
expect( getHostKey({},options) ).to.be.false;
expect( getHostKey([],options) ).to.be.false;
expect( getHostKey(true,options) ).to.be.false;
expect( getHostKey(0,options) ).to.be.false;
expect( getHostKey(null,options) ).to.be.false;
expect( getHostKey(undefined,options) ).to.be.false;
});



it("supports all options true", () =>
describe("Options", function()
{
var options = helpers.options({ ignorePorts:true, ignoreSchemes:true, ignoreSubdomains:true });
it("ignorePorts = true", function()
{
var options = helpers.options({ ignorePorts:true });

expect( getHostKey("https://www.google.com:8080/",options) ).to.equal("https://www.google.com/");
expect( getHostKey("https://127.0.0.1/",options) ).to.equal("https://127.0.0.1/");
});

expect( getHostKey("https://www.google.com:8080/",options) ).to.equal("google.com/");
expect( getHostKey("https://127.0.0.1:8080/",options) ).to.equal("127.0.0.1/");
});



it("rejects erroneous URLs", () =>
{
var options = helpers.options();

expect( getHostKey("/path/",options) ).to.be.false;
expect( getHostKey("resource.html",options) ).to.be.false;
expect( getHostKey("",options) ).to.be.false;

it("ignoreSchemes = true", function()
{
var options = helpers.options({ ignoreSchemes:true });

expect( getHostKey("https://www.google.com:8080/",options) ).to.equal("www.google.com:8080/");
expect( getHostKey("https://127.0.0.1:8080/",options) ).to.equal("127.0.0.1:8080/");
});



it("ignoreSubdomains = true", function()
{
var options = helpers.options({ ignoreSubdomains:true });

expect( getHostKey("https://www.google.com:8080/",options) ).to.equal("https://google.com:8080/");
expect( getHostKey("https://127.0.0.1:8080/",options) ).to.equal("https://127.0.0.1:8080/");
});



it("all options true", function()
{
var options = helpers.options({ ignorePorts:true, ignoreSchemes:true, ignoreSubdomains:true });

expect( getHostKey("https://www.google.com:8080/",options) ).to.equal("google.com/");
expect( getHostKey("https://127.0.0.1:8080/",options) ).to.equal("127.0.0.1/");
});
});
});
});
14 changes: 10 additions & 4 deletions test/server/1.public.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var helpers = require("./helpers");
var RequestQueue = require("../../lib");

var expect = require("chai").expect;
var parseUrl = require("url").parse;
var URL = require("whatwg-url").URL;
var urllib = require("url");



Expand All @@ -22,7 +22,7 @@ describe("Public API", function()
[
helpers.urls[0],
{ url:helpers.urls[0] },
{ url:urllib.parse(helpers.urls[0]) },
{ url:parseUrl(helpers.urls[0]) },
{ url:new URL(helpers.urls[0]) }

].forEach(url =>
Expand Down Expand Up @@ -61,8 +61,14 @@ describe("Public API", function()
"/path/",
"resource.html",
"",
{ url:urllib.parse("/path/") },
{ url:{} }
1,
null,
{ url:parseUrl("/path/") },
{ url:{} },
{ url:[] },
{ url:"/path/" },
{ url:1 },
{ url:null }

].forEach(url =>
{
Expand Down

0 comments on commit 2b314e8

Please sign in to comment.