Hi haproxy list,
For testing purposes i am trying to 'modify' a response of a webserver
but only having limited success. Is this supposed to work?
As a more usefull goal than the current LAL to TST replacement i imagine
rewriting absolute links on a webpage could be possible which is
sometimes problematic with 'dumb' webapplications..
Or is it outside of the current scope of implemented functionality? If
so, it on the 'lua todo list' ?
I tried for example a configuration like below. And get several
different results in the browser.
-Sometimes i get 4 times TSTA
-Sometimes i see after the 8th TSTA- Connection: keep-alive << this
happens most of the time..
-Sometimes i get 9 times TSTA + STOP << this would be the desired
outcome (only seen very few times..)
Probably due to the response-buffer being filled differently due to
'timing'..
The "connection: keep-alive" text is probably from the actual server
reply which is 'appended' behind the response generated by my lua
script.?. However shouldn't the .done() prevent that from being send to
the client?
Ive tried putting a loop into the lua script to call res:get() multiple
times but that didnt seem to work..
Also to properly modify a page i would need to know all changes before
sending the headers with changed content-length back to the client..
Can someone confirm this is or isn't (reliably) possible? Or how this
can be scripted in lua differently?
Thanks in advance,
PiBa-NL
## haproxy.cfg
listen proxyresponse
bind :10006
mode http
http-response lua.luahttpresponse
server x 192.168.0.40:302
## script.lua
function luahttpresponse(txn)
local response2 = txn.res:get()
response2 = string.gsub(response2,"LAL","TST")
txn.res:send(response2)
txn.done()
end
core.register_action("luahttpresponse" , { "http-res" }, luahttpresponse);
## webpage.aspx , with 2.7KB output.
------------------
<%@ Page Language="C#" %>
<html><body>START
<% var x = new String('x', 250);
x = "<input type=\"hidden\" value=\""+x+"\" />"; %>
1 -LALA- <% Response.Write(x); %>
2 -LALA- <% Response.Write(x); %>
3 -LALA- <% Response.Write(x); %>
4 -LALA- <% Response.Write(x); %>
5 -LALA- <% Response.Write(x); %>
6 -LALA- <% Response.Write(x); %>
7 -LALA- <% Response.Write(x); %>
8 -LALA- <% Response.Write(x); %>
9 -LALA- <% Response.Write(x); %>
STOP
--------------------