|
| 1 | +diff --git src/http/modules/ngx_http_gzip_filter_module.c src/http/modules/ngx_http_gzip_filter_module.c |
| 2 | +index c75169c..35b8433 100644 |
| 3 | +--- src/http/modules/ngx_http_gzip_filter_module.c |
| 4 | ++++ src/http/modules/ngx_http_gzip_filter_module.c |
| 5 | +@@ -8,6 +8,9 @@ |
| 6 | + #include <ngx_config.h> |
| 7 | + #include <ngx_core.h> |
| 8 | + #include <ngx_http.h> |
| 9 | ++#if (NGX_HTTP_APISIX) |
| 10 | ++#include <ngx_http_apisix_module.h> |
| 11 | ++#endif |
| 12 | + |
| 13 | + #include <zlib.h> |
| 14 | + |
| 15 | +@@ -225,6 +228,26 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r) |
| 16 | + |
| 17 | + conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); |
| 18 | + |
| 19 | ++#if (NGX_HTTP_APISIX) |
| 20 | ++ if ((r->headers_out.status != NGX_HTTP_OK |
| 21 | ++ && r->headers_out.status != NGX_HTTP_FORBIDDEN |
| 22 | ++ && r->headers_out.status != NGX_HTTP_NOT_FOUND) |
| 23 | ++ || (r->headers_out.content_encoding |
| 24 | ++ && r->headers_out.content_encoding->value.len) |
| 25 | ++ || r->header_only) |
| 26 | ++ { |
| 27 | ++ return ngx_http_next_header_filter(r); |
| 28 | ++ } |
| 29 | ++ |
| 30 | ++ if (!ngx_http_apisix_is_gzip_set(r) |
| 31 | ++ && (!conf->enable |
| 32 | ++ || (r->headers_out.content_length_n != -1 |
| 33 | ++ && r->headers_out.content_length_n < conf->min_length) |
| 34 | ++ || ngx_http_test_content_type(r, &conf->types) == NULL)) |
| 35 | ++ { |
| 36 | ++ return ngx_http_next_header_filter(r); |
| 37 | ++ } |
| 38 | ++#else |
| 39 | + if (!conf->enable |
| 40 | + || (r->headers_out.status != NGX_HTTP_OK |
| 41 | + && r->headers_out.status != NGX_HTTP_FORBIDDEN |
| 42 | +@@ -238,6 +261,7 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r) |
| 43 | + { |
| 44 | + return ngx_http_next_header_filter(r); |
| 45 | + } |
| 46 | ++#endif |
| 47 | + |
| 48 | + r->gzip_vary = 1; |
| 49 | + |
| 50 | +@@ -515,7 +539,18 @@ ngx_http_gzip_filter_memory(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx) |
| 51 | + * 16-byte padding in one out of the two window-sized buffers. |
| 52 | + */ |
| 53 | + |
| 54 | ++#if (NGX_HTTP_APISIX) |
| 55 | ++ ngx_int_t level; |
| 56 | ++ |
| 57 | ++ level = ngx_http_apisix_get_gzip_compress_level(r); |
| 58 | ++ if (level == NGX_DECLINED) { |
| 59 | ++ level = conf->level; |
| 60 | ++ } |
| 61 | ++ |
| 62 | ++ if (level == 1) { |
| 63 | ++#else |
| 64 | + if (conf->level == 1) { |
| 65 | ++#endif |
| 66 | + wbits = ngx_max(wbits, 13); |
| 67 | + } |
| 68 | + |
| 69 | +@@ -615,6 +650,21 @@ ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r, |
| 70 | + ctx->zstream.zfree = ngx_http_gzip_filter_free; |
| 71 | + ctx->zstream.opaque = ctx; |
| 72 | + |
| 73 | ++#if (NGX_HTTP_APISIX) |
| 74 | ++ ngx_int_t level; |
| 75 | ++ |
| 76 | ++ level = ngx_http_apisix_get_gzip_compress_level(r); |
| 77 | ++ if (level == NGX_DECLINED) { |
| 78 | ++ level = conf->level; |
| 79 | ++ } |
| 80 | ++ |
| 81 | ++ rc = deflateInit2(&ctx->zstream, (int) level, Z_DEFLATED, |
| 82 | ++ ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY); |
| 83 | ++#else |
| 84 | ++ rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, |
| 85 | ++ ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY); |
| 86 | ++#endif |
| 87 | ++ |
| 88 | + rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, |
| 89 | + ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY); |
| 90 | + |
| 91 | +@@ -705,6 +755,16 @@ ngx_http_gzip_filter_get_buf(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx) |
| 92 | + |
| 93 | + conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); |
| 94 | + |
| 95 | ++#if (NGX_HTTP_APISIX) |
| 96 | ++ ngx_int_t num; |
| 97 | ++ size_t size; |
| 98 | ++ |
| 99 | ++ if (ngx_http_apisix_get_gzip_buffer_conf(r, &num, &size) == NGX_DECLINED) { |
| 100 | ++ num = conf->bufs.num; |
| 101 | ++ size = conf->bufs.size; |
| 102 | ++ } |
| 103 | ++#endif |
| 104 | ++ |
| 105 | + if (ctx->free) { |
| 106 | + |
| 107 | + cl = ctx->free; |
| 108 | +@@ -713,9 +773,15 @@ ngx_http_gzip_filter_get_buf(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx) |
| 109 | + |
| 110 | + ngx_free_chain(r->pool, cl); |
| 111 | + |
| 112 | ++#if (NGX_HTTP_APISIX) |
| 113 | ++ } else if (ctx->bufs < num) { |
| 114 | ++ |
| 115 | ++ ctx->out_buf = ngx_create_temp_buf(r->pool, size); |
| 116 | ++#else |
| 117 | + } else if (ctx->bufs < conf->bufs.num) { |
| 118 | + |
| 119 | + ctx->out_buf = ngx_create_temp_buf(r->pool, conf->bufs.size); |
| 120 | ++#endif |
| 121 | + if (ctx->out_buf == NULL) { |
| 122 | + return NGX_ERROR; |
| 123 | + } |
| 124 | +diff --git src/http/ngx_http_core_module.c src/http/ngx_http_core_module.c |
| 125 | +index b900467..160e512 100644 |
| 126 | +--- src/http/ngx_http_core_module.c |
| 127 | ++++ src/http/ngx_http_core_module.c |
| 128 | +@@ -2065,9 +2065,16 @@ ngx_http_gzip_ok(ngx_http_request_t *r) |
| 129 | + return NGX_DECLINED; |
| 130 | + } |
| 131 | + |
| 132 | ++#if (NGX_HTTP_APISIX) |
| 133 | ++ if (!ngx_http_apisix_is_gzip_set(r) |
| 134 | ++ && r->http_version < clcf->gzip_http_version) { |
| 135 | ++ return NGX_DECLINED; |
| 136 | ++ } |
| 137 | ++#else |
| 138 | + if (r->http_version < clcf->gzip_http_version) { |
| 139 | + return NGX_DECLINED; |
| 140 | + } |
| 141 | ++#endif |
| 142 | + |
| 143 | + if (r->headers_in.via == NULL) { |
| 144 | + goto ok; |
0 commit comments