Skip to content

Commit 7b25e2b

Browse files
committed
Add preserveHeaderKeyCase Option
1 parent e791604 commit 7b25e2b

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ proxyServer.listen(8015);
333333
* **ignorePath**: true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request (note: you will have to append / manually if required).
334334
* **localAddress**: Local interface string to bind for outgoing connections
335335
* **changeOrigin**: true/false, Default: false - changes the origin of the host header to the target URL
336+
* **preserveHeaderKeyCase**: true/false, Default: false - specify whether you want to keep letter case of response header key
336337
* **auth**: Basic authentication i.e. 'user:password' to compute an Authorization header.
337338
* **hostRewrite**: rewrites the location hostname on (201/301/302/307/308) redirects.
338339
* **autoRewrite**: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.

lib/http-proxy.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function createProxyServer(options) {
3535
* ignorePath: <true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request>
3636
* localAddress : <Local interface string to bind for outgoing connections>
3737
* changeOrigin: <true/false, Default: false - changes the origin of the host header to the target URL>
38+
* preserveHeaderKeyCase: <true/false, Default: false - specify whether you want to keep letter case of response header key >
3839
* auth : Basic authentication i.e. 'user:password' to compute an Authorization header.
3940
* hostRewrite: rewrites the location hostname on (301/302/307/308) redirects, Default: null.
4041
* autoRewrite: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false.

lib/http-proxy/passes/web-outgoing.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ module.exports = { // <--
8484
*/
8585
writeHeaders: function writeHeaders(req, res, proxyRes, options) {
8686
var rewriteCookieDomainConfig = options.cookieDomainRewrite,
87-
rawHeaderKeyMap = {},
87+
preserveHeaderKeyCase = options.preserveHeaderKeyCase,
88+
rawHeaderKeyMap,
8889
setHeader = function(key, header) {
8990
if (header == undefined) return;
9091
if (rewriteCookieDomainConfig && key.toLowerCase() === 'set-cookie') {
@@ -99,7 +100,8 @@ module.exports = { // <--
99100

100101
// message.rawHeaders is added in: v0.11.6
101102
// https://nodejs.org/api/http.html#http_message_rawheaders
102-
if (proxyRes.rawHeaders != undefined) {
103+
if (preserveHeaderKeyCase && proxyRes.rawHeaders != undefined) {
104+
rawHeaderKeyMap = {};
103105
for (var i = 0; i < proxyRes.rawHeaders.length; i += 2) {
104106
var key = proxyRes.rawHeaders[i];
105107
rawHeaderKeyMap[key.toLowerCase()] = key;

test/lib-http-proxy-test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ describe('lib/http-proxy.js', function() {
130130
it('should make the request, handle response and finish it', function(done) {
131131
var ports = { source: gen.port, proxy: gen.port };
132132
var proxy = httpProxy.createProxyServer({
133-
target: 'http://127.0.0.1:' + ports.source
133+
target: 'http://127.0.0.1:' + ports.source,
134+
preserveHeaderKeyCase: true
134135
}).listen(ports.proxy);
135136

136137
var source = http.createServer(function(req, res) {

0 commit comments

Comments
 (0)