rnewson commented on code in PR #6013:
URL: https://github.com/apache/couchdb/pull/6013#discussion_r3782296789


##########
src/couch_replicator/src/couch_replicator_api_wrap.erl:
##########
@@ -1053,6 +1065,31 @@ header_value(Key, Headers, Default) ->
             Default
     end.
 
+%% Returns true if compression is enabled and body meets the minimum size 
threshold.
+should_compress_request(#httpdb{request_compression = ?COMPRESS_GZIP}, 
BodySize) ->
+    MinSize = config:get_integer("replicator", "compress_min_size", 
?COMPRESS_MIN_SIZE),
+    BodySize >= MinSize;
+should_compress_request(#httpdb{}, _BodySize) ->
+    false.
+
+%% Compress Body with gzip, prepend Content-Length and Content-Encoding 
headers.
+%% Returns {CompressedBody, Headers}.
+gzip_request_body(Body, Headers) ->
+    Compressed = zlib:gzip(Body),
+    Len = byte_size(Compressed),
+    couch_stats:increment_counter([couch_replicator, requests_compressed, 
gzip]),
+    {Compressed, [{"Content-Length", Len}, {"Content-Encoding", "gzip"} | 
Headers]}.

Review Comment:
   It should not be necessary to calculate the content-length header ourselves 
nor set the header. 



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