forked from svrjs/svrjs
Fix HTML MIME type in cached requests, regardless of the extension
This commit is contained in:
parent
33fde81ba1
commit
4eb2987f01
5 changed files with 11 additions and 11 deletions
|
@ -7,13 +7,13 @@ const generateServerString = require("../utils/generateServerString.js");
|
||||||
let serverconsole = {};
|
let serverconsole = {};
|
||||||
|
|
||||||
function clientErrorHandler(err, socket) {
|
function clientErrorHandler(err, socket) {
|
||||||
const config = Object.assign(process.serverConfig);
|
const config = Object.assign({}, process.serverConfig);
|
||||||
|
|
||||||
config.generateServerString = () =>
|
config.generateServerString = () =>
|
||||||
generateServerString(config.exposeServerVersion);
|
generateServerString(config.exposeServerVersion);
|
||||||
|
|
||||||
// getCustomHeaders() in SVR.JS 3.x
|
// getCustomHeaders() in SVR.JS 3.x
|
||||||
config.getCustomHeaders = () => Object.assign(config.customHeaders);
|
config.getCustomHeaders = () => Object.assign({}, config.customHeaders);
|
||||||
|
|
||||||
// Prevent multiple error handlers from one request
|
// Prevent multiple error handlers from one request
|
||||||
if (socket.__assigned__) {
|
if (socket.__assigned__) {
|
||||||
|
@ -54,7 +54,7 @@ function clientErrorHandler(err, socket) {
|
||||||
if (code >= 400 && code <= 499) process.err4xxcounter++;
|
if (code >= 400 && code <= 499) process.err4xxcounter++;
|
||||||
if (code >= 500 && code <= 599) process.err5xxcounter++;
|
if (code >= 500 && code <= 599) process.err5xxcounter++;
|
||||||
let head = "HTTP/1.1 " + code.toString() + " " + name + "\r\n";
|
let head = "HTTP/1.1 " + code.toString() + " " + name + "\r\n";
|
||||||
headers = Object.assign(headers);
|
headers = Object.assign({}, headers);
|
||||||
headers["Date"] = new Date().toGMTString();
|
headers["Date"] = new Date().toGMTString();
|
||||||
headers["Connection"] = "close";
|
headers["Connection"] = "close";
|
||||||
Object.keys(headers).forEach(function (headername) {
|
Object.keys(headers).forEach(function (headername) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ function noproxyHandler(req, socket, head) {
|
||||||
socket.on("error", () => {});
|
socket.on("error", () => {});
|
||||||
|
|
||||||
// SVR.JS configuration object (modified)
|
// SVR.JS configuration object (modified)
|
||||||
const config = Object.assign(process.serverConfig);
|
const config = Object.assign({}, process.serverConfig);
|
||||||
|
|
||||||
var reqip = socket.remoteAddress;
|
var reqip = socket.remoteAddress;
|
||||||
var reqport = socket.remotePort;
|
var reqport = socket.remotePort;
|
||||||
|
|
|
@ -29,7 +29,7 @@ function proxyHandler(req, socket, head) {
|
||||||
socket.on("error", () => {});
|
socket.on("error", () => {});
|
||||||
|
|
||||||
// SVR.JS configuration object (modified)
|
// SVR.JS configuration object (modified)
|
||||||
const config = Object.assign(process.serverConfig);
|
const config = Object.assign({}, process.serverConfig);
|
||||||
|
|
||||||
config.generateServerString = () => {
|
config.generateServerString = () => {
|
||||||
return generateServerString(config.exposeServerVersion);
|
return generateServerString(config.exposeServerVersion);
|
||||||
|
|
|
@ -29,7 +29,7 @@ function requestHandler(req, res) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// SVR.JS configuration object (modified)
|
// SVR.JS configuration object (modified)
|
||||||
const config = Object.assign(process.serverConfig);
|
const config = Object.assign({}, process.serverConfig);
|
||||||
|
|
||||||
config.generateServerString = () => {
|
config.generateServerString = () => {
|
||||||
return generateServerString(config.exposeServerVersion);
|
return generateServerString(config.exposeServerVersion);
|
||||||
|
@ -37,7 +37,7 @@ function requestHandler(req, res) {
|
||||||
|
|
||||||
// getCustomHeaders() in SVR.JS 3.x
|
// getCustomHeaders() in SVR.JS 3.x
|
||||||
config.getCustomHeaders = () => {
|
config.getCustomHeaders = () => {
|
||||||
let ph = Object.assign(config.customHeaders);
|
let ph = Object.assign({}, config.customHeaders);
|
||||||
if (config.customHeadersVHost) {
|
if (config.customHeadersVHost) {
|
||||||
let vhostP = null;
|
let vhostP = null;
|
||||||
config.customHeadersVHost.every(function (vhost) {
|
config.customHeadersVHost.every(function (vhost) {
|
||||||
|
@ -52,7 +52,7 @@ function requestHandler(req, res) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (vhostP && vhostP.headers) {
|
if (vhostP && vhostP.headers) {
|
||||||
const phNu = Object.assign(vhostP.headers);
|
const phNu = Object.assign({}, vhostP.headers);
|
||||||
Object.keys(phNu).forEach(function (phNuK) {
|
Object.keys(phNu).forEach(function (phNuK) {
|
||||||
ph[phNuK] = phNu[phNuK];
|
ph[phNuK] = phNu[phNuK];
|
||||||
});
|
});
|
||||||
|
@ -80,7 +80,7 @@ function requestHandler(req, res) {
|
||||||
if (typeof b == "object") table = b;
|
if (typeof b == "object") table = b;
|
||||||
if (table == undefined) table = this.tHeaders;
|
if (table == undefined) table = this.tHeaders;
|
||||||
if (table == undefined) table = {};
|
if (table == undefined) table = {};
|
||||||
table = Object.assign(table);
|
table = Object.assign({}, table);
|
||||||
Object.keys(table).forEach(function (key) {
|
Object.keys(table).forEach(function (key) {
|
||||||
const al = key.toLowerCase();
|
const al = key.toLowerCase();
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -87,9 +87,9 @@ if (!process.singleThreaded) {
|
||||||
cluster.workers = {};
|
cluster.workers = {};
|
||||||
cluster.fork = function (env) {
|
cluster.fork = function (env) {
|
||||||
const child_process = require("child_process");
|
const child_process = require("child_process");
|
||||||
let newEnvironment = Object.assign(env ? env : process.env);
|
let newEnvironment = Object.assign({}, env ? env : process.env);
|
||||||
newEnvironment.NODE_UNIQUE_ID = cluster._workersCounter;
|
newEnvironment.NODE_UNIQUE_ID = cluster._workersCounter;
|
||||||
let newArguments = Object.assign(process.argv);
|
let newArguments = Object.assign({}, process.argv);
|
||||||
let command = newArguments.shift();
|
let command = newArguments.shift();
|
||||||
let newWorker = child_process.spawn(command, newArguments, {
|
let newWorker = child_process.spawn(command, newArguments, {
|
||||||
env: newEnvironment,
|
env: newEnvironment,
|
||||||
|
|
Reference in a new issue