Project

General

Profile

[Solved] Reverse Proxy - Catch/Log Response

Added by carlos over 6 years ago

Hi,

I want to check the response for the forwarded request in Lighttpd (ideally) in a Lua script. Something like:


$HTTP["url"] =~ "^/DoStuff" {

    proxy.server  = ( "" => 
                        ( "" =>
                            (
                                "host" => "127.0.0.1",
                                "port" => 8080
                            )
                        )
                    ),

      run_script = ( "check_response.lua")

}

Is this possible ? My objective here is to confirm from lighttpd that the local http server was able to successfully reply to the forwarded request.


Replies (5)

RE: Reverse Proxy - Catch/Log Response - Added by gstrauss over 6 years ago

What is the problem you are trying to solve? Please don't simply present that "solution" that you think you want to use. Why do you need to check the response of the backend http server? Why isn't your script running in, or acting as the local http server? Plenty of scripting languages provide libraries to act as httpd servers and work fine as long as you don't need high performance. Why must you run your script in the proxy? In lighttpd, mod_magnet can handle a request, but does not have a hook to post-process a response from another handler.

RE: Reverse Proxy - Catch/Log Response - Added by carlos over 6 years ago

Thanks for the reply.

Making it more clear then, the problem I want to solve is how do I log/check the response of forwarded requests.

To give greater context, I am using Lighttpd as a kind of service integration layer. All external (that is, outside of the local network) requests are routed thru Lighttpd, which also handles authorisation, and then forwarded to the correct service provider.
One of the access rules I want to enforce requires me to know that the request was properly handled by the service provider. Hence the need to check the response.

And yes, I know mod_magnet can only handle requests, not responses. Should have made the 'solution' more generic, what I intended to highlight was the need for a hook for the response.

What I came up with is this :

    proxy.server  = ( "" => 
                        ( "" =>
                            (
                                "host" => "127.0.0.1",
                                "port" => 8080
                            )
                        )
                    ),

    accesslog.format = "%h %t \"%r\" %>s %b",
    accesslog.filename = "commands.log" 

As the rule(s) I want to enforce only impact new request and not the current one, I am using accesslog to log information (will still check if it can log all the information I require) that I will later on use in rule enforcement.

RE: Reverse Proxy - Catch/Log Response - Added by gstrauss over 6 years ago

As you found, mod_accesslog is the proper solution to logging response status.

RE: [Solved] Reverse Proxy - Catch/Log Response - Added by carlos over 6 years ago

Yes, but that was not my specific intent. :)

Fortunately for my purposes, it will (hopefully) be sufficient as the rules I need to enforce are on new requests and not current ones.

Cheers

RE: [Solved] Reverse Proxy - Catch/Log Response - Added by gstrauss 12 months ago

FYI: since lighttpd 1.4.56, lighttpd mod_magnet supports magnet.attract-response-start-to and if the response is not configured in lighttpd.conf to be streamed (the default), then you may use lua to manipulate the response.

    (1-5/5)