passing additional data with the request

21 views
Skip to first unread message

pablo

unread,
Nov 8, 2009, 8:47:33 AM11/8/09
to MochiWeb
Hi,

I'm building a simple CMS on top of mochiweb.
In the loop have a dispatcher that pass the request to a handler
module.
There are several modules that process the request before it reaches
the handler which are similar
to django middlewares.
An example for a middleware is a session module which retrive the
user's session data from the db according to the session cookie in the
request.

Is there a way I can attach the session data and any other data to the
request?
I can call the handler with several parameters but it won't be
modular:
handler(Req, Session...)

I really like the way mochiweb uses parametrized modules to put all
data in the Req.
Will you consider adding a general get/set functions for custom
request data?

Thanks

Bob Ippolito

unread,
Nov 8, 2009, 12:28:04 PM11/8/09
to moch...@googlegroups.com
On Sun, Nov 8, 2009 at 5:47 AM, pablo <pablo...@gmail.com> wrote:
>
> I'm building a simple CMS on top of mochiweb.
> In the loop have a dispatcher that pass the request to a handler
> module.
> There are several modules that process the request before it reaches
> the handler which are similar
> to django middlewares.
> An example for a middleware is a session module which retrive the
> user's session data from the db according to the session cookie in the
> request.
>
> Is there a way I can attach the session data and any other data to the
> request?

No, the only state maintained in the request is the socket and what's
read from the socket.

> I can call the handler with several parameters but it won't be
> modular:
> handler(Req, Session...)

It could be perfectly modular if instead of Session you passed around
a proplist that your session middleware would modify, or an ets table
or something like that. I would recommend against using the process
dictionary because the process doesn't die at the end of a request so
you have to somehow make sure to clean it up.

> I really like the way mochiweb uses parametrized modules to put all
> data in the Req.
> Will you consider adding a general get/set functions for custom
> request data?

It doesn't fit the functional style and it adds overhead for something
we wouldn't use, so I wouldn't add this kind of functionality to
mochiweb_request.

-bob

pablo

unread,
Nov 8, 2009, 4:54:52 PM11/8/09
to MochiWeb


On Nov 8, 7:28 pm, Bob Ippolito <b...@redivi.com> wrote:
> On Sun, Nov 8, 2009 at 5:47 AM, pablo <pablo.pl...@gmail.com> wrote:
>
> > I'm building a simple CMS on top of mochiweb.
> > In the loop have a dispatcher that pass the request to a handler
> > module.
> > There are several modules that process the request before it reaches
> > the handler which are similar
> > to django middlewares.
> > An example for a middleware is a session module which retrive the
> > user's session data from the db according to the session cookie in the
> > request.
>
> > Is there a way I can attach the session data and any other data to the
> > request?
>
> No, the only state maintained in the request is the socket and what's
> read from the socket.
>
> > I can call the handler with several parameters but it won't be
> > modular:
> > handler(Req, Session...)
>
> It could be perfectly modular if instead of Session you passed around
> a proplist that your session middleware would modify, or an ets table
> or something like that. I would recommend against using the process
> dictionary because the process doesn't die at the end of a request so
> you have to somehow make sure to clean it up.

I thought the process die at the end of a request.
What's the purpose of keeping it alive?

>
> > I really like the way mochiweb uses parametrized modules to put all
> > data in the Req.
> > Will you consider adding a general get/set functions for custom
> > request data?
>
> It doesn't fit the functional style and it adds overhead for something
> we wouldn't use, so I wouldn't add this kind of functionality to
> mochiweb_request.
>
> -bob

I'm looking at ewgi and beepbeep.
Do you think there is an advantage of using ewgi except for server
portability?
It introduces middleware chaining and iterator to mochiweb which let
you handle session and url rewriting for example.
Yet, I feel that it duplicates part of mochiweb code.

pablo

Bob Ippolito

unread,
Nov 8, 2009, 4:59:08 PM11/8/09
to moch...@googlegroups.com

HTTP Keep-Alive.

>>
>> > I really like the way mochiweb uses parametrized modules to put all
>> > data in the Req.
>> > Will you consider adding a general get/set functions for custom
>> > request data?
>>
>> It doesn't fit the functional style and it adds overhead for something
>> we wouldn't use, so I wouldn't add this kind of functionality to
>> mochiweb_request.
>

> I'm looking at ewgi and beepbeep.
> Do you think there is an advantage of using ewgi except for server
> portability?
> It introduces middleware chaining and iterator to mochiweb which let
> you handle session and url rewriting for example.
> Yet, I feel that it duplicates part of mochiweb code.

I don't have any opinion on that stuff, we only use mochiweb as-is.

-bob

Reply all
Reply to author
Forward
0 new messages