Hi Ruei-Bang,

On Fri, Nov 10, 2023 at 01:33:01AM +0000, Ruei-Bang Chen wrote:
> Hi team,
> 
> Based on the feedback from
> https://www.mail-archive.com/haproxy@formilux.org/msg44153.html, I have
> attached a patch for modifying fetchers for req.hdrs and res.hdrs to
> selectively include / exclude headers.

Great!

> I have the following 3 questions while I was doing this change:
> 
>   1.  Should I place the helper function skip_hdr_for_fetch  within
>       http_fetch.c  or there is a better place for this?

I think it's fine like this.

>   2.  Should I do this to smp_fetch_hdrs_bin  as well? I can update the code,
>       comments, documentation if that is needed.

Indeed, that would be an excellent idea, in order to maintain consistency
between the two.

>   3.> Not sure if this is the best style for modifying the fetch to support
>   10 arguments as it does not align with other fetchers due to the huge
>   number of characters required.

I had a look at it, and it's fine to me. What I'm suspecting is that if
users find it useful, it will not be long before some ask for a way to
designate prefixes (e.g. select x-companyname-*, or exclude accept-* etc).
The way you did it will make it easy to extend it for this, for example,
by appending '*' to a header name, so that's fine. Hmmm well, '*' is
actually permitted in header field names, so maybe another solution could
be that we consider that we'd use prefixes by default and terminante names
with ':' to designate full names. E.g. req.hdrs(accept:) would match only
"accept" while req.hdrs(accept) would also match accept-encoding,
accept-range etc. It's just up to us to decide (and you first since you're
the first one to need this, so the ability to extend this and/or to factor
arguments may be relevant to your use case.

If you want to slightly optimize the loop in smp_fetch_hdrs(), you should
call skip_hdr_for_fetch() only when you have at least one argument, so
that by default when called with no argument, it skips it. I don't know
what the most common use case will be, to be honest, so just take this
as a hint, maybe we don't care that much about all headers given that
the overall processing around it will be expensive anyway.

> Please let me know what are your thoughts on this.

I think it's quite nice like this and you patch looks clean. Please just
consider the points above in case that gives you some ideas.

Similarly I'm seeing that having the '!' in the first argument does add
some special cases everywhere down the inner loop. Maybe just having a
new name such as "req.hdrs_exc()" to enumerate exclusion would simplify
everything, and possibly make it easier even for APIs which will feed
these arguments, so as to remove the special case of the first argument.
I don't know, but feel free to explore such possibilities, it's important
to think about how configs will be used and updated. Very often the amount
of work needed to make the core easy to use is less than the work needed
externally to adapt to it ;-)

Maybe other participants here have any idea on this matter ?

Thanks!
Willy

Reply via email to