Browse Source

Style tweaks

master
Kornel Lesiński 8 years ago
parent
commit
7791675bcf
  1. 25
      index.js

25
index.js

@ -348,28 +348,29 @@ module.exports = class CachePolicy {
}; };
} }
validationRequest(req) { validationRequest(incoming_req) {
this._assertRequestHasHeaders(req); this._assertRequestHasHeaders(incoming_req);
if (!(this._resHeaders.etag || this._resHeaders["last-modified"])) { if (!this._resHeaders.etag && !this._resHeaders["last-modified"]) {
return null; // no validators available return incoming_req; // no validators available
} }
// revalidation allowed via HEAD // revalidation allowed via HEAD
if (!this._requestMatches(req, true)) { if (!this._requestMatches(incoming_req, true)) {
return null; // not for the same resource return incoming_req; // not for the same resource
} }
const vreq = Object.assign({}, req);
vreq.headers = Object.assign({}, req.headers); const upstream_req = Object.assign({}, incoming_req);
upstream_req.headers = Object.assign({}, incoming_req.headers);
/* MUST send that entity-tag in any cache validation request (using If-Match or If-None-Match) if an entity-tag has been provided by the origin server. */ /* MUST send that entity-tag in any cache validation request (using If-Match or If-None-Match) if an entity-tag has been provided by the origin server. */
if (this._resHeaders.etag) { if (this._resHeaders.etag) {
vreq.headers['if-none-match'] = this._resHeaders.etag; upstream_req.headers['if-none-match'] = this._resHeaders.etag;
} }
/* SHOULD send the Last-Modified value in non-subrange cache validation requests (using If-Modified-Since) if only a Last-Modified value has been provided by the origin server. /* SHOULD send the Last-Modified value in non-subrange cache validation requests (using If-Modified-Since) if only a Last-Modified value has been provided by the origin server.
Note: This implementation does not understand partial responses (206) */ Note: This implementation does not understand partial responses (206) */
if (this._resHeaders['last-modified']) { if (this._resHeaders['last-modified'] && this.storable()) {
vreq.headers['if-modified-since'] = this._resHeaders['last-modified']; upstream_req.headers['if-modified-since'] = this._resHeaders['last-modified'];
} }
return vreq; return upstream_req;
} }
}; };

Loading…
Cancel
Save