On Fri, 16 Oct 2015 23:08:51 +0200
One Seeker <[email protected]> wrote:
> Thank you Willy, that's an honest answer.
> You grasped my "practical" concern (I always thought "Examples" section in
> man pages should be moved up high :)
> I've been to blog.haproxy.com, and no full-fat Lua meals there as of yet.
> I understand this is a new hot thing with HAProxy, so we'll have to wait
> for it to grow & thrive..
> Sure I'll report back here if I get to the point where I get some Lua code
> to do this (even a lame contraption).
>
> That being said, if a charitable soul here around can provide some working
> Lua code for modifying backend response in TCP mode, or a battle plan for
> the concept, that would be nice.
>
> Also, maybe this can be made a new feature in 1.7, even minimally : search
> for a stretch of bytes and replace with some other byte sequence (rewrites
> for TCP, basically), append a piece of data, .. that kind of simple stuff
> (at the user's own peril, of course. Shuffling bytes is for adults).
> Would be nice, and doesn't sound daunting to implement..
>
> Forgot to mention : HAProxy is freakin'great !
Hello, you can manipulate data on a tcp stream by this way:
- registering action
- using the object Channel
This is an untested sample code:
core.register_action("tcp-mod", { "tcp-req" }, function(txn)
local data = txn.req:get() -- get and remove the data waiting for forward
-- .. modify the data variable content ..
txn.req:set(data) -- set the modified data
end)
The associated doc:
http://www.arpalert.org/src/haproxy-lua-api/1.6/index.html#core.register_action
http://www.arpalert.org/src/haproxy-lua-api/1.6/index.html#channel-class
Thierry
> On Fri, Oct 16, 2015 at 7:15 PM, Willy Tarreau <[email protected]> wrote:
>
> > Hello,
> >
> > On Fri, Oct 16, 2015 at 06:38:16PM +0200, One Seeker wrote:
> > > Hello,
> > >
> > > I would like to manipulate some data from a TCP backend (modify data
> > before
> > > it is forwarded to client), and this is not supported (it is for HTTP
> > with
> > > rewrites, but not in TCP mode).
> > >
> > > With v1.6, Lua scripting brings hope, but the documentation is lacking
> > > (doc/lua-api/index.rst is a bit of a harsh place to start learning this
> > > aspect of HAProxy)..
> > > Is there an "elaborate" (or advanced) example of using Lua with HAProxy
> > > (not a Hello World) I can learn from (I'm very good at learning from
> > > real-world code :), not necessarily doing what I'm describing here, but
> > > just doing some real stuff to showcase Lua for HAProxy..
> >
> > I understand what you're looking for. I've seen that Thierry is currently
> > working on a nice doc, but as any doc, it takes at least as long to write
> > as it took to implement the documented features. There are some simple
> > examples on blog.haproxy.com, I don't know if they help you enough. Maybe
> > at some point if you post what you came up with, someone here could help
> > you finish.
> >
> > That's all I can provide for now :-/
> >
> > willy
> >
> >