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
9faa924a
Commit
9faa924a
authored
Feb 21, 2011
by
indexzero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[api] First pass at removing pool and working with node v0.4.0
parent
34cba38c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
119 deletions
+102
-119
.gitignore
.gitignore
+1
-0
lib/node-http-proxy.js
lib/node-http-proxy.js
+95
-109
test/forward-proxy-test.js
test/forward-proxy-test.js
+2
-3
test/helpers.js
test/helpers.js
+2
-4
test/node-http-proxy-test.js
test/node-http-proxy-test.js
+2
-3
No files found.
.gitignore
0 → 100644
View file @
9faa924a
test/config.json
\ No newline at end of file
lib/node-http-proxy.js
View file @
9faa924a
...
...
@@ -27,15 +27,8 @@
var
util
=
require
(
'
util
'
),
http
=
require
(
'
http
'
),
events
=
require
(
'
events
'
),
pool
=
require
(
'
pool
'
),
ProxyTable
=
require
(
'
./proxy-table
'
).
ProxyTable
,
min
=
0
,
max
=
100
;
// Setup the PoolManager
var
manager
=
pool
.
createPoolManager
();
manager
.
setMinClients
(
min
);
manager
.
setMaxClients
(
max
);
maxSockets
=
100
;
exports
.
createServer
=
function
()
{
var
args
,
callback
,
port
,
host
,
forward
,
...
...
@@ -114,17 +107,13 @@ exports.createServer = function () {
return
server
;
};
exports
.
setMin
=
function
(
value
)
{
min
=
value
;
manager
.
setMinClients
(
min
);
exports
.
setMaxSockets
=
function
(
value
)
{
maxSockets
=
value
;
};
exports
.
setMax
=
function
(
value
)
{
max
=
value
;
manager
.
setMaxClients
(
max
);
};
exports
.
ProxyTable
=
ProxyTable
;
var
HttpProxy
=
function
(
req
,
res
,
head
)
{
var
HttpProxy
=
exports
.
HttpProxy
=
function
(
req
,
res
,
head
)
{
this
.
events
=
{};
this
.
req
=
req
;
...
...
@@ -177,18 +166,8 @@ HttpProxy.prototype = {
},
proxyRequest
:
function
(
port
,
server
)
{
var
self
=
this
,
req
=
this
.
req
,
res
=
this
.
res
;
// Open new HTTP request to internal resource with will act as a reverse proxy pass
var
p
=
manager
.
getPool
(
port
,
server
);
p
.
on
(
'
error
'
,
function
(
err
)
{
// Remark: We should probably do something here
// but this is a hot-fix because I don't think 'pool'
// should be emitting this event.
});
var
self
=
this
,
req
=
this
.
req
,
res
=
this
.
res
,
reverseProxy
;
p
.
request
(
req
.
method
,
req
.
url
,
req
.
headers
,
function
(
reverse_proxy
)
{
// Create an error handler so we can use it temporarily
function
error
(
obj
)
{
var
fn
=
function
(
err
)
{
...
...
@@ -206,12 +185,16 @@ HttpProxy.prototype = {
return
fn
;
};
// Add a listener for the connection timeout event
var
reverseProxyError
=
error
(
reverse_proxy
);
reverse_proxy
.
addListener
(
'
error
'
,
reverseProxyError
);
// Add a listener for the reverse_proxy response event
reverse_proxy
.
addListener
(
'
response
'
,
function
(
response
)
{
// Open new HTTP request to internal resource with will act as a reverse proxy pass
reverseProxy
=
http
.
request
({
host
:
server
,
port
:
port
,
method
:
req
.
method
,
path
:
req
.
url
,
headers
:
req
.
headers
},
function
(
response
)
{
// Process the reverse_proxy response when it's received.
if
(
response
.
headers
.
connection
)
{
if
(
req
.
headers
.
connection
)
response
.
headers
.
connection
=
req
.
headers
.
connection
;
else
response
.
headers
.
connection
=
'
close
'
;
...
...
@@ -237,56 +220,62 @@ HttpProxy.prototype = {
// Add event listener for end of proxied response
response
.
addListener
(
'
end
'
,
function
()
{
reverse_p
roxy
.
removeListener
(
'
error
'
,
reverseProxyError
);
reverseP
roxy
.
removeListener
(
'
error
'
,
reverseProxyError
);
res
.
end
();
});
});
// Add a listener for the connection timeout event
var
reverseProxyError
=
error
(
reverseProxy
);
reverseProxy
.
addListener
(
'
error
'
,
reverseProxyError
);
// Chunk the client request body as chunks from the proxied request come in
req
.
addListener
(
'
data
'
,
function
(
chunk
)
{
reverse_p
roxy
.
write
(
chunk
,
'
binary
'
);
reverseP
roxy
.
write
(
chunk
,
'
binary
'
);
})
// At the end of the client request, we are going to stop the proxied request
req
.
addListener
(
'
end
'
,
function
()
{
reverse_p
roxy
.
end
();
reverseP
roxy
.
end
();
});
self
.
unwatch
(
req
);
});
},
forwardRequest
:
function
(
port
,
server
)
{
var
self
=
this
,
req
=
this
.
req
;
var
self
=
this
,
req
=
this
.
req
,
forwardProxy
;
// Open new HTTP request to internal resource with will act as a reverse proxy pass
var
p
=
manager
.
getPool
(
port
,
server
);
p
.
on
(
'
error
'
,
function
(
err
)
{
// Remark: We should probably do something here
// but this is a hot-fix because I don't think 'pool'
// should be emitting this event.
forwardProxy
=
http
.
request
({
host
:
server
,
port
:
port
,
method
:
req
.
method
,
path
:
req
.
url
,
headers
:
req
.
headers
},
function
(
response
)
{
//
// Ignore the response from the forward proxy since this is a 'fire-and-forget' proxy.
// Remark (indexzero): We will eventually emit a 'forward' event here for performance tuning.
//
});
p
.
request
(
req
.
method
,
req
.
url
,
req
.
headers
,
function
(
forward_proxy
)
{
// Add a listener for the connection timeout event
forward_p
roxy
.
addListener
(
'
error
'
,
function
(
err
)
{
forwardP
roxy
.
addListener
(
'
error
'
,
function
(
err
)
{
// Remark: Ignoring this error in the event
// forward target doesn't exist.
});
// Chunk the client request body as chunks from the proxied request come in
req
.
addListener
(
'
data
'
,
function
(
chunk
)
{
forward_p
roxy
.
write
(
chunk
,
'
binary
'
);
forwardP
roxy
.
write
(
chunk
,
'
binary
'
);
})
// At the end of the client request, we are going to stop the proxied request
req
.
addListener
(
'
end
'
,
function
()
{
forward_p
roxy
.
end
();
forwardP
roxy
.
end
();
});
self
.
unwatch
(
req
);
});
},
proxyWebSocketRequest
:
function
(
port
,
server
,
host
)
{
...
...
@@ -478,6 +467,3 @@ HttpProxy.prototype = {
};
}
};
\ No newline at end of file
exports
.
HttpProxy
=
HttpProxy
;
exports
.
ProxyTable
=
ProxyTable
;
\ No newline at end of file
test/forward-proxy-test.js
View file @
9faa924a
...
...
@@ -11,10 +11,9 @@ var fs = require('fs'),
path
=
require
(
'
path
'
),
request
=
require
(
'
request
'
),
assert
=
require
(
'
assert
'
),
helpers
=
require
(
'
./helpers
'
),
TestRunner
=
helpers
.
TestRunner
;
helpers
=
require
(
'
./helpers
'
);
var
runner
=
new
TestRunner
(),
var
runner
=
new
helpers
.
TestRunner
(),
assertProxiedWithTarget
=
helpers
.
assertProxiedWithTarget
,
assertProxiedWithNoTarget
=
helpers
.
assertProxiedWithNoTarget
;
...
...
test/helpers.js
View file @
9faa924a
...
...
@@ -63,7 +63,7 @@ exports.assertProxiedWithNoTarget = function (runner, proxyPort, statusCode, cre
return
test
;
}
var
TestRunner
=
function
()
{
var
TestRunner
=
exports
.
TestRunner
=
function
()
{
this
.
testServers
=
[];
}
...
...
@@ -160,5 +160,3 @@ TestRunner.prototype.closeServers = function () {
return
this
.
testServers
;
};
\ No newline at end of file
exports
.
TestRunner
=
TestRunner
;
\ No newline at end of file
test/node-http-proxy-test.js
View file @
9faa924a
...
...
@@ -28,10 +28,9 @@ var vows = require('vows'),
util
=
require
(
'
util
'
),
request
=
require
(
'
request
'
),
assert
=
require
(
'
assert
'
),
helpers
=
require
(
'
./helpers
'
),
TestRunner
=
helpers
.
TestRunner
;
helpers
=
require
(
'
./helpers
'
);
var
runner
=
new
TestRunner
(),
var
runner
=
new
helpers
.
TestRunner
(),
assertProxiedWithTarget
=
helpers
.
assertProxiedWithTarget
,
assertProxiedWithNoTarget
=
helpers
.
assertProxiedWithNoTarget
;
...
...
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