summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/nxt_http_compress.c33
-rw-r--r--src/nxt_http_compress.h4
-rw-r--r--src/nxt_http_compress_gzip.c11
3 files changed, 48 insertions, 0 deletions
diff --git a/src/nxt_http_compress.c b/src/nxt_http_compress.c
index b7c4c08d..980ed0bc 100644
--- a/src/nxt_http_compress.c
+++ b/src/nxt_http_compress.c
@@ -21,6 +21,7 @@
#include "nxt_mp.h"
#include "nxt_router.h"
#include "nxt_string.h"
+#include "nxt_tstr.h"
#include "nxt_types.h"
@@ -59,6 +60,8 @@ nxt_http_compress_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
nxt_int_t ret;
nxt_http_compress_conf_t *conf;
+ static nxt_str_t hdr_a_e = nxt_string("$header_accept_encoding");
+
mp = rtcf->mem_pool;
conf = nxt_mp_zget(mp, sizeof(nxt_http_compress_conf_t));
@@ -82,6 +85,11 @@ nxt_http_compress_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
}
}
+ conf->accept_encoding = nxt_tstr_compile(rtcf->tstr_state, &hdr_a_e, 0);
+ if (nxt_slow_path(conf->accept_encoding == NULL)) {
+ return NXT_ERROR;
+ }
+
if (NXT_WITH_ZLIB && nxt_str_eq(&conf->encoding, "gzip", strlen("gzip"))) {
conf->handler = nxt_http_compress_gzip;
@@ -147,6 +155,31 @@ nxt_http_compress_resp_content_length(nxt_http_response_t *resp)
nxt_int_t
+nxt_http_compress_accept_encoding(nxt_task_t *task, nxt_http_request_t *r,
+ nxt_tstr_t *accept_encoding, nxt_str_t *encoding)
+{
+ nxt_int_t ret;
+ nxt_str_t str;
+ nxt_router_conf_t *rtcf;
+
+ rtcf = r->conf->socket_conf->router_conf;
+
+ ret = nxt_tstr_query_init(&r->tstr_query, rtcf->tstr_state, &r->tstr_cache,
+ r, r->mem_pool);
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return NXT_ERROR;
+ }
+
+ nxt_tstr_query(task, r->tstr_query, accept_encoding, &str);
+ if (nxt_slow_path(nxt_tstr_query_failed(r->tstr_query))) {
+ return NXT_ERROR;
+ }
+
+ return nxt_strstr_eq(&str, encoding);
+}
+
+
+nxt_int_t
nxt_http_compressible_mtype(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_route_rule_t *mtrule)
{
diff --git a/src/nxt_http_compress.h b/src/nxt_http_compress.h
index 1d671bf9..27b8b1c3 100644
--- a/src/nxt_http_compress.h
+++ b/src/nxt_http_compress.h
@@ -16,6 +16,7 @@
#include "nxt_main.h"
#include "nxt_router.h"
#include "nxt_string.h"
+#include "nxt_tstr.h"
#include "nxt_types.h"
@@ -28,6 +29,7 @@ struct nxt_http_compress_conf_s {
int8_t level;
size_t min_len;
+ nxt_tstr_t *accept_encoding;
nxt_conf_value_t *mtypes;
nxt_http_route_rule_t *mtrule;
};
@@ -37,6 +39,8 @@ nxt_int_t nxt_http_compress_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
nxt_http_action_t *action, nxt_http_action_conf_t *acf);
ssize_t nxt_http_compress_resp_content_length(nxt_http_response_t *resp);
+nxt_int_t nxt_http_compress_accept_encoding(nxt_task_t *task,
+ nxt_http_request_t *r, nxt_tstr_t *accept_encoding, nxt_str_t *encoding);
nxt_int_t nxt_http_compressible_mtype(nxt_task_t *task, nxt_http_request_t *r,
nxt_http_route_rule_t *mtrule);
nxt_int_t nxt_http_compress_append_field(nxt_task_t *task,
diff --git a/src/nxt_http_compress_gzip.c b/src/nxt_http_compress_gzip.c
index c1ff962b..f8d88bf8 100644
--- a/src/nxt_http_compress_gzip.c
+++ b/src/nxt_http_compress_gzip.c
@@ -66,6 +66,17 @@ nxt_http_compress_gzip(nxt_task_t *task, nxt_http_request_t *r,
return NXT_OK;
}
+ ret = nxt_http_compress_accept_encoding(task, r, conf->accept_encoding,
+ &gzip);
+ switch (ret) {
+ case NXT_ERROR:
+ return NXT_ERROR;
+ case 0:
+ return NXT_OK;
+ case 1:
+ break;
+ }
+
ret = nxt_http_compressible_mtype(task, r, conf->mtrule);
switch (ret) {
case NXT_ERROR: