From: Willy Tarreau Date: Fri, 7 Dec 2018 07:47:45 +0000 (+0100) Subject: MEDIUM: ist: always turn header names to lower case X-Git-Tag: v1.9-dev10~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed00e345e2f4b734fd37d697a4a67aab74f2b40c;p=thirdparty%2Fhaproxy.git MEDIUM: ist: always turn header names to lower case HTTP/2 and above require header names to be lower cased, while HTTP/1 doesn't care. By making lower case the standard way to store header names in HTX, we can significantly simplify all operations applying to header names retrieved from HTX (including, but not limited to, lookups and lower case checks which are not needed anymore). As a side effect of replacing memcpy() with ist2bin_lc(), a small increase of the request rate performance of about 0.5-1% was noticed on keep-alive traffic, very likely due to memcpy() being overkill for tiny strings. This trivial patch was marked medium because it may have a visible end-user impact (e.g. non-HTTP compliant agent, etc). --- diff --git a/src/htx.c b/src/htx.c index 5ca7b7e636..2c660e79b1 100644 --- a/src/htx.c +++ b/src/htx.c @@ -567,6 +567,7 @@ static struct htx_blk *htx_new_blk_value(struct htx *htx, struct htx_blk *blk, /* Replaces an header by a new one. The new header can be smaller or larger than * the old one. It returns the new block on success, otherwise it returns NULL. + * The header name is always lower cased. */ struct htx_blk *htx_replace_header(struct htx *htx, struct htx_blk *blk, const struct ist name, const struct ist value) @@ -582,7 +583,7 @@ struct htx_blk *htx_replace_header(struct htx *htx, struct htx_blk *blk, return NULL; blk->info = (type << 28) + (value.len << 8) + name.len; - memcpy(htx_get_blk_ptr(htx, blk), name.ptr, name.len); + ist2bin_lc(htx_get_blk_ptr(htx, blk), name); memcpy(htx_get_blk_ptr(htx, blk) + name.len, value.ptr, value.len); return blk; @@ -675,7 +676,7 @@ struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned } /* Adds an HTX block of type HDR in . It returns the new block on - * success. Otherwise, it returns NULL. + * success. Otherwise, it returns NULL. The header name is always lower cased. */ struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, const struct ist value) @@ -688,7 +689,7 @@ struct htx_blk *htx_add_header(struct htx *htx, const struct ist name, return NULL; blk->info += (value.len << 8) + name.len; - memcpy(htx_get_blk_ptr(htx, blk), name.ptr, name.len); + ist2bin_lc(htx_get_blk_ptr(htx, blk), name); memcpy(htx_get_blk_ptr(htx, blk) + name.len, value.ptr, value.len); return blk; }