]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: http: add a function to validate characters of :authority
authorWilly Tarreau <w@1wt.eu>
Mon, 12 May 2025 15:39:08 +0000 (17:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 May 2025 16:02:47 +0000 (18:02 +0200)
commitebab479cdf34255cd6162d2e843645f88b95327f
treebcee8222ff4244df340db9e75239f75da21058ee
parentc40d6ac84012d3f8c46e0c8aa90b5898111e642f
MINOR: http: add a function to validate characters of :authority

As discussed here:
  https://github.com/httpwg/http2-spec/pull/936
  https://github.com/haproxy/haproxy/issues/2941

It's important to take care of some special characters in the :authority
pseudo header before reassembling a complete URI, because after assembly
it's too late (e.g. the '/').

This patch adds a specific function which was checks all such characters
and their ranges on an ist, and benefits from modern compilers
optimizations that arrange the comparisons into an evaluation tree for
faster match. That's the version that gave the most consistent performance
across various compilers, though some hand-crafted versions using bitmaps
stored in register could be slightly faster but super sensitive to code
ordering, suggesting that the results might vary with future compilers.
This one takes on average 1.2ns per character at 3 GHz (3.6 cycles per
char on avg). The resulting impact on H2 request processing time (small
requests) was measured around 0.3%, from 6.60 to 6.618us per request,
which is a bit high but remains acceptable given that the test only
focused on req rate.

The code was made usable both for H2 and H3.
include/haproxy/http.h