You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Bertrand Mansion <bm...@mamasam.net> on 2009/01/11 13:21:50 UTC

mod_lua headers_out

Hi,

My name is Bertrand Mansion, I live in Paris, France, I have been
mostly programming in PHP for the last few years and I am very excited
about mod_lua since I consider Lua is superior in many ways. I have
followed the development of mod_wombat and noticed that you changed
the way headers_in and headers_out are accessed, they were previously
tables, now only headers_in can be accessed through a headers_in()
method. I have written a method to have access to headers_out as well.
I am not sure it is perfect since I haven't coded with Lua and apr C
APIs before and many you thought already about something more clever.

Anyway, with this patch, you can do:
r:headers_out('Location', 'http://www.example.com') -- set the Location header
r:headers_out('Location) -- return the current value for header Location
r:headers_out('Location', nil) -- unset the Location header

There might be other options I haven't implemented for example:

r.headers_out['Location'] = 'http://www.example.com' -- like in
previous versions of mod_wombat
  or
r:headers_out{Location = 'http://www.example.com} -- but then it
becomes harder to unset a header (?)
  or
r.headers_out:set('Location', 'http://www.example.com')
r.headers_out:get('Location')
r.headers_out:unset('Location')

HTH

-----
Bertrand Mansion
Mamasam

Re: mod_lua headers_out

Posted by Brian McCallister <br...@skife.org>.
On Mon, Jan 12, 2009 at 2:07 AM, Bertrand Mansion <bm...@mamasam.net> wrote:

.. snip ..

>> Does that work?
>
> Yes, it will work, thank you :)
>
> The advantage of having a function instead of a table for setting
> headers_in/headers_out is that you can use luaL_checkstring() to make
> sure the given parameters are of the correct type. I don't know what
> the patch will return if someone tries to set a table like in
> headers_out['Foo'] = {Bar = 'baz'}
>
> Maybe it is possible to set a metatable for headers_in/headers_out
> that would check on __index and __newindex if the value validates with
> luaL_checkstring (just thinking out loud).
>

I believe it does -- header_in and headers_out are boxed apr_table_t
instances and the only thing they have in their metatable are __index
and __newindex. If they are not checking for strings, that is a bug as
apr_table_t is string only.

-Brian

Re: mod_lua headers_out

Posted by Bertrand Mansion <bm...@mamasam.net>.
On Mon, Jan 12, 2009 at 5:23 AM, Brian McCallister <br...@skife.org> wrote:
> Bertrand,
>
> I just send in a patch on the message with subject "patch for handling
> headers_in and headers_out as tables in mod_lua" which takes knowledge
> of setting headers_in, headers_out off the request which, with that
> patch, can just push the apr_table_t as a boxed pointer allowing
> lua-style [] access and modification.
>
> Does that work?

Yes, it will work, thank you :)

The advantage of having a function instead of a table for setting
headers_in/headers_out is that you can use luaL_checkstring() to make
sure the given parameters are of the correct type. I don't know what
the patch will return if someone tries to set a table like in
headers_out['Foo'] = {Bar = 'baz'}

Maybe it is possible to set a metatable for headers_in/headers_out
that would check on __index and __newindex if the value validates with
luaL_checkstring (just thinking out loud).

Re: mod_lua headers_out

Posted by Brian McCallister <br...@skife.org>.
Bertrand,

I just send in a patch on the message with subject "patch for handling
headers_in and headers_out as tables in mod_lua" which takes knowledge
of setting headers_in, headers_out off the request which, with that
patch, can just push the apr_table_t as a boxed pointer allowing
lua-style [] access and modification.

Does that work?

-Brian

On Sun, Jan 11, 2009 at 4:21 AM, Bertrand Mansion <bm...@mamasam.net> wrote:
> Hi,
>
> My name is Bertrand Mansion, I live in Paris, France, I have been
> mostly programming in PHP for the last few years and I am very excited
> about mod_lua since I consider Lua is superior in many ways. I have
> followed the development of mod_wombat and noticed that you changed
> the way headers_in and headers_out are accessed, they were previously
> tables, now only headers_in can be accessed through a headers_in()
> method. I have written a method to have access to headers_out as well.
> I am not sure it is perfect since I haven't coded with Lua and apr C
> APIs before and many you thought already about something more clever.
>
> Anyway, with this patch, you can do:
> r:headers_out('Location', 'http://www.example.com') -- set the Location header
> r:headers_out('Location) -- return the current value for header Location
> r:headers_out('Location', nil) -- unset the Location header
>
> There might be other options I haven't implemented for example:
>
> r.headers_out['Location'] = 'http://www.example.com' -- like in
> previous versions of mod_wombat
>  or
> r:headers_out{Location = 'http://www.example.com} -- but then it
> becomes harder to unset a header (?)
>  or
> r.headers_out:set('Location', 'http://www.example.com')
> r.headers_out:get('Location')
> r.headers_out:unset('Location')
>
> HTH
>
> -----
> Bertrand Mansion
> Mamasam
>

Re: mod_lua headers_out

Posted by Brian McCallister <br...@skife.org>.
On Sun, Jan 11, 2009 at 4:21 AM, Bertrand Mansion <bm...@mamasam.net> wrote:

.. snip ..

> I have
> followed the development of mod_wombat and noticed that you changed
> the way headers_in and headers_out are accessed, they were previously
> tables

I would actually prefer to make them tables again -- in particular, to
put the  apr_table_t instance directly in as a boxed userdata.

Paul, any particular reason for making it a function rather than userdata?

>
> Anyway, with this patch, you can do:
> r:headers_out('Location', 'http://www.example.com') -- set the Location header
> r:headers_out('Location) -- return the current value for header Location
> r:headers_out('Location', nil) -- unset the Location header
>
> There might be other options I haven't implemented for example:
>
> r.headers_out['Location'] = 'http://www.example.com' -- like in
> previous versions of mod_wombat
>  or
> r:headers_out{Location = 'http://www.example.com} -- but then it
> becomes harder to unset a header (?)
>  or
> r.headers_out:set('Location', 'http://www.example.com')
> r.headers_out:get('Location')
> r.headers_out:unset('Location')
>
> HTH
>
> -----
> Bertrand Mansion
> Mamasam
>