nickva commented on code in PR #6013:
URL: https://github.com/apache/couchdb/pull/6013#discussion_r3785002222
##########
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:
Oh you're right @rnewson! So before we had to supply a Len because we always
used a BodyFun (a callback) and the client didn't know what the length was if
we feed it an iolist then it can compute it itself. Good catch!
--
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]