Skip to content

Commit

Permalink
transports: use yeast to generate the cache busting id
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Sep 12, 2015
1 parent b401885 commit 874484c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
7 changes: 0 additions & 7 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ function Transport (opts) {

Emitter(Transport.prototype);

/**
* A counter used to prevent collisions in the timestamps used
* for cache busting.
*/

Transport.timestamps = 0;

/**
* Emits an error.
*
Expand Down
3 changes: 2 additions & 1 deletion lib/transports/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Transport = require('../transport');
var parseqs = require('parseqs');
var parser = require('engine.io-parser');
var inherit = require('component-inherit');
var yeast = require('yeast');
var debug = require('debug')('engine.io-client:polling');

/**
Expand Down Expand Up @@ -221,7 +222,7 @@ Polling.prototype.uri = function(){

// cache busting is forced
if (false !== this.timestampRequests) {
query[this.timestampParam] = +new Date + '-' + Transport.timestamps++;
query[this.timestampParam] = yeast();
}

if (!this.supportsBinary && !query.sid) {
Expand Down
3 changes: 2 additions & 1 deletion lib/transports/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Transport = require('../transport');
var parser = require('engine.io-parser');
var parseqs = require('parseqs');
var inherit = require('component-inherit');
var yeast = require('yeast');
var debug = require('debug')('engine.io-client:websocket');

/**
Expand Down Expand Up @@ -229,7 +230,7 @@ WS.prototype.uri = function(){

// append timestamp to URI
if (this.timestampRequests) {
query[this.timestampParam] = +new Date;
query[this.timestampParam] = yeast();
}

// communicate binary support capabilities
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"parseuri": "0.0.4",
"parsejson": "0.0.1",
"parseqs": "0.0.2",
"component-inherit": "0.0.3"
"component-inherit": "0.0.3",
"yeast": "0.1.2"
},
"devDependencies": {
"blob": "0.0.2",
Expand Down
4 changes: 2 additions & 2 deletions test/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('Transport', function () {
, timestampParam: 't'
, timestampRequests: true
});
expect(polling.uri()).to.match(/http:\/\/localhost\/engine\.io\?(j=[0-9]+&)?(t=[0-9]+)/);
expect(polling.uri()).to.match(/http:\/\/localhost\/engine\.io\?(j=[0-9]+&)?(t=[0-9A-Za-z-_]+)/);
});

it('should generate a ws uri', function () {
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('Transport', function () {
, timestampParam: 'woot'
, timestampRequests: true
});
expect(ws.uri()).to.match(/ws:\/\/localhost\/engine\.io\?woot=[0-9]+/);
expect(ws.uri()).to.match(/ws:\/\/localhost\/engine\.io\?woot=[0-9A-Za-z-_]+/);
});
});

Expand Down

0 comments on commit 874484c

Please sign in to comment.