summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/couchdb/couch_httpd_db.erl17
-rwxr-xr-xtest/etap/140-attachment-comp.t12
2 files changed, 13 insertions, 16 deletions
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 2ef2fe4f..7362c979 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -580,7 +580,7 @@ db_doc_req(#httpd{method='DELETE'}=Req, Db, DocId) ->
{[{<<"_rev">>, ?l2b(Rev)},{<<"_deleted">>,true}]}))
end;
-db_doc_req(#httpd{method='GET'}=Req, Db, DocId) ->
+db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
#doc_query_args{
rev = Rev,
open_revs = Revs,
@@ -599,11 +599,7 @@ db_doc_req(#httpd{method='GET'}=Req, Db, DocId) ->
send_doc(Req, Doc, Options);
_ ->
{ok, Results} = couch_db:open_doc_revs(Db, DocId, Revs, Options),
- AcceptedTypes = case couch_httpd:header_value(Req, "Accept") of
- undefined -> [];
- AcceptHeader -> string:tokens(AcceptHeader, ", ")
- end,
- case lists:member("multipart/mixed", AcceptedTypes) of
+ case MochiReq:accepts_content_type("multipart/mixed") of
false ->
{ok, Resp} = start_json_response(Req, 200),
send_chunk(Resp, "["),
@@ -745,14 +741,11 @@ send_doc(Req, Doc, Options) ->
send_doc_efficiently(Req, #doc{atts=[]}=Doc, Headers, Options) ->
send_json(Req, 200, Headers, couch_doc:to_json_obj(Doc, Options));
-send_doc_efficiently(Req, #doc{atts=Atts}=Doc, Headers, Options) ->
+send_doc_efficiently(#httpd{mochi_req = MochiReq} = Req,
+ #doc{atts = Atts} = Doc, Headers, Options) ->
case lists:member(attachments, Options) of
true ->
- AcceptedTypes = case couch_httpd:header_value(Req, "Accept") of
- undefined -> [];
- AcceptHeader -> string:tokens(AcceptHeader, ", ")
- end,
- case lists:member("multipart/related", AcceptedTypes) of
+ case MochiReq:accepts_content_type("multipart/related") of
false ->
send_json(Req, 200, Headers, couch_doc:to_json_obj(Doc, Options));
true ->
diff --git a/test/etap/140-attachment-comp.t b/test/etap/140-attachment-comp.t
index 98d37abc..1a90bf0b 100755
--- a/test/etap/140-attachment-comp.t
+++ b/test/etap/140-attachment-comp.t
@@ -301,7 +301,8 @@ test_get_1st_png_att_with_accept_encoding_deflate() ->
test_get_doc_with_1st_text_att() ->
{ok, {{_, Code, _}, _Headers, Body}} = http:request(
get,
- {db_url() ++ "/testdoc1?attachments=true", []},
+ {db_url() ++ "/testdoc1?attachments=true",
+ [{"Accept", "application/json"}]},
[],
[{sync, true}]),
etap:is(Code, 200, "HTTP response code is 200"),
@@ -367,7 +368,8 @@ test_1st_text_att_stub() ->
test_get_doc_with_1st_png_att() ->
{ok, {{_, Code, _}, _Headers, Body}} = http:request(
get,
- {db_url() ++ "/testdoc2?attachments=true", []},
+ {db_url() ++ "/testdoc2?attachments=true",
+ [{"Accept", "application/json"}]},
[],
[{sync, true}]),
etap:is(Code, 200, "HTTP response code is 200"),
@@ -492,7 +494,8 @@ test_get_2nd_png_att_with_accept_encoding_gzip() ->
test_get_doc_with_2nd_text_att() ->
{ok, {{_, Code, _}, _Headers, Body}} = http:request(
get,
- {db_url() ++ "/testdoc3?attachments=true", []},
+ {db_url() ++ "/testdoc3?attachments=true",
+ [{"Accept", "application/json"}]},
[],
[{sync, true}]),
etap:is(Code, 200, "HTTP response code is 200"),
@@ -554,7 +557,8 @@ test_2nd_text_att_stub() ->
test_get_doc_with_2nd_png_att() ->
{ok, {{_, Code, _}, _Headers, Body}} = http:request(
get,
- {db_url() ++ "/testdoc4?attachments=true", []},
+ {db_url() ++ "/testdoc4?attachments=true",
+ [{"Accept", "application/json"}]},
[],
[{sync, true}]),
etap:is(Code, 200, "HTTP response code is 200"),