Hello,

I agree its not clear :) "http-response" is an HAProxy for modifying
the response. I think that its a good idea to add 2 new keyword with
this function like this:

   http-response set-code
   http-response set-reason

(look in src/proto_http.c in the function "parse_http_res_cond")

With this two new directives, your function "http_replace_res_line"
will be in used with "native" haproxy configuration and with Lua
functions. 

Thierry

On Thu, 23 Jul 2015 19:06:00 -0700
Bowen Ni <[email protected]> wrote:

> Hi Thierry,
> 
> Sure. Please find the attachment. I'm patching on top of haproxy-ss-20150723
> I'm not sure what did you mean by "the function http_replace_res_line
> should be integrated also with the http-response". Could you explain a bit?
> Thank you!
> 
> Best,
> Bowen
> 
> On Thu, Jul 23, 2015 at 1:14 AM, Thierry FOURNIER <
> [email protected]> wrote:
> 
> > Hi Bowen,
> >
> > Can you send an email with the pacth in attachement ? the email
> > encoding for inline text makes some difficulties to get the patch
> > without modifications.
> >
> > In other way, the patch its intresting, but I think that the function
> > "http_replace_res_line" should be integrated also with the
> > "http-response".
> >
> > thank you
> > Thierry
> >
> > On Sun, 12 Jul 2015 22:22:22 -0700
> > Bowen Ni <[email protected]> wrote:
> >
> > > Hi,
> > >
> > > With Lua integration in HAProxy 1.6, one can change the request method,
> > > path, uri, header, response header etc except response line.
> > > I'd like to contribute the following methods to allow modification of the
> > > response line.
> > >
> > > diff --git a/haproxy-ss-20150711/src/hlua.c
> > b/haproxy-ss-20150711/src/hlua.c
> > > index a5df204..c56de6e 100644
> > > --- a/haproxy-ss-20150711/src/hlua.c
> > > +++ b/haproxy-ss-20150711/src/hlua.c
> > > @@ -3305,6 +3305,26 @@ static int hlua_http_req_set_uri(lua_State *L)
> > >       return 1;
> > >  }
> > >
> > > +static int hlua_http_res_set_code(lua_State *L)
> > > +{
> > > +     struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
> > > +     size_t name_len;
> > > +     const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
> > > +
> > > +     lua_pushboolean(L, http_replace_res_line(0, name, name_len,
> > htxn->p,
> > > htxn->s) != -1);
> > > +     return 1;
> > > +}
> > > +
> > > +static int hlua_http_res_set_reason(lua_State *L)
> > > +{
> > > +     struct hlua_txn *htxn = MAY_LJMP(hlua_checkhttp(L, 1));
> > > +     size_t name_len;
> > > +     const char *name = MAY_LJMP(luaL_checklstring(L, 2, &name_len));
> > > +
> > > +     lua_pushboolean(L, http_replace_res_line(1, name, name_len,
> > htxn->p,
> > > htxn->s) != -1);
> > > +     return 1;
> > > +}
> > > +
> > >  /*
> > >   *
> > >   *
> > > @@ -4969,6 +4989,8 @@ void hlua_init(void)
> > >       hlua_class_function(gL.T, "res_rep_value",  hlua_http_res_rep_val);
> > >       hlua_class_function(gL.T, "res_add_header", hlua_http_res_add_hdr);
> > >       hlua_class_function(gL.T, "res_set_header", hlua_http_res_set_hdr);
> > > +     hlua_class_function(gL.T, "res_set_code",
> >  hlua_http_res_set_code);
> > > +     hlua_class_function(gL.T, "res_set_reason",
> > hlua_http_res_set_reason);
> > >
> > >       lua_settable(gL.T, -3);
> > >
> > > diff --git a/haproxy-ss-20150711/src/proto_http.c
> > > b/haproxy-ss-20150711/src/proto_http.c
> > > index 0ebc2c4..6075f83 100644
> > > --- a/haproxy-ss-20150711/src/proto_http.c
> > > +++ b/haproxy-ss-20150711/src/proto_http.c
> > > @@ -12463,6 +12463,45 @@ int http_replace_req_line(int action, const
> > > char *replace, int len,
> > >       return 0;
> > >  }
> > >
> > > +int http_replace_res_line(int action, const char *replace, int len,
> > > struct proxy *px, struct stream *s)
> > > +{
> > > +     struct http_txn *txn = s->txn;
> > > +     char *cur_ptr, *cur_end;
> > > +     int offset = 0;
> > > +     int delta;
> > > +
> > > +     switch (action) {
> > > +     case 0: // code
> > > +             cur_ptr = s->res.buf->p + txn->rsp.sl.st.c;
> > > +             cur_end = cur_ptr + txn->rsp.sl.st.c_l;
> > > +
> > > +             /* adjust res line offsets and lengths */
> > > +             delta = len - offset - (cur_end - cur_ptr);
> > > +             txn->rsp.sl.st.c_l += delta;
> > > +             txn->rsp.sl.st.r   += delta;
> > > +             break;
> > > +
> > > +     case 1: // reason
> > > +             cur_ptr = s->res.buf->p + txn->rsp.sl.st.r;
> > > +             cur_end = cur_ptr + txn->rsp.sl.st.r_l;
> > > +
> > > +             /* adjust res line offsets and lengths */
> > > +             delta = len - offset - (cur_end - cur_ptr);
> > > +             txn->rsp.sl.st.r_l += delta;
> > > +             break;
> > > +
> > > +     default:
> > > +             return -1;
> > > +     }
> > > +
> > > +     /* commit changes and adjust end of message */
> > > +     delta = buffer_replace2(s->res.buf, cur_ptr, cur_end, replace +
> > > offset, len - offset);
> > > +     txn->rsp.sl.st.l += delta;
> > > +     txn->hdr_idx.v[0].len += delta;
> > > +     http_msg_move_end(&txn->rsp, delta);
> > > +     return 0;
> > > +}
> > > +
> > >
> > > Best,
> > >
> > > Bowen
> >

Reply via email to