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
c773eede
Commit
c773eede
authored
Jul 24, 2011
by
Dominic Tarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[minor] add middleware to node-http-proxy
parent
25c06a3a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
33 deletions
+56
-33
lib/node-http-proxy.js
lib/node-http-proxy.js
+56
-33
No files found.
lib/node-http-proxy.js
View file @
c773eede
...
@@ -112,6 +112,30 @@ exports.getMaxSockets = function () {
...
@@ -112,6 +112,30 @@ exports.getMaxSockets = function () {
exports
.
setMaxSockets
=
function
(
value
)
{
exports
.
setMaxSockets
=
function
(
value
)
{
maxSockets
=
value
;
maxSockets
=
value
;
};
};
//
// stack
// adapted from https://github.com/creationix/stack
//
function
stack
(
middlewares
,
proxy
)
{
var
handle
;
middlewares
.
reverse
().
forEach
(
function
(
layer
)
{
var
child
=
handle
;
var
next
=
function
(
err
)
{
if
(
err
)
{
throw
err
;
//return error(req, res, err);
}
child
(
req
,
res
);
}
next
.
__proto__
=
proxy
;
handle
=
function
(
req
,
res
)
{
layer
(
req
,
res
,
next
);
};
});
return
handle
;
}
//
//
// ### function createServer ([port, host, options, handler])
// ### function createServer ([port, host, options, handler])
...
@@ -127,60 +151,59 @@ exports.setMaxSockets = function (value) {
...
@@ -127,60 +151,59 @@ exports.setMaxSockets = function (value) {
//
//
exports
.
createServer
=
function
()
{
exports
.
createServer
=
function
()
{
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
),
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
),
callback
=
typeof
args
[
0
]
===
'
function
'
&&
args
.
shift
()
,
callback
,
options
=
{},
port
,
host
,
forward
,
silent
,
proxy
,
server
,
handler
;
options
=
{},
port
,
host
,
forward
,
silent
,
proxy
,
server
,
middleware
=
[]
;
if
(
args
.
length
>=
2
)
{
args
.
forEach
(
function
(
arg
)
{
port
=
args
[
0
];
host
=
args
[
1
];
options
=
args
[
2
]
||
{};
}
else
if
(
args
.
length
===
1
)
{
options
=
args
[
0
]
||
{};
if
(
!
options
.
router
&&
!
callback
)
{
throw
new
Error
(
'
Cannot create server with no router and no callback
'
);
}
}
proxy
=
new
HttpProxy
(
options
);
handler
=
function
(
req
,
res
)
{
switch
(
typeof
arg
)
{
if
(
callback
)
{
case
'
string
'
:
host
=
arg
;
break
;
//
case
'
number
'
:
port
=
arg
;
break
;
// If we were passed a callback to process the request
case
'
function
'
:
middleware
.
push
(
arg
);
break
;
// or response in some way, then call it.
case
'
object
'
:
options
=
arg
;
break
;
//
};
callback
(
req
,
res
,
proxy
);
}
});
else
if
(
port
&&
host
)
{
var
proxy
=
new
HttpProxy
(
options
);
if
(
middleware
.
length
)
//handler = callback = middleware.shift()
//else if (middleware.length)
handler
=
callback
=
stack
(
middleware
,
proxy
);
if
(
port
&&
host
)
{
//
//
// If we have a target host and port for the request
// If we have a target host and port for the request
// then proxy to the specified location.
// then proxy to the specified location.
//
//
proxy
.
proxyRequest
(
req
,
res
,
{
handler
=
function
(
req
,
res
)
{
port
:
port
,
proxy
.
proxyRequest
(
req
,
res
,
{
host
:
host
port
:
port
,
});
host
:
host
});
}
}
}
else
if
(
proxy
.
proxyTable
)
{
else
if
(
proxy
.
proxyTable
)
{
//
//
// If the proxy is configured with a ProxyTable
// If the proxy is configured with a ProxyTable
// instance then use that before failing.
// instance then use that before failing.
//
//
proxy
.
proxyRequest
(
req
,
res
);
handler
=
function
(
req
,
res
)
{
proxy
.
proxyRequest
(
req
,
res
);
}
}
}
else
{
else
if
(
!
handler
)
{
//
//
// Otherwise this server is improperly configured.
// Otherwise this server is improperly configured.
//
//
throw
new
Error
(
'
Cannot proxy without port, host, or router.
'
)
throw
new
Error
(
'
Cannot proxy without port, host, or router.
'
)
}
}
};
server
=
options
.
https
server
=
options
.
https
?
https
.
createServer
(
options
.
https
,
handler
)
?
https
.
createServer
(
options
.
https
,
handler
)
:
http
.
createServer
(
handler
);
:
http
.
createServer
(
handler
);
server
.
on
(
'
close
'
,
function
()
{
server
.
on
(
'
close
'
,
function
()
{
proxy
.
close
();
proxy
.
close
();
});
});
...
...
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