superagent-cache
Advanced tools
Comparing version 1.3.4 to 1.3.5
{ | ||
"name": "superagent-cache", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "Superagent with flexible built-in caching.", | ||
"main": "superagentCache.js", | ||
"dependencies": { | ||
"superagent": "1.6.1", | ||
"superagent": "1.7.2", | ||
"cache-service-cache-module": "1.2.2" | ||
@@ -9,0 +9,0 @@ }, |
@@ -5,3 +5,3 @@ # superagent-cache | ||
Upgrading from an older version? Please see the [Breaking Change History](#breaking-change-history) section. | ||
Upgrading from an older version or seeing a bug? Please see the [Breaking Change History](#breaking-change-history) section. | ||
@@ -449,2 +449,8 @@ # Basic Usage | ||
#### 1.3.5 | ||
In superagent `1.7.0`, the superagent team introduced some internal changes to how they handle headers. As a result, you must use superagent-cache `1.3.5` or later to be compatible with superagent `1.7.0` or later. All versions of superagent-cache (to this point) should be backwards compatible with all versions of superagent going back to at least version `1.1.0`. To be clear, this was no one's fault. However, I have reached out to the superagent team to see what I can do to help minimize internally breaking changes in the future. | ||
If you're seeing other incompatibilities, please submit an issue. | ||
#### 1.0.6 | ||
@@ -451,0 +457,0 @@ |
@@ -113,3 +113,2 @@ var utils = require('./utils'); | ||
Request.prototype.end = function(cb){ | ||
var _this = this; | ||
var curProps = props; | ||
@@ -150,7 +149,7 @@ props = utils.resetProps(superagent.defaults); | ||
superagent.cache.set(key, response, curProps.expiration, refresh, function (){ | ||
utils.callbackExecutor(cb, err, response, key); | ||
return utils.callbackExecutor(cb, err, response, key); | ||
}); | ||
} | ||
else{ | ||
utils.callbackExecutor(cb, err, response, key); | ||
return utils.callbackExecutor(cb, err, response, key); | ||
} | ||
@@ -161,3 +160,3 @@ } | ||
else{ | ||
utils.callbackExecutor(cb, null, null, key); | ||
return utils.callbackExecutor(cb, null, null, key); | ||
} | ||
@@ -184,3 +183,3 @@ } | ||
this._end(function (err, response){ | ||
utils.callbackExecutor(cb, err, response, undefined); | ||
return utils.callbackExecutor(cb, err, response, undefined); | ||
}); | ||
@@ -187,0 +186,0 @@ } |
@@ -50,2 +50,6 @@ var name = require.resolve('superagent'); | ||
app.get('/404', function(req, res){ | ||
res.send(404); | ||
}); | ||
app.listen(3000); | ||
@@ -205,5 +209,10 @@ | ||
expect(response.body.otherOptions).toBe('false'); | ||
//Superagent converts headers to lower case so I check here for lower case versions of the headers sent above | ||
//Before superagent 1.7.0, superagent converts headers to lower case. To be backwards compatible, | ||
//I check for lower as well as the upper case versions of the headers sent above | ||
expect(key.indexOf('pruneoptions')).toBe(-1); | ||
expect(key.indexOf('otheroptions')).toBeGreaterThan(-1); | ||
expect(key.indexOf('pruneOptions')).toBe(-1); | ||
var lowerOtherOptions = key.indexOf('otheroptions'); | ||
var upperOtherOptions = key.indexOf('otherOptions'); | ||
var otherOptionsIsPresent = (lowerOtherOptions > -1 || upperOtherOptions > -1); | ||
expect(otherOptionsIsPresent).toBe(true); | ||
done(); | ||
@@ -210,0 +219,0 @@ } |
@@ -50,2 +50,6 @@ var name = require.resolve('superagent'); | ||
app.get('/404', function(req, res){ | ||
res.send(404); | ||
}); | ||
app.listen(3000); | ||
@@ -52,0 +56,0 @@ |
@@ -65,2 +65,6 @@ var name = require.resolve('superagent'); | ||
app.get('/404', function(req, res){ | ||
res.send(404); | ||
}); | ||
app.listen(3000); | ||
@@ -133,3 +137,3 @@ | ||
.end(function (err, response, key){ | ||
expect(key).toBe('{"method":"GET","uri":"http://localhost:3000/redirect","params":null,"options":null}'); | ||
expect(key).toBe('{"method":"GET","uri":"http://localhost:3000/redirect","params":null,"options":{}}'); | ||
expect(response.body.key).toBe('one'); | ||
@@ -188,2 +192,12 @@ superagent.cache.get(key, function (err, response) { | ||
it('.get(404) .end() should fire', function (done) { | ||
superagent | ||
.get('localhost:3000/404') | ||
.end(function (err, response, key){ | ||
expect(true).toBe(true); | ||
done(); | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -190,0 +204,0 @@ |
@@ -51,2 +51,6 @@ var name = require.resolve('superagent'); | ||
app.get('/404', function(req, res){ | ||
res.send(404); | ||
}); | ||
app.listen(3000); | ||
@@ -53,0 +57,0 @@ |
16
utils.js
@@ -51,8 +51,12 @@ module.exports = { | ||
getHeaderOptions: function(req){ | ||
if(req && req.req && req.req._headers){ | ||
return req.req._headers; | ||
//I have to remove the User-Agent header ever since superagent 1.7.0 | ||
if(req && req._header){ | ||
return this.pruneObj(req._header, ['User-Agent', 'user-agent']); | ||
} | ||
else if(req && req._header){ | ||
return req._header; | ||
else if(req && req.req && req.req._headers){ | ||
return this.pruneObj(req.req._headers, ['User-Agent', 'user-agent']); | ||
} | ||
else if(req && req.header){ | ||
return this.pruneObj(req.header, ['User-Agent', 'user-agent']); | ||
} | ||
return null; | ||
@@ -112,5 +116,5 @@ }, | ||
if(isOptions){ | ||
prop = prop.toLowerCase(); | ||
delete obj[prop.toLowerCase()]; | ||
} | ||
delete obj[prop] | ||
delete obj[prop]; | ||
} | ||
@@ -117,0 +121,0 @@ return obj; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61501
1183
461
+ Addedcomponent-emitter@1.2.1(transitive)
+ Addedextend@3.0.0(transitive)
+ Addedformidable@1.0.17(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedsuperagent@1.7.2(transitive)
- Removedcomponent-emitter@1.1.2(transitive)
- Removedextend@1.2.1(transitive)
- Removedformidable@1.0.14(transitive)
- Removedmethods@1.0.1(transitive)
- Removedsuperagent@1.6.1(transitive)
Updatedsuperagent@1.7.2