Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Add support for custom request headers #34

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions allowedRequestHeaders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"Accept",
"Content-Type"
]
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var http = require('http'),
faviconPNG = fsRead('favicon.png')
faviconPNGGZip = gzip(faviconPNG)
port = process.env.PORT || 8080,
allowedOriginalHeaders = new RegExp('^' + require('./allowedOriginalHeaders.json').join('|'), 'i')
allowedOriginalHeaders = new RegExp('^' + require('./allowedOriginalHeaders.json').join('|'), 'i'),
allowedRequestHeaders = require('./allowedRequestHeaders.json'),
bannedUrls = new RegExp(require('./bannedUrls.json').join('|'), 'i'),
defaultOptions = {
gzip:true
Expand Down Expand Up @@ -78,6 +79,14 @@ var http = require('http'),
break;
}
}

var toLower = function (str) {
return str.toLowerCase();
}
//add headers from original request
for ( var header of allowedRequestHeaders.map(toLower)) {
opts.headers[header] = req.headers[header]
}
return opts
},
handler = function handler(req, res) {
Expand Down Expand Up @@ -110,7 +119,7 @@ var http = require('http'),
r.pipefilter = function(response, dest) {
for (var header in response.headers) {
if (!allowedOriginalHeaders.test(header)) {
dest.removeHeader(header);
dest.removeHeader(header);
}
if (options.flags.gzip === true && header === 'content-encoding') dest.setHeader('content-encoding', response.headers[header])
}
Expand Down