Skip to content
Snippets Groups Projects
Commit 66266cd3 authored by Zachary Carter's avatar Zachary Carter
Browse files

Refactor forwarding of response headers - issue #1657

parent 4cc2476b
No related branches found
No related tags found
No related merge requests found
......@@ -45,31 +45,15 @@ exports.forward = function(dest, req, res, cb) {
}, function(pres) {
res.statusCode = pres.statusCode;
// forward along Content-Type and Content-Length, if available
if (pres.headers.hasOwnProperty('content-type')) {
res.setHeader('Content-Type', pres.headers['content-type']);
}
if (pres.headers.hasOwnProperty('content-length')) {
res.setHeader('Content-Length', pres.headers['content-length']);
}
if (pres.headers.hasOwnProperty('set-cookie')) {
res.setHeader('Set-Cookie', pres.headers['set-cookie']);
}
if (pres.headers.hasOwnProperty('vary')) {
res.setHeader('Vary', pres.headers['vary']);
}
if (pres.headers.hasOwnProperty('cache-control')) {
res.setHeader('Cache-Control', pres.headers['cache-control']);
}
if (pres.headers.hasOwnProperty('etag')) {
res.setHeader('ETag', pres.headers['etag']);
}
if (pres.headers.hasOwnProperty('x-frame-options')) {
res.setHeader('X-Frame-Options', pres.headers['x-frame-options']);
}
if (pres.headers.hasOwnProperty('location')) {
res.setHeader('Location', pres.headers['location']);
}
// forward necessary headers
['Content-Type', 'Content-Length', 'Set-Cookie', 'Vary', 'Cache-Control', 'ETag', 'X-Frame-Options', 'Location']
.forEach(function (header) {
if (pres.headers.hasOwnProperty(header.toLowerCase())) {
res.setHeader(header, pres.headers[header.toLowerCase()]);
}
});
pres.on('data', function (chunk) {
res.write(chunk);
}).on('end', function() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment