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
c887a757
Commit
c887a757
authored
Aug 08, 2010
by
indexzero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[api] Updated request hashes to use a unique identifier
parent
d15bba4c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
15 deletions
+38
-15
lib/node-http-proxy.js
lib/node-http-proxy.js
+38
-15
No files found.
lib/node-http-proxy.js
View file @
c887a757
...
...
@@ -32,6 +32,7 @@ exports.HttpProxy = function () {
this
.
emitter
=
new
(
events
.
EventEmitter
);
this
.
events
=
{};
this
.
listeners
=
{};
this
.
collisions
=
{};
};
exports
.
createServer
=
function
()
{
...
...
@@ -83,34 +84,55 @@ exports.HttpProxy.prototype = {
watch
:
function
(
req
,
res
)
{
var
self
=
this
;
this
.
events
[
req
]
=
[];
// Create a unique id for this request so
// we can reference it later.
var
id
=
new
Date
().
getTime
().
toString
();
this
.
listeners
[
req
]
=
{
// If we get a request in the same tick, we need to
// append to the id so it stays unique.
if
(
typeof
this
.
collisions
[
id
]
===
'
undefined
'
)
{
this
.
collisions
[
id
]
=
0
;
}
else
{
this
.
collisions
[
id
]
++
;
id
+=
this
.
collisions
[
id
];
}
req
.
id
=
id
;
this
.
events
[
req
.
id
]
=
[];
this
.
listeners
[
req
.
id
]
=
{
onData
:
function
()
{
self
.
events
[
req
].
push
([
'
data
'
].
concat
(
self
.
toArray
(
arguments
)));
self
.
events
[
req
.
id
].
push
([
'
data
'
].
concat
(
self
.
toArray
(
arguments
)));
},
onEnd
:
function
()
{
self
.
events
[
req
].
push
([
'
end
'
].
concat
(
self
.
toArray
(
arguments
)));
self
.
events
[
req
.
id
].
push
([
'
end
'
].
concat
(
self
.
toArray
(
arguments
)));
}
};
req
.
addListener
(
'
data
'
,
this
.
listeners
[
req
].
onData
);
req
.
addListener
(
'
end
'
,
this
.
listeners
[
req
].
onEnd
);
req
.
addListener
(
'
data
'
,
this
.
listeners
[
req
.
id
].
onData
);
req
.
addListener
(
'
end
'
,
this
.
listeners
[
req
.
id
].
onEnd
);
},
unwatch
:
function
(
req
,
res
)
{
req
.
removeListener
(
'
data
'
,
this
.
listeners
[
req
].
onData
);
req
.
removeListener
(
'
end
'
,
this
.
listeners
[
req
].
onEnd
);
req
.
removeListener
(
'
data
'
,
this
.
listeners
[
req
.
id
].
onData
);
req
.
removeListener
(
'
end
'
,
this
.
listeners
[
req
.
id
].
onEnd
);
// Rebroadcast any events that have been buffered
while
(
this
.
events
[
req
].
length
>
0
)
{
var
args
=
this
.
events
[
req
].
shift
();
while
(
this
.
events
[
req
.
id
].
length
>
0
)
{
var
args
=
this
.
events
[
req
.
id
].
shift
();
req
.
emit
.
apply
(
req
,
args
);
}
// Remove the data from the event and listeners hashes
delete
this
.
listeners
[
req
];
delete
this
.
events
[
req
];
delete
this
.
listeners
[
req
.
id
];
delete
this
.
events
[
req
.
id
];
// If this request id is a base time, delete it
if
(
typeof
this
.
collisions
[
req
.
id
]
!==
'
undefined
'
)
{
delete
this
.
collisions
[
req
.
id
];
}
},
proxyRequest
:
function
(
port
,
server
,
req
,
res
)
{
...
...
@@ -135,11 +157,12 @@ exports.HttpProxy.prototype = {
res
.
end
();
});
// Add a listener for the reverse_proxy response event
reverse_proxy
.
addListener
(
'
response
'
,
function
(
response
)
{
// 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
'
)
{
...
...
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