i.e. with the patch
http.createServer(m1, m2).listen(PORT);
is equivalent to
var server = http.createServer(m1);
server.addListener("request", m2);
server.listen(PORT);
The patch (plus test case) is at
This makes simple HTTP middleware a little bit easier to build.
(I was thinking about whether it would make sense for the arguments to
http.createServer() to be applied in a chain, with execution halting
if a listener returned false, but I think it's probably better for
that behaviour to be implemented by hand.)
Cheers,
Michael
> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>
I think this API is good enough
var s = http.createServer();
s.addListener(m1);
s.addListener(m2);
Oh, I didn't realise createServer() with no arguments would work. So the
server.addListener("request", null);
in http.js's createServer() will be a no-op? It seems as though
emitter.addListener("foo", something) doesn't do anything unless
typeof something == 'function'.
If you want it, there's a patch adding a test for the
s.addListener("request", m1), s.addListener("request", m2) style at
Michael
On Tue, Feb 23, 2010 at 1:44 AM, Mark Hansen <ma...@markhansen.co.nz> wrote:
> Sorry, I'm not sure I understand what this could be used for? Could
> you give an example?
Adding multiple request listeners is not tremendously useful (since
the request is largely unmodifiable and writing to the response at
multiple points is not really going to work), and no substitute for
real HTTP middleware, but you might want to use it to stack a logger
or ACL system, say, on top of your "regular" "request" listener.
Michael