Hi,
The attached patchset is a first attempt at adding the possibility to
compress requests, as well as responses.
It adds a new keyword for compression, "tocompress" (any better
alternative name would be appreciated). The valid values are "request",
if you want to compress requests, "response" if you want to compress
responses or "both", if you want to compress both.
The default is to compress responses only.
Any comment is more than welcome.
Thanks!
Olivier
>From 6c3e62baa888359521091387ce6ac8376a001259 Mon Sep 17 00:00:00 2001
From: Olivier Houchard
Date: Mon, 3 Apr 2023 22:22:24 +0200
Subject: [PATCH 1/2] MINOR: compression: Make compression offload a flag
Turn compression offload into a flag in struct comp, instead of using
an int just for it.
---
include/haproxy/compression-t.h | 5 -
src/flt_http_comp.c | 6 +++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/include/haproxy/compression-t.h b/include/haproxy/compression-t.h
index 062f17f76..cdbf0d14e 100644
--- a/include/haproxy/compression-t.h
+++ b/include/haproxy/compression-t.h
@@ -34,10 +34,13 @@
#include
+/* Compression flags */
+
+#define COMP_FL_OFFLOAD 0x0001 /* Compression offload */
struct comp {
struct comp_algo *algos;
struct comp_type *types;
- unsigned int offload;
+ unsigned int flags;
};
struct comp_ctx {
diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c
index ceda3fd5e..507009692 100644
--- a/src/flt_http_comp.c
+++ b/src/flt_http_comp.c
@@ -451,8 +451,8 @@ select_compression_request_header(struct comp_state *st, struct stream *s, struc
/* remove all occurrences of the header when "compression offload" is set */
if (st->comp_algo) {
- if ((s->be->comp && s->be->comp->offload) ||
- (strm_fe(s)->comp && strm_fe(s)->comp->offload)) {
+ if ((s->be->comp && (s->be->comp->flags & COMP_FL_OFFLOAD)) ||
+ (strm_fe(s)->comp && (strm_fe(s)->comp->flags & COMP_FL_OFFLOAD))) {
http_remove_header(htx, );
ctx.blk = NULL;
while (http_find_header(htx, ist("Accept-Encoding"), , 1))
@@ -690,7 +690,7 @@ parse_compression_options(char **args, int section, struct proxy *proxy,
args[0], args[1]);
ret = 1;
}
- comp->offload = 1;
+ comp->flags |= COMP_FL_OFFLOAD;
}
else if (strcmp(args[1], "type") == 0) {
int cur_arg = 2;
--
2.39.1
>From 77a5657592338db2ed53189c50828b3c0ed52716 Mon Sep 17 00:00:00 2001
From: Olivier Houchard
Date: Tue, 4 Apr 2023 00:14:36 +0200
Subject: [PATCH 2/2] MEDIUM: compression: allow to compress requests too.
Make it so we can compress requests, as well as responses.
A new compress keyword is added, "tocompress". It takes exactly one
argument. The valid values for that arguments are "response", if we want
to compress only responses, "request", if we want to compress only
requests, or "both", if we want to compress both.
The dafault value is "response".
---
doc/configuration.txt | 12 ++-
include/haproxy/compression-t.h | 3 +
src/flt_http_comp.c | 165 +++-
3 files changed, 154 insertions(+), 26 deletions(-)
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 586689ca2..8f86b285e 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -5077,7 +5077,7 @@ compression type ...
compression algo gzip
compression type text/html text/plain
- See also : "compression offload"
+ See also : "compression offload", "compression tocompress"
compression offload
Makes HAProxy work as a compression offloader only.
@@ -5099,7 +5099,15 @@ compression offload
If this setting is used in a defaults section, a warning is emitted and the
option is ignored.
- See also : "compression type", "compression algo"
+ See also : "compression type", "compression algo", "compression tocompress"
+
+compression tocompress
+ Makes haproxy able to compress both requests and responses.
+ Valid values are "request", to compress only requests, "response", to
+ compress only responses, or "both", when you want to compress both.
+ The default value is "response".
+
+ See also : "compression type", "compression algo", "compression offload"
cookie [ rewrite | insert | prefix ] [ indirect ] [ nocache ]
[ postonly ] [ preserve ] [ httponly ] [ secure ]
diff --git a/include/haproxy/compression-t.h b/include/haproxy/compression-t.h
index cdbf0d14e..d15d15ee3 100644
--- a/include/haproxy/compression-t.h
+++ b/include/haproxy/compression-t.h
@@ -37,6 +37,9 @@
/* Compression flags */
#define COMP_FL_OFFLOAD 0x0001 /* Compression offload */
+#define COMP_FL_COMPRESS_REQ 0x0002 /* Compress requests */
+#define COMP_FL_COMPRESS_RES 0x0004 /* Compress responses */
+
struct comp {
struct comp_algo *algos;
struct comp_type *types;
diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c
index 507009692..7680e241f 100644
--- a/src/flt_http_comp.c
+++ b/src/flt_http_comp.c
@@ -33,7 +33,9 @@ struct flt_ops