couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r965703 - in /couchdb/branches/0.11.x: share/www/script/test/view_errors.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_misc_handlers.erl src/couchdb/couch_httpd_view.erl src/couchdb/couch_rep.erl
Date Tue, 20 Jul 2010 01:05:18 GMT
Author: jchris
Date: Tue Jul 20 01:05:17 2010
New Revision: 965703

URL: http://svn.apache.org/viewvc?rev=965703&view=rev
Log:
require application/json content-type in the remaining places where a POST has side-effects

Modified:
    couchdb/branches/0.11.x/share/www/script/test/view_errors.js
    couchdb/branches/0.11.x/src/couchdb/couch_httpd_db.erl
    couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl
    couchdb/branches/0.11.x/src/couchdb/couch_httpd_view.erl
    couchdb/branches/0.11.x/src/couchdb/couch_rep.erl

Modified: couchdb/branches/0.11.x/share/www/script/test/view_errors.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/view_errors.js?rev=965703&r1=965702&r2=965703&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/view_errors.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/view_errors.js Tue Jul 20 01:05:17 2010
@@ -56,14 +56,14 @@ couchTests.view_errors = function(debug)
       });
       T(JSON.parse(xhr.responseText).error == "bad_request");
 
-      // views should ignore Content-Type, like the rest of CouchDB
+      // content type must be json
       var xhr = CouchDB.request("POST", "/test_suite_db/_temp_view", {
         headers: {"Content-Type": "application/x-www-form-urlencoded"},
         body: JSON.stringify({language: "javascript",
           map : "function(doc){}"
         })
       });
-      T(xhr.status == 200);
+      T(xhr.status == 415);
 
       var map = function (doc) {emit(doc.integer, doc.integer);};
 

Modified: couchdb/branches/0.11.x/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd_db.erl?rev=965703&r1=965702&r2=965703&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_httpd_db.erl Tue Jul 20 01:05:17 2010
@@ -261,6 +261,7 @@ db_req(#httpd{path_parts=[_DbName]}=Req,
     send_method_not_allowed(Req, "DELETE,GET,HEAD,POST");
 
 db_req(#httpd{method='POST',path_parts=[_,<<"_ensure_full_commit">>]}=Req, Db)
->
+    couch_httpd:validate_ctype(Req, "application/json"),
     UpdateSeq = couch_db:get_update_seq(Db),
     CommittedSeq = couch_db:get_committed_update_seq(Db),
     {ok, StartTime} =

Modified: couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl?rev=965703&r1=965702&r2=965703&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_httpd_misc_handlers.erl Tue Jul 20 01:05:17
2010
@@ -79,6 +79,7 @@ handle_task_status_req(Req) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
 handle_replicate_req(#httpd{method='POST'}=Req) ->
+    couch_httpd:validate_ctype(Req, "application/json"),
     PostBody = couch_httpd:json_body_obj(Req),
     try couch_rep:replicate(PostBody, Req#httpd.user_ctx) of
     {ok, {continuous, RepId}} ->
@@ -102,6 +103,7 @@ handle_replicate_req(Req) ->
 
 
 handle_restart_req(#httpd{method='POST'}=Req) ->
+    couch_httpd:validate_ctype(Req, "application/json"),
     ok = couch_httpd:verify_is_server_admin(Req),
     couch_server_sup:restart_core_server(),
     send_json(Req, 200, {[{ok, true}]});
@@ -189,6 +191,7 @@ handle_config_req(Req) ->
 % httpd db handlers
 
 increment_update_seq_req(#httpd{method='POST'}=Req, Db) ->
+    couch_httpd:validate_ctype(Req, "application/json"),
     {ok, NewSeq} = couch_db:increment_update_seq(Db),
     send_json(Req, {[{ok, true},
         {update_seq, NewSeq}

Modified: couchdb/branches/0.11.x/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd_view.erl?rev=965703&r1=965702&r2=965703&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_httpd_view.erl Tue Jul 20 01:05:17 2010
@@ -59,6 +59,7 @@ handle_view_req(#httpd{method='GET',
 
 handle_view_req(#httpd{method='POST',
         path_parts=[_, _, DName, _, ViewName]}=Req, Db, _DDoc) ->
+    couch_httpd:validate_ctype(Req, "application/json"),
     {Fields} = couch_httpd:json_body_obj(Req),
     case proplists:get_value(<<"keys">>, Fields, nil) of
     nil ->
@@ -75,6 +76,7 @@ handle_view_req(Req, _Db, _DDoc) ->
     send_method_not_allowed(Req, "GET,POST,HEAD").
 
 handle_temp_view_req(#httpd{method='POST'}=Req, Db) ->
+    couch_httpd:validate_ctype(Req, "application/json"),
     ok = couch_db:check_is_admin(Db),
     couch_stats_collector:increment({httpd, temporary_view_reads}),
     {Props} = couch_httpd:json_body_obj(Req),

Modified: couchdb/branches/0.11.x/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_rep.erl?rev=965703&r1=965702&r2=965703&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_rep.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_rep.erl Tue Jul 20 01:05:17 2010
@@ -657,8 +657,9 @@ ensure_full_commit(#http_db{headers = He
     Req = Target#http_db{
         resource = "_ensure_full_commit",
         method = post,
-        headers = [{"content-type", "application/json"} | Headers]
+        headers = couch_util:proplist_apply_field({"Content-Type", "application/json"}, Headers)
     },
+    ?LOG_ERROR("Req ~p",[Req]),
     {ResultProps} = couch_rep_httpc:request(Req),
     true = proplists:get_value(<<"ok">>, ResultProps),
     proplists:get_value(<<"instance_start_time">>, ResultProps);
@@ -683,7 +684,7 @@ ensure_full_commit(#http_db{headers = He
         resource = "_ensure_full_commit",
         method = post,
         qs = [{seq, RequiredSeq}],
-        headers = [{"content-type", "application/json"} | Headers]
+        headers = couch_util:proplist_apply_field({"Content-Type", "application/json"}, Headers)
     },
     {ResultProps} = couch_rep_httpc:request(Req),
     case proplists:get_value(<<"ok">>, ResultProps) of



Mime
View raw message