Re: Refiring requests to proxy backend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel,

I have successfully implemented the router in lua using a lua script called from a "LuaHookFixups" directive.

LuaHookFixups /var/www/lua/myscript.lua router

-- /var/www/lua/myscript.lua
function router(r)
    local route = get_route(r)
    if route then
        r.filename = "proxy:balancer://" .. route .. r.uri
    end
    return apache2.DECLINED
end


For the second requirement- i wired up a LuaOutputFilter which can catch the custom response code. What i was not able to figure out was how to send the request back to the backend.

LuaOutputFilter myfilter /var/www/lua/myscript.lua output_filter

function output_filter(r)
    if r.status ~= 399 then
        return
    end

    coroutine.yield()
    while bucket ~= nil do
        coroutine.yield(bucket)
    end
    coroutine.yield()
end

Is it possible to retry the request again from the output filter ?

Regards,
Jose

On Fri, Dec 18, 2015 at 9:42 PM, Daniel Gruno <humbedooh@xxxxxxxxxx> wrote:
I think you need two phases here, as mod_lua doesn't itself do the
proxying, but delegates it to mod_proxy.

First, http://modlua.org/recipes/loadbalancing will show you how to proxy.

Secondly, you could then set up a handler for the specific HTTP code
using ErrorDocument or an output filter.

I haven't tried this myself (the 'act on return code'), but it should work.

With regards,
Daniel.

On 12/18/2015 04:23 PM, Jim Jagielski wrote:
> I'm not a mod_lua expert, esp as it relates to exposing the
> full Apache httpd API... it is possible that using r.handler
> and specifying the proxy may work.
>
>> On Dec 18, 2015, at 8:05 AM, Jose Thomas <jostho@xxxxxxxxx> wrote:
>>
>> Jim,
>>
>> Sorry, I could not find the documentation on how to do this using mod_lua. Can you please point me there ?
>>
>> In my current setup which is on httpd 2.2 - we use modpython. For routing requests (based on a header) we use a simple python script. For refiring the request (when a custom response code is received), another python script is configured in a "PythonOutputFilter". That script internally uses the python requests library.
>>
>> We are upgrading to httpd 2.4 and wanted to see if this code can be ported to mod_lua. I have already ported the first script (routing) to lua. Where i am clueless, is how to resend the request to backend for the 2nd script in a "LuaOutputFilter".
>>
>> Thanks & regards,
>> Jose
>>
>> On Fri, Dec 18, 2015 at 5:08 PM, Jim Jagielski <jim@xxxxxxxxxxx> wrote:
>> In general, if you prepend the URL w/ 'proxy:' and then
>> use it in a subrequest, it will be processed as a proxy
>> request.
>>> On Dec 17, 2015, at 9:21 AM, Jose Thomas <jostho@xxxxxxxxx> wrote:
>>>
>>> All,
>>>
>>> I am using httpd 2.4 with mod_proxy (http) routing requests to multiple backends.
>>>
>>> I have a strange requirement. If a backend responds with a custom response code - i need to re-execute the request to a different backend.
>>>
>>> What would be the right way to implement this functionality ?
>>>
>>> I was looking at mod_lua for a solution. The idea is to use a "LuaOutputFilter" to check the response code, and then re-execute the request with a different backend. How can i refire the request ? Should i use a lua httpclient library for this ? Is there a easier way to do this ?
>>>
>>> Any other suggestions/comments are welcome.
>>>
>>> Version of stack
>>> * Apache 2.4.6
>>> * Lua 5.1.4
>>>
>>> Regards,
>>> Jose
>>> ____________
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
>> For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
> For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux