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
3fd3c96f
Commit
3fd3c96f
authored
Mar 20, 2011
by
indexzero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[api] Force connection header to be `close` until keep-alive is replemented
parent
35886878
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
20 deletions
+22
-20
lib/node-http-proxy.js
lib/node-http-proxy.js
+22
-20
No files found.
lib/node-http-proxy.js
View file @
3fd3c96f
...
@@ -242,7 +242,7 @@ HttpProxy.prototype.close = function () {
...
@@ -242,7 +242,7 @@ HttpProxy.prototype.close = function () {
// #### @buffer {Object} **Optional** Result from `httpProxy.buffer(req)`
// #### @buffer {Object} **Optional** Result from `httpProxy.buffer(req)`
//
//
HttpProxy
.
prototype
.
proxyRequest
=
function
(
req
,
res
,
port
,
host
,
buffer
)
{
HttpProxy
.
prototype
.
proxyRequest
=
function
(
req
,
res
,
port
,
host
,
buffer
)
{
var
self
=
this
,
reverseProxy
,
location
,
errState
=
false
;
var
self
=
this
,
reverseProxy
,
location
,
errState
=
false
,
opts
;
//
//
// Check the proxy table for this instance to see if we need
// Check the proxy table for this instance to see if we need
...
@@ -301,15 +301,21 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
...
@@ -301,15 +301,21 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
res
.
end
();
res
.
end
();
}
}
// Open new HTTP request to internal resource with will act as a reverse proxy pass
var
opts
=
{
reverseProxy
=
http
.
request
({
host
:
host
,
host
:
host
,
port
:
port
,
port
:
port
,
agent
:
_getAgent
(
host
,
port
),
agent
:
_getAgent
(
host
,
port
),
method
:
req
.
method
,
method
:
req
.
method
,
path
:
req
.
url
,
path
:
req
.
url
,
headers
:
req
.
headers
headers
:
req
.
headers
},
function
(
response
)
{
};
// Force the `connection` header to be 'close' until
// node.js core re-implements 'keep-alive'.
opts
.
headers
[
'
connection
'
]
=
'
close
'
;
// Open new HTTP request to internal resource with will act as a reverse proxy pass
reverseProxy
=
http
.
request
(
opts
,
function
(
response
)
{
// Process the `reverseProxy` `response` when it's received.
// Process the `reverseProxy` `response` when it's received.
if
(
response
.
headers
.
connection
)
{
if
(
response
.
headers
.
connection
)
{
...
@@ -362,17 +368,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
...
@@ -362,17 +368,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
// request unless we have entered an error state.
// request unless we have entered an error state.
//
//
req
.
on
(
'
end
'
,
function
()
{
req
.
on
(
'
end
'
,
function
()
{
//
if
(
!
errState
)
{
// __Remark__ *(indexzero | 3/10/2011)*: This is a short-term workaround for a suspect error from net.js when
// `http.ClientRequest.end()` is called in reproducable, but uninvestigated scenarios
//
// net.js:313
// throw new Error('Socket.end() called already; cannot write.');
// ^
// Error: Socket.end() called already; cannot write.
// at Socket.write (net.js:313:13)
//
if
(
!
errState
&&
(
!
reverseProxy
.
socket
||
reverseProxy
.
socket
.
_writeQueueLast
()
!==
42
))
{
reverseProxy
.
end
();
reverseProxy
.
end
();
}
}
});
});
...
@@ -390,20 +386,26 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
...
@@ -390,20 +386,26 @@ HttpProxy.prototype.proxyRequest = function (req, res, port, host, buffer) {
// by `this.options.forward` ignoring errors and the subsequent response.
// by `this.options.forward` ignoring errors and the subsequent response.
//
//
HttpProxy
.
prototype
.
_forwardRequest
=
function
(
req
)
{
HttpProxy
.
prototype
.
_forwardRequest
=
function
(
req
)
{
var
self
=
this
,
port
,
host
,
forwardProxy
;
var
self
=
this
,
port
,
host
,
forwardProxy
,
opts
;
port
=
this
.
options
.
forward
.
port
;
port
=
this
.
options
.
forward
.
port
;
host
=
this
.
options
.
forward
.
host
;
host
=
this
.
options
.
forward
.
host
;
// Open new HTTP request to internal resource with will act as a reverse proxy pass
opts
=
{
forwardProxy
=
http
.
request
({
host
:
host
,
host
:
host
,
port
:
port
,
port
:
port
,
agent
:
_getAgent
(
host
,
port
),
agent
:
_getAgent
(
host
,
port
),
method
:
req
.
method
,
method
:
req
.
method
,
path
:
req
.
url
,
path
:
req
.
url
,
headers
:
req
.
headers
headers
:
req
.
headers
},
function
(
response
)
{
};
// Force the `connection` header to be 'close' until
// node.js core re-implements 'keep-alive'.
opts
.
headers
[
'
connection
'
]
=
'
close
'
;
// Open new HTTP request to internal resource with will act as a reverse proxy pass
forwardProxy
=
http
.
request
(
opts
,
function
(
response
)
{
//
//
// Ignore the response from the forward proxy since this is a 'fire-and-forget' proxy.
// 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.
// Remark (indexzero): We will eventually emit a 'forward' event here for performance tuning.
...
@@ -415,7 +417,7 @@ HttpProxy.prototype._forwardRequest = function (req) {
...
@@ -415,7 +417,7 @@ HttpProxy.prototype._forwardRequest = function (req) {
// Remark: Ignoring this error in the event
// Remark: Ignoring this error in the event
// forward target doesn't exist.
// forward target doesn't exist.
//
//
forwardProxy
.
on
(
'
error
'
,
function
(
err
)
{
});
forwardProxy
.
on
ce
(
'
error
'
,
function
(
err
)
{
});
// Chunk the client request body as chunks from the proxied request come in
// Chunk the client request body as chunks from the proxied request come in
req
.
on
(
'
data
'
,
function
(
chunk
)
{
req
.
on
(
'
data
'
,
function
(
chunk
)
{
...
...
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