diff --git a/lib/http_forward.js b/lib/http_forward.js index f04001e1d6282c7ef88de5030f3ac36824657223..5fbf3fe7bdd47aece8152575fc7671215ff13bc9 100644 --- a/lib/http_forward.js +++ b/lib/http_forward.js @@ -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() {