You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2020/09/10 19:06:54 UTC

[couchdb] 01/01: Fix buffer_response=true

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch fix-buffer-response-true
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 5965b1a865321895758f88daef10f1d4bba98be1
Author: Robert Newson <rn...@apache.org>
AuthorDate: Thu Sep 10 20:06:15 2020 +0100

    Fix buffer_response=true
    
    We need to call StartFun as it might add headers, etc.
---
 src/chttpd/src/chttpd.erl | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index fb7d61a..216b0a9 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -855,13 +855,19 @@ end_delayed_json_response(#delayed_resp{buffer_response=false}=DelayedResp) ->
 
 end_delayed_json_response(#delayed_resp{buffer_response=true}=DelayedResp) ->
     #delayed_resp{
+        start_fun = StartFun,
         req = Req,
         code = Code,
         headers = Headers,
         chunks = Chunks
     } = DelayedResp,
-    {ok, Resp} = start_response_length(Req, Code, Headers, iolist_size(Chunks)),
-    send(Resp, lists:reverse(Chunks)).
+    {ok, Resp} = StartFun(Req, Code, Headers),
+    lists:foreach(
+        fun
+            ("") -> ok;
+            (Chunk) -> send_chunk(Resp, Chunk)
+        end, lists:reverse(Chunks)),
+    end_json_response(Resp).
 
 
 get_delayed_req(#delayed_resp{req=#httpd{mochi_req=MochiReq}}) ->