rnewson commented on PR #6013:
URL: https://github.com/apache/couchdb/pull/6013#issuecomment-5202667215
For the `_bulk_get` side, I think we can fairly simply gzip any non-chunked
response, the replicator would just have to indicate that it can accept them
(`Accept-Encoding: gzip`).
```erlang
diff --git a/src/couch/src/couch_httpd.erl b/src/couch/src/couch_httpd.erl
index 0a9e39e7a..fd63ec444 100644
--- a/src/couch/src/couch_httpd.erl
+++ b/src/couch/src/couch_httpd.erl
@@ -1395,10 +1395,23 @@ before_response(Req0, Code0, Headers0, {json,
JsonObj}) ->
{ok, {Req1, Code1, Headers1, Body1}} =
chttpd_plugin:before_response(Req0, Code0, Headers0, JsonObj),
Body2 = [start_jsonp(), ?JSON_ENCODE(Body1), end_jsonp(), $\n],
- {ok, {Req1, Code1, Headers1, Body2}};
+ {Headers2, Body3} = maybe_compress_request_body(Req0, Headers1, Body2),
+ {ok, {Req1, Code1, Headers2, Body3}};
before_response(Req0, Code0, Headers0, Args0) ->
chttpd_plugin:before_response(Req0, Code0, Headers0, Args0).
+maybe_compress_request_body(Req, Headers, Body) ->
+ case accepts_gzip(Req) of
+ true ->
+ {[{~"Content-Encoding", ~"gzip"} | Headers],
+ zlib:gzip(Body)};
+ false ->
+ {Headers, Body}
+ end.
+
+accepts_gzip(#httpd{} = Req) ->
+ lists:member("gzip", couch_httpd:accepted_encodings(Req)).
+
respond_(#httpd{mochi_req = MochiReq} = Req, Code, Headers, Args, Type) ->
case MochiReq:get(socket) of
{remote, Pid, Ref} ->
```
--
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]