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 23:01:23 UTC

[2/7] chttpd commit: updated refs/heads/2724-chunked-buffering to 45bb534

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/45bb5343
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/45bb5343
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/45bb5343

Branch: refs/heads/2724-chunked-buffering
Commit: 45bb534361d5f6d4deff88fc3a5a621cb01156f1
Parents: 4278115
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 16:57:49 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/45bb5343/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 28e15b6..1cbbd04 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/45bb5343/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) ->