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
e5693d2b
Commit
e5693d2b
authored
Sep 21, 2011
by
Charlie McConnell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #110 from nodejitsu/gh-107
#107: Set x-forwarded-for header (amongst others)
parents
787370ee
1f33943b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
7 deletions
+45
-7
lib/node-http-proxy/http-proxy.js
lib/node-http-proxy/http-proxy.js
+5
-4
test/helpers.js
test/helpers.js
+35
-1
test/http/http-proxy-test.js
test/http/http-proxy-test.js
+5
-2
No files found.
lib/node-http-proxy/http-proxy.js
View file @
e5693d2b
...
...
@@ -128,9 +128,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
// * `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
;
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
'
;
}
...
...
test/helpers.js
View file @
e5693d2b
...
...
@@ -128,6 +128,40 @@ TestRunner.prototype.assertResponseCode = function (proxyPort, statusCode, creat
return
test
;
};
// A test helper to check and see if the http headers were set properly.
TestRunner
.
prototype
.
assertHeaders
=
function
(
proxyPort
,
headerName
,
createProxy
)
{
var
assertion
=
"
should receive http header
\"
"
+
headerName
+
"
\"
"
,
protocol
=
this
.
source
.
protocols
.
http
;
var
test
=
{
topic
:
function
()
{
var
that
=
this
,
options
=
{
method
:
'
GET
'
,
uri
:
protocol
+
'
://localhost:
'
+
proxyPort
,
headers
:
{
host
:
'
unknown.com
'
}
};
if
(
createProxy
)
{
return
createProxy
(
function
()
{
request
(
options
,
that
.
callback
);
});
}
request
(
options
,
this
.
callback
);
}
};
test
[
assertion
]
=
function
(
err
,
res
,
body
)
{
assert
.
isNull
(
err
);
assert
.
isNotNull
(
res
.
headers
[
headerName
]);
};
return
test
;
};
//
// WebSocketTest
//
...
...
test/http/http-proxy-test.js
View file @
e5693d2b
...
...
@@ -74,8 +74,11 @@ vows.describe('node-http-proxy/http-proxy/' + testName).addBatch({
"
and a valid target server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8120
,
8121
,
function
(
callback
)
{
runner
.
startProxyServerWithForwarding
(
8120
,
8121
,
'
localhost
'
,
forwardOptions
,
callback
);
}),
"
and without a valid forward server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8122
,
8123
,
function
(
callback
)
{
runner
.
startProxyServerWithForwarding
(
8122
,
8123
,
'
localhost
'
,
badForwardOptions
,
callback
);
"
and also a valid target server
"
:
runner
.
assertHeaders
(
8122
,
"
x-forwarded-for
"
,
function
(
callback
)
{
runner
.
startProxyServerWithForwarding
(
8122
,
8123
,
'
localhost
'
,
forwardOptions
,
callback
);
}),
"
and without a valid forward server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8124
,
8125
,
function
(
callback
)
{
runner
.
startProxyServerWithForwarding
(
8124
,
8125
,
'
localhost
'
,
badForwardOptions
,
callback
);
})
}
}
...
...
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