membphis commented on code in PR #14252:
URL: https://github.com/apache/apisix/pull/14252#discussion_r4676337238


##########
apisix/plugins/brotli.lua:
##########
@@ -241,10 +231,14 @@ function _M.header_filter(conf, ctx)
         core.response.add_header("Vary", "Accept-Encoding")
     end
 
-    local compressor = create_brotli_compressor(conf.mode, conf.comp_level,
-                                                conf.lgwin, conf.lgblock)
+    local compressor, err = lib.new_encoder({
+        mode = conf.mode,
+        quality = conf.comp_level,
+        lgwin = conf.lgwin,

Review Comment:
   **[P2] Preserve the effective window for `lgwin=0`**
   
   Using the same native Brotli library, I verified that an explicit `0` 
produced the same output as `lgwin=10` with the previous binding. 
`lua-resty-brotli 0.1.0-1` skips setting the parameter for `0`, and the 
resulting stream uses the native default of `22`. Existing routes with 
`lgwin=0` move from a window of about 1 KiB to about 4 MiB, which can change 
the resource cost of compressing long responses.
   
   Please preserve the previous effective value for explicit `0` and add a 
compatibility test. If the window change is intentional, document it and 
measure its impact on long responses.



##########
apisix/plugins/response-rewrite.lua:
##########
@@ -272,11 +272,13 @@ function _M.body_filter(conf, ctx)
 
         local err
         if ctx.response_encoding ~= nil and body ~= "" then
-            local decoder = 
content_decode.dispatch_decoder(ctx.response_encoding)
+            local decoder, unavailable = 
content_decode.dispatch_decoder(ctx.response_encoding)
             if not decoder then
-                core.log.error("filters may not work as expected ",
-                               "due to unsupported compression encoding type: 
",
-                               ctx.response_encoding)
+                if not unavailable then

Review Comment:
   **[P2] Handle a missing Brotli decoder before modifying the response**
   
   The header filter has already removed `Content-Encoding` when this branch 
runs, and the body filter has already withheld earlier chunks. In a Lua-level 
check with simulated Nginx input, a valid two-chunk Brotli response with a 
missing decoder produced HTTP 200 with only 10 of the original 16 bytes and no 
encoding header. This happened on both the base and the new revision. The new 
revision reported the error on only the first of two requests from the same 
worker.
   
   Please check decoder availability before clearing headers or buffering the 
response. Preserve the original bytes and encoding when the route allows 
passthrough, or return an explicit error. Add a regression test for repeated 
requests to the same worker.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to