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
73381cf7
Commit
73381cf7
authored
Sep 22, 2010
by
indexzero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[debug] Removed pool as a dependency for stress test
parent
266e5246
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
55 deletions
+60
-55
lib/node-http-proxy.js
lib/node-http-proxy.js
+60
-55
No files found.
lib/node-http-proxy.js
View file @
73381cf7
...
...
@@ -145,78 +145,83 @@ HttpProxy.prototype = {
self
.
body
=
''
;
// Open new HTTP request to internal resource with will act as a reverse proxy pass
var
p
=
manager
.
getPool
(
port
,
server
);
sys
.
puts
(
'
Current pool count for
'
+
req
.
headers
.
host
+
"
:
"
+
port
+
'
'
+
p
.
clients
.
length
+
'
, Busy:
'
+
p
.
getBusy
()
+
'
, Free:
'
+
p
.
getFree
());
//
var p = manager.getPool(port, server);
//
sys.puts('Current pool count for ' + req.headers.host + ":" + port + ' ' + p.clients.length + ', Busy: ' + p.getBusy() + ', Free: ' + p.getFree());
p
.
on
(
'
error
'
,
function
(
err
)
{
//
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
client
=
http
.
createClient
(
port
,
server
);
var
reverse_proxy
=
client
.
request
(
req
.
method
,
req
.
url
,
req
.
headers
);
p
.
request
(
req
.
method
,
req
.
url
,
req
.
headers
,
function
(
reverse_proxy
)
{
// Create an error handler so we can use it temporarily
var
error
=
function
(
err
)
{
res
.
writeHead
(
500
,
{
'
Content-Type
'
:
'
text/plain
'
});
//p.request(req.method, req.url, req.headers, function (reverse_proxy) {
if
(
req
.
method
!==
'
HEAD
'
)
{
res
.
write
(
'
An error has occurred:
'
+
JSON
.
stringify
(
err
));
}
// Response end may never come so removeListener here
reverse_proxy
.
removeListener
(
'
error
'
,
error
);
res
.
end
();
};
// Create an error handler so we can use it temporarily
var
error
=
function
(
err
)
{
res
.
writeHead
(
500
,
{
'
Content-Type
'
:
'
text/plain
'
});
// Add a listener for the connection timeout event
reverse_proxy
.
addListener
(
'
error
'
,
error
);
if
(
req
.
method
!==
'
HEAD
'
)
{
res
.
write
(
'
An error has occurred:
'
+
JSON
.
stringify
(
err
));
}
// Response end may never come so removeListener here
reverse_proxy
.
removeListener
(
'
error
'
,
error
);
res
.
end
();
};
// Add a listener for the reverse_proxy response event
reverse_proxy
.
addListener
(
'
response
'
,
function
(
response
)
{
if
(
response
.
headers
.
connection
)
{
if
(
req
.
headers
.
connection
)
response
.
headers
.
connection
=
req
.
headers
.
connection
;
else
response
.
headers
.
connection
=
'
close
'
;
}
// Add a listener for the connection timeout event
reverse_proxy
.
addListener
(
'
error
'
,
error
);
// Set the response headers of the client response
res
.
writeHead
(
response
.
statusCode
,
response
.
headers
);
// Add a listener for the reverse_proxy response event
reverse_proxy
.
addListener
(
'
response
'
,
function
(
response
)
{
if
(
response
.
headers
.
connection
)
{
if
(
req
.
headers
.
connection
)
response
.
headers
.
connection
=
req
.
headers
.
connection
;
else
response
.
headers
.
connection
=
'
close
'
;
}
// Status code = 304
// No 'data' event and no 'end'
if
(
response
.
statusCode
===
304
)
{
res
.
end
();
return
;
}
// Set the response headers of the client response
res
.
writeHead
(
response
.
statusCode
,
response
.
headers
);
// Add event handler for the proxied response in chunks
response
.
addListener
(
'
data
'
,
function
(
chunk
)
{
if
(
req
.
method
!==
'
HEAD
'
)
{
res
.
write
(
chunk
,
'
binary
'
);
self
.
body
+=
chunk
;
}
});
// Status code = 304
// No 'data' event and no 'end'
if
(
response
.
statusCode
===
304
)
{
res
.
end
();
return
;
}
// Add event listener for end of proxied response
response
.
addListener
(
'
end
'
,
function
()
{
// Remark: Emit the end event for testability
self
.
emitter
.
emit
(
'
proxy
'
,
null
,
self
.
body
);
reverse_proxy
.
removeListener
(
'
error
'
,
error
);
res
.
end
();
});
// Add event handler for the proxied response in chunks
response
.
addListener
(
'
data
'
,
function
(
chunk
)
{
if
(
req
.
method
!==
'
HEAD
'
)
{
res
.
write
(
chunk
,
'
binary
'
);
self
.
body
+=
chunk
;
}
});
// Chunk the client request body as chunks from the proxied request come in
req
.
addListener
(
'
data
'
,
function
(
chunk
)
{
reverse_proxy
.
write
(
chunk
,
'
binary
'
);
})
// At the end of the client request, we are going to stop the proxied request
req
.
addListener
(
'
end
'
,
function
()
{
reverse_proxy
.
end
();
// Add event listener for end of proxied response
response
.
addListener
(
'
end
'
,
function
()
{
// Remark: Emit the end event for testability
self
.
emitter
.
emit
(
'
proxy
'
,
null
,
self
.
body
);
reverse_proxy
.
removeListener
(
'
error
'
,
error
);
res
.
end
();
});
});
self
.
unwatch
(
req
);
// Chunk the client request body as chunks from the proxied request come in
req
.
addListener
(
'
data
'
,
function
(
chunk
)
{
reverse_proxy
.
write
(
chunk
,
'
binary
'
);
})
// At the end of the client request, we are going to stop the proxied request
req
.
addListener
(
'
end
'
,
function
()
{
reverse_proxy
.
end
();
});
self
.
unwatch
(
req
);
//});
},
proxyWebSocketRequest
:
function
(
port
,
server
,
host
)
{
...
...
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