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
66e98206
Commit
66e98206
authored
Sep 20, 2011
by
Joshua Holbrook
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Added a test for the "x-forwarded-for" header
parent
2677bb6c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
3 deletions
+40
-3
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.
test/helpers.js
View file @
66e98206
...
...
@@ -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
//
...
...
@@ -368,4 +402,4 @@ function merge (target) {
});
});
return
target
;
}
\ No newline at end of file
}
test/http/http-proxy-test.js
View file @
66e98206
...
...
@@ -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