You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2015/07/22 20:33:39 UTC

[2/2] chttpd commit: updated refs/heads/2724-chunked-buffering to 11166b9

Match old behavior when buffering is disabled

If the threshold is set to zero we make sure to send a separate chunk to
close the JSON, otherwise we just merge it into the previous chunk.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/11166b97
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/11166b97
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/11166b97

Branch: refs/heads/2724-chunked-buffering
Commit: 11166b9774a90efc60a4eaa2c9f913b53ad0773f
Parents: 9102795
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Jul 22 14:14:48 2015 -0400
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Wed Jul 22 14:32:50 2015 -0400

----------------------------------------------------------------------
 src/chttpd.erl    | 11 ++++++++++-
 src/chttpd_db.erl | 19 +++++++++----------
 2 files changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/11166b97/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index c51a463..f5c0282 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -35,7 +35,8 @@
     get_delayed_req/1]).
 
 -export([
-    chunked_response_buffer_size/0
+    chunked_response_buffer_size/0,
+    close_delayed_json_object/4
 ]).
 
 -record(delayed_resp, {
@@ -728,6 +729,14 @@ send_delayed_error(#delayed_resp{resp=Resp}, Reason) ->
     log_error_with_stack_trace(Reason),
     throw({http_abort, Resp, Reason}).
 
+close_delayed_json_object(Resp, Buffer, Terminator, 0) ->
+    % Use a separate chunk to close the streamed array to maintain strict
+    % compatibility with earlier versions. See COUCHDB-2724
+    {ok, R1} = chttpd:send_delayed_chunk(Resp, Buffer),
+    send_delayed_chunk(R1, Terminator);
+close_delayed_json_object(Resp, Buffer, Terminator, _Threshold) ->
+    send_delayed_chunk(Resp, [Buffer | Terminator]).
+
 end_delayed_json_response(#delayed_resp{}=DelayedResp) ->
     {ok, #delayed_resp{resp=Resp}} =
         start_delayed_response(DelayedResp),

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/11166b97/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index b4b4a83..735480c 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -183,16 +183,15 @@ changes_callback({change, Change}, Acc) ->
     Len = iolist_size(Data),
     maybe_flush_changes_feed(Acc, Data, Len);
 changes_callback({stop, EndSeq, Pending}, Acc) ->
-    #cacc{buffer = Buf, mochi = Resp} = Acc,
-    {ok, Resp1} = chttpd:send_delayed_chunk(Resp, [
-            Buf,
-            "\n],\n\"last_seq\":",
-            ?JSON_ENCODE(EndSeq),
-            ",\"pending\":",
-            ?JSON_ENCODE(Pending),
-            "}\n"
-        ])
-    end,
+    #cacc{buffer = Buf, mochi = Resp, threshold = Max} = Acc,
+    Terminator = [
+        "\n],\n\"last_seq\":",
+        ?JSON_ENCODE(EndSeq),
+        ",\"pending\":",
+        ?JSON_ENCODE(Pending),
+        "}\n"
+    ],
+    {ok, Resp1} = chttpd:close_delayed_json_object(Resp, Buf, Terminator, Max),
     chttpd:end_delayed_json_response(Resp1);
 
 changes_callback(waiting_for_updates, Acc) ->