You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Matt Hughes <hu...@gmail.com> on 2016/04/16 03:10:06 UTC

[users@httpd] Using mod_lua to modify request body before being sent to mod_proxy

I currently have Apache setup as a reverse proxy to another server.

I was hoping to use mod_lua to slightly tweak the request body of incoming requests before sending them off to the other server. I have mod_lua setup enough so that I have a LuaHookInsertFilter that is pointing to my LuaInputFilter. But the question is, what does the function in the LuaHookInsertFilter have to return so that the modified request continues on to the proxy?

Right now I have something like:

function handle(r)
    r.info(r, "example handler called") -- debug print
    r:add_input_filter("myInputFilter")
    return apache2.PROXYREQ_REVERSE
end
Am I using the right LuaHook? Any examples would be greatly appreciated.





Re: [users@httpd] Using mod_lua to modify request body before being sent to mod_proxy

Posted by Rainer Jung <ra...@kippdata.de>.
Am 19.04.2016 um 04:41 schrieb Matt Hughes:
> Yeah, I misspoke when I said |LuaHookInsertFilter|; that isn’t actually
> implemented yet at least on 2.4. Actually have been trying the quick
> handler and hookfixups.
>
> What hook should I be using? What value do I return from my handler so
> that Apache will still send the request onto the reverse proxy?
>
> I feel like this (http://www.modlua.org/recipes/loadbalancing) may be
> what I want, but I don’t know how to hook that into my httpd.conf file.
> Does this tie into mod_proxy at all, or is this instead of?
>
> In that example, what is the magic string “proxy-server”?:

As far as I can see it is only used by mod_dir and set by mod_rewrite 
(in case a rewrite rule triggers proxying) and mod_proxy. I haven't 
inspected in detail, why mod_dir checks it.

> |function proxy_handler(r) r.handler = "proxy-server" r.proxyreq =
> apache2.PROXYREQ_REVERSE r.filename = "proxy:" ..
> backends[math.random(1,#backends)] .. r.uri return apache2.DECLINED --
> let the proxy handler do this instead end |

Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Using mod_lua to modify request body before being sent to mod_proxy

Posted by Matt Hughes <hu...@gmail.com>.
Yeah, I misspoke when I said LuaHookInsertFilter; that isn’t actually implemented yet at least on 2.4. Actually have been trying the quick handler and hookfixups.

What hook should I be using? What value do I return from my handler so that Apache will still send the request onto the reverse proxy?

I feel like this (http://www.modlua.org/recipes/loadbalancing) may be what I want, but I don’t know how to hook that into my httpd.conf file. Does this tie into mod_proxy at all, or is this instead of?

In that example, what is the magic string “proxy-server”?:

function proxy_handler(r)
    r.handler  = "proxy-server"
    r.proxyreq = apache2.PROXYREQ_REVERSE
    r.filename = "proxy:" .. backends[math.random(1,#backends)] .. r.uri
    return apache2.DECLINED -- let the proxy handler do this instead
end




On April 15, 2016 at 9:47:01 PM, Eric Covener (covener@gmail.com) wrote:

On Fri, Apr 15, 2016 at 9:10 PM, Matt Hughes <hu...@gmail.com> wrote:  
> I currently have Apache setup as a reverse proxy to another server.  
>  
> I was hoping to use mod_lua to slightly tweak the request body of incoming  
> requests before sending them off to the other server. I have mod_lua setup  
> enough so that I have a LuaHookInsertFilter that is pointing to my  
> LuaInputFilter. But the question is, what does the function in the  
> LuaHookInsertFilter have to return so that the modified request continues on  
> to the proxy?  
>  
> Right now I have something like:  
>  
> function handle(r)  
> r.info(r, "example handler called") -- debug print  
> r:add_input_filter("myInputFilter")  
> return apache2.PROXYREQ_REVERSE  
> end  
>  
> Am I using the right LuaHook? Any examples would be greatly appreciated.  

Looks right to me. The underlying hook for "insert_filter" expects a  
void return.  

This means everyone who is registered gets called every time.  

---------------------------------------------------------------------  
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org  
For additional commands, e-mail: users-help@httpd.apache.org  


Re: [users@httpd] Using mod_lua to modify request body before being sent to mod_proxy

Posted by Eric Covener <co...@gmail.com>.
On Fri, Apr 15, 2016 at 9:10 PM, Matt Hughes <hu...@gmail.com> wrote:
> I currently have Apache setup as a reverse proxy to another server.
>
> I was hoping to use mod_lua to slightly tweak the request body of incoming
> requests before sending them off to the other server. I have mod_lua setup
> enough so that I have a LuaHookInsertFilter that is pointing to my
> LuaInputFilter. But the question is, what does the function in the
> LuaHookInsertFilter have to return so that the modified request continues on
> to the proxy?
>
> Right now I have something like:
>
> function handle(r)
>     r.info(r, "example handler called") -- debug print
>     r:add_input_filter("myInputFilter")
>     return apache2.PROXYREQ_REVERSE
> end
>
> Am I using the right LuaHook? Any examples would be greatly appreciated.

Looks right to me. The underlying hook for "insert_filter" expects a
void return.

This means everyone who is registered gets called every time.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org