superagent-no-cache
Advanced tools
Comparing version
18
index.js
@@ -1,10 +0,11 @@ | ||
var ie | ||
try { | ||
ie = require('ie') | ||
} catch (e) { | ||
ie = require('component-ie') | ||
} | ||
var ie = require('component-ie') | ||
function with_query_strings (request) { | ||
request._query = [Date.now().toString()] | ||
var timestamp = Date.now().toString() | ||
if (request._query !== undefined && request._query[0]) { | ||
request._query[0] += '&' + timestamp | ||
} else { | ||
request._query = [timestamp] | ||
} | ||
return request | ||
@@ -15,3 +16,4 @@ } | ||
request.set('X-Requested-With', 'XMLHttpRequest') | ||
request.set('Cache-Control', 'no-cache,no-store,must-revalidate,max-age=-1') | ||
request.set('Expires', '-1') | ||
request.set('Cache-Control', 'no-cache,no-store,must-revalidate,max-age=-1,private') | ||
@@ -18,0 +20,0 @@ if (ie || mockIE) { |
@@ -5,3 +5,3 @@ { | ||
"description": "Plugin for visionmedia/superagent that adds headers to all requests that prevents caching", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "superagent", |
@@ -6,7 +6,5 @@ | ||
caching | ||
*Note:* Until TJ merges [my pull request](https://github.com/visionmedia/superagent/pull/293) adding plugin support, you must use johntron/supermedia | ||
## Installation | ||
### Using Component | ||
Install with [component(1)](http://component.io): | ||
@@ -17,15 +15,47 @@ | ||
``` | ||
### Using NPM / Browserify | ||
```bash | ||
$ npm install --save superagent-no-cache | ||
``` | ||
## API | ||
```javascript | ||
var request = require('request'), | ||
no_cache = require('superagent-no-cache'); | ||
var request = require('superagent') | ||
var noCache = require('superagent-no-cache') | ||
request.get('/url') | ||
.use(no_cache) | ||
.end(function () { | ||
.use(noCache) | ||
.end(function _requestCallback() { | ||
// do something | ||
}); | ||
``` | ||
## Contributing | ||
To run the tests install mocha and run: | ||
```bash | ||
$ mocha test/superagent-no-cache.test.js | ||
``` | ||
## License | ||
MIT | ||
The MIT License (MIT) | ||
Copyright (c) 2015 John Syrinek | ||
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. |
@@ -22,2 +22,3 @@ var expect = require('chai').expect | ||
it('should add an additional query for IE browsers', _specIE) | ||
it('should add an additional param to an existing query string for IE browsers', _specIEExistingQuery) | ||
} | ||
@@ -44,3 +45,3 @@ | ||
expect(error.toString()) | ||
.to.equal('TypeError: undefined is not a function') | ||
.to.contain('TypeError') | ||
done() | ||
@@ -64,3 +65,3 @@ } | ||
expect(results.data['Cache-Control']) | ||
.to.equal('no-cache,no-store,must-revalidate,max-age=-1') | ||
.to.equal('no-cache,no-store,must-revalidate,max-age=-1,private') | ||
@@ -81,3 +82,3 @@ expect(results._query) | ||
expect(results.data['Cache-Control']) | ||
.to.equal('no-cache,no-store,must-revalidate,max-age=-1') | ||
.to.equal('no-cache,no-store,must-revalidate,max-age=-1,private') | ||
expect(results._query) | ||
@@ -91,2 +92,21 @@ .to.be.an('array') | ||
} | ||
function _specIEExistingQuery (done) { | ||
var request = { | ||
set:_mockSet, | ||
_query: ['param=123'], // random query string | ||
data:{} | ||
}; | ||
var results = nocache(request, true); | ||
expect(results.data['X-Requested-With']) | ||
.to.equal('XMLHttpRequest') | ||
expect(results.data['Cache-Control']) | ||
.to.equal('no-cache,no-store,must-revalidate,max-age=-1,private') | ||
expect(results._query) | ||
.to.be.an('array') | ||
expect(results._query[0]) | ||
.to.be.a('string') | ||
expect(results._query[0]) | ||
.to.match(/^param=123&[0-9].*$/) | ||
done(); | ||
} | ||
@@ -93,0 +113,0 @@ /* Mocks */ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
6898
39.33%130
19.27%60
100%0
-100%