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/11 16:21:00 UTC
[couchdb] branch prototype/fdb-layer updated: Fix
buffer_response=true (#3145)
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/prototype/fdb-layer by this push:
new 56e0f9c Fix buffer_response=true (#3145)
56e0f9c is described below
commit 56e0f9c936af75d4206346214cd836206f4b629a
Author: Robert Newson <rn...@apache.org>
AuthorDate: Thu Sep 10 23:00:36 2020 +0100
Fix buffer_response=true (#3145)
We need to call StartFun as it might add headers, etc.
---
src/chttpd/src/chttpd.erl | 9 +++++++--
src/chttpd/test/eunit/chttpd_delayed_test.erl | 15 +++++++--------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index fdca5c8..1a9b19b 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -875,13 +875,18 @@ 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}}) ->
diff --git a/src/chttpd/test/eunit/chttpd_delayed_test.erl b/src/chttpd/test/eunit/chttpd_delayed_test.erl
index 64232dc..63e6cb0 100644
--- a/src/chttpd/test/eunit/chttpd_delayed_test.erl
+++ b/src/chttpd/test/eunit/chttpd_delayed_test.erl
@@ -17,7 +17,7 @@
setup() ->
Hashed = couch_passwords:hash_admin_password(?PASS),
ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
- ok = config:set("chttpd", "buffer_response", "true"),
+ ok = config:set("chttpd", "buffer_response", "true", _Persist=false),
TmpDb = ?tempdb(),
Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
Port = mochiweb_socket_server:get(chttpd, port),
@@ -57,17 +57,16 @@ all_test_() ->
test_buffer_response_all_docs(Url) ->
- assert_has_content_length(Url ++ "/_all_docs").
+ assert_successful_response(Url ++ "/_all_docs").
test_buffer_response_changes(Url) ->
- assert_has_content_length(Url ++ "/_changes").
+ assert_successful_response(Url ++ "/_changes").
-assert_has_content_length(Url) ->
+assert_successful_response(Url) ->
{timeout, ?TIMEOUT, ?_test(begin
- {ok, Code, Headers, _Body} = test_request:get(Url, [?AUTH]),
- ?assertEqual(200, Code),
- ?assert(lists:keymember("Content-Length", 1, Headers))
+ {ok, Code, _Headers, _Body} = test_request:get(Url, [?AUTH]),
+ ?assertEqual(200, Code)
end)}.
-
\ No newline at end of file
+