couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1034554 - in /couchdb/trunk: src/couchdb/couch_httpd_db.erl test/etap/140-attachment-comp.t
Date Fri, 12 Nov 2010 20:17:04 GMT
Author: fdmanana
Date: Fri Nov 12 20:17:03 2010
New Revision: 1034554

URL: http://svn.apache.org/viewvc?rev=1034554&view=rev
Log:
Proper verification of the request's accepted media types. Uses the new function mochiweb_request:accepts_content_type/1.

Modified:
    couchdb/trunk/src/couchdb/couch_httpd_db.erl
    couchdb/trunk/test/etap/140-attachment-comp.t

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=1034554&r1=1034553&r2=1034554&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Nov 12 20:17:03 2010
@@ -580,7 +580,7 @@ db_doc_req(#httpd{method='DELETE'}=Req, 
                     {[{<<"_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,
         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 ->

Modified: couchdb/trunk/test/etap/140-attachment-comp.t
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/140-attachment-comp.t?rev=1034554&r1=1034553&r2=1034554&view=diff
==============================================================================
--- couchdb/trunk/test/etap/140-attachment-comp.t (original)
+++ couchdb/trunk/test/etap/140-attachment-comp.t Fri Nov 12 20:17:03 2010
@@ -301,7 +301,8 @@ test_get_1st_png_att_with_accept_encodin
 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_encodin
 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"),



Mime
View raw message