Dynamic input to lua action?

I want an haproxy rule that does a redirect, but adds CORS headers to the response conditionally, based on the Origin header of the request. Furthermore, the location of the redirect is dynamic. I’m using 1.8, so I don’t have the http-after-response set-header option. I’ve tried several approaches, but none have worked the way I want.

register_service doesn’t allow me to give it any arguments. I can pass it data with a variable, but unfortunately, afaict there isn’t a way to set a variable using log format, or concatenate strings, so I can’t compose multiple inputs into a single variable.

register_action allows me to take arguments, but haproxy doesn’t seem to do any kind of processing before giving them to me, so something like https://%[req.hdr(Host),word(1)].new.example.com%[url] doesn’t work. I also wasn’t able to figure out a way to respond with http other than an HTTP response directly to the res channel, which won’t work if we ever switch to supporting http/2.

Is there a way to accomplish this in haproxy 1.8?