nickva commented on code in PR #6122:
URL: https://github.com/apache/couchdb/pull/6122#discussion_r4450831301


##########
src/couch/src/couch_httpd.erl:
##########
@@ -1442,9 +1447,30 @@ http_respond_(#httpd{mochi_req = MochiReq}, 413, 
Headers, Args, Type) ->
     Socket = MochiReq:get(socket),
     mochiweb_socket:recv(Socket, ?MAX_DRAIN_BYTES, ?MAX_DRAIN_TIME_MSEC),
     Result;
+http_respond_(#httpd{mochi_req = MochiReq} = Req, Code, Headers, Args, 
respond) when
+    is_binary(Args) orelse is_list(Args)
+->
+    case should_compress(Req) of

Review Comment:
   One this to worry about here is what happens if we compress an empty body. 
If send a 304 or 204 we shouldn't send any body. In some cases we send `<<>>` 
with ` chttpd:send_response_no_cors(Req, 204, PreflightHeaders, <<>>)` (maybe 
other cases) and then we'd compress to something non-empty with a body in the 
output and maybe we shouldn't.
   
   To be safe maybe we should add a minimum on body size we'd compress and if 
it's 0 we definitely don't. Not sure if a config value is better or just hard 
code it at 256 or 1024 bytes maybe...
   
   ```
   should_compress(Req, Body) ->
       should_compress(Req) andalso compressible_size(iolist_size(Body)).
   
   compressible_size(0) ->
       false;
   compressible_size(Size) ->
       Size >= chttpd_util:get_chttpd_config_integer("compress_min_size", 1024).
   ```
   



-- 
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