Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-disk-cache

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-disk-cache - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

33

middleware.js

@@ -7,3 +7,3 @@ var Buffer = require("safe-buffer").Buffer;

var fs = require("fs-extra");
var debug = function() {};
var debug = function () {};

@@ -18,3 +18,3 @@ // Regex to check the Cache-Control header to

module.exports = function(cache_directory) {
module.exports = function (cache_directory) {
var tmp_directory;

@@ -31,7 +31,7 @@

var stream, final_path, tmp_path, tmp_name, protocol;
var content_type, cache_control, has_max_age, cache_age;
var content_type, cache_control, has_max_age, category;
var _write = res.write;
var _end = res.end;
res.write = function(chunk, encoding) {
res.write = function (chunk, encoding) {
debug("write called", chunk, encoding);

@@ -60,3 +60,3 @@

res.end = function(chunk, encoding) {
res.end = function (chunk, encoding) {
debug("end called", chunk, encoding);

@@ -119,3 +119,3 @@

// code for the cache to send which needlessly complicates it.
if (res.statusCode !== 200) {
if (res.statusCode !== 200 && res.statusCode !== 404) {
debug("BAD status " + req.originalUrl + " " + res.statusCode);

@@ -152,3 +152,3 @@ return;

// points will no longer exist. There are probably other errors here too.
stream.on("error", function(err) {
stream.on("error", function (err) {
debug(err);

@@ -169,5 +169,16 @@ stream.close();

has_max_age = cache_control && cache_control.indexOf("max-age") > -1;
cache_age = has_max_age ? "permanent" : "temporary";
protocol = req.protocol;
// Determine the category for the response:
// - temporary means don't set a max-age
// - permanent means the file will never change
// - missing means the response was sent with a 404 status
if (res.statusCode === 404) {
category = "missing";
} else if (has_max_age) {
category = "permanent";
} else {
category = "temporary";
}
// Trust header added by proxy indicating that before the proxy

@@ -188,3 +199,3 @@ // the request was over HTTPS. This could be spoofed, but the worst

protocol, // protocol to allow us to preserve HTTP -> HTTPS redirects
cache_age, // cache_age, either permanent or temporary
category, // either permanent, temporary or missing (for 404s)
req.originalUrl

@@ -201,3 +212,3 @@ );

// containing the full, successfully-sent response to this request.
fs.move(tmp_path, final_path, { overwrite: true }, function(err) {
fs.move(tmp_path, final_path, { overwrite: true }, function (err) {
if (!err) return; // We moved the file successfully

@@ -209,3 +220,3 @@

debug(err);
fs.remove(tmp_path, function(err) {
fs.remove(tmp_path, function (err) {
// Nothing else we can really do here

@@ -212,0 +223,0 @@ if (err) debug(err);

{
"name": "express-disk-cache",
"version": "1.0.4",
"version": "1.1.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "license": "CC0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc