summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2020-09-10 23:00:36 +0100
committerGitHub <noreply@github.com>2020-09-10 23:00:36 +0100
commit1c6a7386f1204d4af38816034ef9e971b5ff19af (patch)
tree5e8da14837c4396387369235e3c7ecb67887038a
parenta94e693f32672e4613bce0d80d0b9660f85275ea (diff)
downloadcouchdb-1c6a7386f1204d4af38816034ef9e971b5ff19af.tar.gz
Fix buffer_response=true (#3145)
We need to call StartFun as it might add headers, etc.
-rw-r--r--src/chttpd/src/chttpd.erl9
-rw-r--r--src/chttpd/test/eunit/chttpd_delayed_test.erl15
2 files changed, 14 insertions, 10 deletions
diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index fb7d61a06..3962c8601 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -855,13 +855,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 64232dcf8..63e6cb0e5 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
+