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
91e9bb90
Commit
91e9bb90
authored
Oct 15, 2011
by
Max Ogden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding tests for url segment proxytable routing
parent
4d509153
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
17 deletions
+24
-17
lib/node-http-proxy/proxy-table.js
lib/node-http-proxy/proxy-table.js
+9
-8
test/helpers.js
test/helpers.js
+6
-4
test/http/http-proxy-test.js
test/http/http-proxy-test.js
+4
-4
test/http/routing-proxy-test.js
test/http/routing-proxy-test.js
+5
-1
No files found.
lib/node-http-proxy/proxy-table.js
View file @
91e9bb90
...
@@ -135,16 +135,17 @@ ProxyTable.prototype.getProxyLocation = function (req) {
...
@@ -135,16 +135,17 @@ ProxyTable.prototype.getProxyLocation = function (req) {
else
{
else
{
target
+=
req
.
url
;
target
+=
req
.
url
;
for
(
var
i
in
this
.
routes
)
{
for
(
var
i
in
this
.
routes
)
{
var
route
=
this
.
routes
[
i
],
var
route
=
this
.
routes
[
i
];
match
;
if
(
target
.
match
(
route
.
route
))
{
if
(
match
=
target
.
match
(
route
.
route
))
{
var
root
=
"
/
"
+
route
.
path
.
split
(
'
/
'
)[
1
];
var
segments
=
route
.
path
.
split
(
'
/
'
);
var
beginningSegment
=
new
RegExp
(
"
^
"
+
root
);
if
(
req
.
url
.
match
(
beginningSegment
))
{
if
(
segments
.
length
>
0
)
{
req
.
url
=
req
.
url
.
replace
(
beginningSegment
,
''
);
var
lastSegment
=
new
RegExp
(
"
/
"
+
segments
[
segments
.
length
-
1
]
+
"
$
"
);
if
(
req
.
url
.
match
(
lastSegment
))
{
req
.
url
=
req
.
url
.
replace
(
lastSegment
,
'
/
'
);
}
}
}
var
location
=
route
.
target
.
split
(
'
:
'
),
var
location
=
route
.
target
.
split
(
'
:
'
),
...
...
test/helpers.js
View file @
91e9bb90
...
@@ -55,10 +55,12 @@ var TestRunner = exports.TestRunner = function (options) {
...
@@ -55,10 +55,12 @@ var TestRunner = exports.TestRunner = function (options) {
}
}
};
};
TestRunner
.
prototype
.
assertProxied
=
function
(
host
,
proxyPort
,
port
,
createProxy
)
{
TestRunner
.
prototype
.
assertProxied
=
function
(
host
,
proxyPort
,
port
,
requestPath
,
targetPath
,
createProxy
)
{
if
(
!
targetPath
)
targetPath
=
""
;
var
self
=
this
,
var
self
=
this
,
assertion
=
"
should receive 'hello
"
+
host
+
"
'
"
,
output
=
"
hello
"
+
host
+
targetPath
,
output
=
'
hello
'
+
host
;
assertion
=
"
should receive '
"
+
output
+
"
'
"
;
var
test
=
{
var
test
=
{
topic
:
function
()
{
topic
:
function
()
{
...
@@ -73,6 +75,7 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx
...
@@ -73,6 +75,7 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx
}
}
};
};
if
(
requestPath
)
options
.
uri
+=
requestPath
;
function
startTest
()
{
function
startTest
()
{
if
(
port
)
{
if
(
port
)
{
...
@@ -80,7 +83,6 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx
...
@@ -80,7 +83,6 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx
request
(
options
,
that
.
callback
);
request
(
options
,
that
.
callback
);
});
});
}
}
request
(
options
,
this
.
callback
);
request
(
options
,
this
.
callback
);
}
}
...
...
test/http/http-proxy-test.js
View file @
91e9bb90
...
@@ -51,7 +51,7 @@ var options = helpers.parseProtocol(),
...
@@ -51,7 +51,7 @@ var options = helpers.parseProtocol(),
vows
.
describe
(
'
node-http-proxy/http-proxy/
'
+
testName
).
addBatch
({
vows
.
describe
(
'
node-http-proxy/http-proxy/
'
+
testName
).
addBatch
({
"
When using server created by httpProxy.createServer()
"
:
{
"
When using server created by httpProxy.createServer()
"
:
{
"
with no latency
"
:
{
"
with no latency
"
:
{
"
and a valid target server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8080
,
8081
,
function
(
callback
)
{
"
and a valid target server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8080
,
8081
,
f
alse
,
false
,
f
unction
(
callback
)
{
runner
.
startProxyServer
(
8080
,
8081
,
'
localhost
'
,
callback
);
runner
.
startProxyServer
(
8080
,
8081
,
'
localhost
'
,
callback
);
}),
}),
"
and without a valid target server
"
:
runner
.
assertResponseCode
(
8082
,
500
,
function
(
callback
)
{
"
and without a valid target server
"
:
runner
.
assertResponseCode
(
8082
,
500
,
function
(
callback
)
{
...
@@ -59,7 +59,7 @@ vows.describe('node-http-proxy/http-proxy/' + testName).addBatch({
...
@@ -59,7 +59,7 @@ vows.describe('node-http-proxy/http-proxy/' + testName).addBatch({
})
})
},
},
"
with latency
"
:
{
"
with latency
"
:
{
"
and a valid target server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8083
,
8084
,
function
(
callback
)
{
"
and a valid target server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8083
,
8084
,
f
alse
,
false
,
f
unction
(
callback
)
{
runner
.
startLatentProxyServer
(
8083
,
8084
,
'
localhost
'
,
1000
,
callback
);
runner
.
startLatentProxyServer
(
8083
,
8084
,
'
localhost
'
,
1000
,
callback
);
}),
}),
"
and without a valid target server
"
:
runner
.
assertResponseCode
(
8085
,
500
,
function
(
callback
)
{
"
and without a valid target server
"
:
runner
.
assertResponseCode
(
8085
,
500
,
function
(
callback
)
{
...
@@ -71,13 +71,13 @@ vows.describe('node-http-proxy/http-proxy/' + testName).addBatch({
...
@@ -71,13 +71,13 @@ vows.describe('node-http-proxy/http-proxy/' + testName).addBatch({
runner
.
startTargetServer
(
8300
,
'
forward proxy
'
,
this
.
callback
);
runner
.
startTargetServer
(
8300
,
'
forward proxy
'
,
this
.
callback
);
},
},
"
with no latency
"
:
{
"
with no latency
"
:
{
"
and a valid target server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8120
,
8121
,
function
(
callback
)
{
"
and a valid target server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8120
,
8121
,
f
alse
,
false
,
f
unction
(
callback
)
{
runner
.
startProxyServerWithForwarding
(
8120
,
8121
,
'
localhost
'
,
forwardOptions
,
callback
);
runner
.
startProxyServerWithForwarding
(
8120
,
8121
,
'
localhost
'
,
forwardOptions
,
callback
);
}),
}),
"
and also a valid target server
"
:
runner
.
assertHeaders
(
8122
,
"
x-forwarded-for
"
,
function
(
callback
)
{
"
and also a valid target server
"
:
runner
.
assertHeaders
(
8122
,
"
x-forwarded-for
"
,
function
(
callback
)
{
runner
.
startProxyServerWithForwarding
(
8122
,
8123
,
'
localhost
'
,
forwardOptions
,
callback
);
runner
.
startProxyServerWithForwarding
(
8122
,
8123
,
'
localhost
'
,
forwardOptions
,
callback
);
}),
}),
"
and without a valid forward server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8124
,
8125
,
function
(
callback
)
{
"
and without a valid forward server
"
:
runner
.
assertProxied
(
'
localhost
'
,
8124
,
8125
,
f
alse
,
false
,
f
unction
(
callback
)
{
runner
.
startProxyServerWithForwarding
(
8124
,
8125
,
'
localhost
'
,
badForwardOptions
,
callback
);
runner
.
startProxyServerWithForwarding
(
8124
,
8125
,
'
localhost
'
,
badForwardOptions
,
callback
);
})
})
}
}
...
...
test/http/routing-proxy-test.js
View file @
91e9bb90
...
@@ -29,7 +29,9 @@ var fileOptions = {
...
@@ -29,7 +29,9 @@ var fileOptions = {
var
defaultOptions
=
{
var
defaultOptions
=
{
router
:
{
router
:
{
"
foo.com
"
:
"
127.0.0.1:8091
"
,
"
foo.com
"
:
"
127.0.0.1:8091
"
,
"
bar.com
"
:
"
127.0.0.1:8092
"
"
bar.com
"
:
"
127.0.0.1:8092
"
,
"
baz.com/taco
"
:
"
127.0.0.1:8098
"
,
"
pizza.com/taco/muffins
"
:
"
127.0.0.1:8099
"
,
}
}
};
};
...
@@ -50,6 +52,8 @@ vows.describe('node-http-proxy/routing-proxy/' + testName).addBatch({
...
@@ -50,6 +52,8 @@ vows.describe('node-http-proxy/routing-proxy/' + testName).addBatch({
},
},
"
an incoming request to foo.com
"
:
runner
.
assertProxied
(
'
foo.com
'
,
8090
,
8091
),
"
an incoming request to foo.com
"
:
runner
.
assertProxied
(
'
foo.com
'
,
8090
,
8091
),
"
an incoming request to bar.com
"
:
runner
.
assertProxied
(
'
bar.com
'
,
8090
,
8092
),
"
an incoming request to bar.com
"
:
runner
.
assertProxied
(
'
bar.com
'
,
8090
,
8092
),
"
an incoming request to baz.com/taco
"
:
runner
.
assertProxied
(
'
baz.com
'
,
8090
,
8098
,
"
/taco
"
,
"
/
"
),
"
an incoming request to pizza.com/taco/muffins
"
:
runner
.
assertProxied
(
'
pizza.com
'
,
8090
,
8099
,
"
/taco/muffins
"
,
"
/taco
"
),
"
an incoming request to unknown.com
"
:
runner
.
assertResponseCode
(
8090
,
404
)
"
an incoming request to unknown.com
"
:
runner
.
assertResponseCode
(
8090
,
404
)
},
},
"
and routing by Hostname
"
:
{
"
and routing by Hostname
"
:
{
...
...
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