Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-http-proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
node-http-proxy
Commits
3af0238a
Commit
3af0238a
authored
Nov 28, 2011
by
Samyak Bhuta
Committed by
Cédric de Saint Martin
Jan 03, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allowing the common proxy headers' value to be appended in proxy chain scenarios.
parent
b1464068
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
9 deletions
+49
-9
lib/node-http-proxy/http-proxy.js
lib/node-http-proxy/http-proxy.js
+49
-9
No files found.
lib/node-http-proxy/http-proxy.js
View file @
3af0238a
...
...
@@ -122,17 +122,36 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
//
// Add common proxy headers to the request so that they can
// be availible to the proxy target server:
// be availible to the proxy target server. If the proxy is
// part of proxy chain it will append the address:
//
// * `x-forwarded-for`: IP Address of the original request
// * `x-forwarded-proto`: Protocol of the original request
// * `x-forwarded-port`: Port of the original request.
//
if
(
this
.
enable
.
xforward
&&
req
.
connection
&&
req
.
socket
)
{
req
.
headers
[
'
x-forwarded-for
'
]
=
req
.
connection
.
remoteAddress
||
req
.
socket
.
remoteAddress
;
req
.
headers
[
'
x-forwarded-port
'
]
=
req
.
connection
.
remotePort
||
req
.
socket
.
remotePort
;
req
.
headers
[
'
x-forwarded-proto
'
]
=
req
.
connection
.
pair
?
'
https
'
:
'
http
'
;
if
(
req
.
headers
[
'
x-forwarded-for
'
]){
var
addressToAppend
=
"
,
"
+
req
.
connection
.
remoteAddress
||
req
.
socket
.
remoteAddress
;
req
.
headers
[
'
x-forwarded-for
'
]
+=
addressToAppend
;
}
else
{
req
.
headers
[
'
x-forwarded-for
'
]
=
req
.
connection
.
remoteAddress
||
req
.
socket
.
remoteAddress
;
}
if
(
req
.
headers
[
'
x-forwarded-port
'
]){
var
portToAppend
=
"
,
"
+
req
.
connection
.
remotePort
||
req
.
socket
.
remotePort
;
req
.
headers
[
'
x-forwarded-port
'
]
+=
portToAppend
;
}
else
{
req
.
headers
[
'
x-forwarded-port
'
]
=
req
.
connection
.
remotePort
||
req
.
socket
.
remotePort
;
}
if
(
req
.
headers
[
'
x-forwarded-proto
'
]){
var
protoToAppend
=
"
,
"
+
req
.
connection
.
pair
?
'
https
'
:
'
http
'
;
req
.
headers
[
'
x-forwarded-proto
'
]
+=
protoToAppend
;
}
else
{
req
.
headers
[
'
x-forwarded-proto
'
]
=
req
.
connection
.
pair
?
'
https
'
:
'
http
'
;
}
}
//
...
...
@@ -299,6 +318,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
// `req` write it to the `reverseProxy` request.
//
req
.
on
(
'
data
'
,
function
(
chunk
)
{
if
(
!
errState
)
{
var
flushed
=
reverseProxy
.
write
(
chunk
);
if
(
!
flushed
)
{
...
...
@@ -375,16 +395,36 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
//
// Add common proxy headers to the request so that they can
// be availible to the proxy target server:
// be availible to the proxy target server. If the proxy is
// part of proxy chain it will append the address:
//
// * `x-forwarded-for`: IP Address of the original request
// * `x-forwarded-proto`: Protocol of the original request
// * `x-forwarded-port`: Port of the original request.
//
if
(
this
.
enable
.
xforward
&&
req
.
connection
&&
req
.
connection
.
socket
)
{
req
.
headers
[
'
x-forwarded-for
'
]
=
req
.
connection
.
remoteAddress
||
req
.
connection
.
socket
.
remoteAddress
;
req
.
headers
[
'
x-forwarded-port
'
]
=
req
.
connection
.
remotePort
||
req
.
connection
.
socket
.
remotePort
;
req
.
headers
[
'
x-forwarded-proto
'
]
=
req
.
connection
.
pair
?
'
https
'
:
'
http
'
;
if
(
req
.
headers
[
'
x-forwarded-for
'
]){
var
addressToAppend
=
"
,
"
+
req
.
connection
.
remoteAddress
||
req
.
connection
.
socket
.
remoteAddress
;
req
.
headers
[
'
x-forwarded-for
'
]
+=
addressToAppend
;
}
else
{
req
.
headers
[
'
x-forwarded-for
'
]
=
req
.
connection
.
remoteAddress
||
req
.
connection
.
socket
.
remoteAddress
;
}
if
(
req
.
headers
[
'
x-forwarded-port
'
]){
var
portToAppend
=
"
,
"
+
req
.
connection
.
remotePort
||
req
.
connection
.
socket
.
remotePort
;
req
.
headers
[
'
x-forwarded-port
'
]
+=
portToAppend
;
}
else
{
req
.
headers
[
'
x-forwarded-port
'
]
=
req
.
connection
.
remotePort
||
req
.
connection
.
socket
.
remotePort
;
}
if
(
req
.
headers
[
'
x-forwarded-proto
'
]){
var
protoToAppend
=
"
,
"
+
req
.
connection
.
pair
?
'
https
'
:
'
http
'
;
req
.
headers
[
'
x-forwarded-proto
'
]
+=
protoToAppend
;
}
else
{
req
.
headers
[
'
x-forwarded-proto
'
]
=
req
.
connection
.
pair
?
'
https
'
:
'
http
'
;
}
}
//
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment