couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r727973 - in /couchdb/trunk: etc/couchdb/default.ini.tpl.in share/www/script/couch_tests.js src/couchdb/couch_httpd_external.erl
Date Fri, 19 Dec 2008 08:25:19 GMT
Author: jchris
Date: Fri Dec 19 00:25:19 2008
New Revision: 727973

URL: http://svn.apache.org/viewvc?rev=727973&view=rev
Log:
shorter path to _action servers, external supports better routing control

Modified:
    couchdb/trunk/etc/couchdb/default.ini.tpl.in
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/src/couchdb/couch_httpd_external.erl

Modified: couchdb/trunk/etc/couchdb/default.ini.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/trunk/etc/couchdb/default.ini.tpl.in?rev=727973&r1=727972&r2=727973&view=diff
==============================================================================
--- couchdb/trunk/etc/couchdb/default.ini.tpl.in (original)
+++ couchdb/trunk/etc/couchdb/default.ini.tpl.in Fri Dec 19 00:25:19 2008
@@ -45,4 +45,10 @@
 [httpd_db_handlers]
 _view = {couch_httpd_view, handle_view_req}
 _temp_view = {couch_httpd_view, handle_temp_view_req}
-_external = {couch_httpd_external, handle_external_req}
+; The new location for action servers
+_action = {couch_httpd_external, handle_external_req, <<"action">>}
+; They'd been here for a while. If something you've been running breaks on you
+; try adding the next line to your local.ini. Or better yet replace
+; '_external/action' in your urls with '_action'.
+; This message will be removed before the next release.
+; _external = {couch_httpd_external, handle_external_req}

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=727973&r1=727972&r2=727973&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Fri Dec 19 00:25:19 2008
@@ -2054,48 +2054,45 @@
     // Make sure we don't succeed on something that shouldn't
     xhr = CouchDB.request("GET", "/test_suite_db/_external");
     T(xhr.status == 404);
-    T(JSON.parse(xhr.responseText).reason == "No server name specified.");
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/bannana");
+    T(JSON.parse(xhr.responseText).reason == "missing");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action");
     T(xhr.status == 404);
-    T(JSON.parse(xhr.responseText).reason == "No server configured for \"bannana\".");
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action");
-    T(xhr.status == 404);
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/no_actions");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/no_actions");
     T(xhr.status == 404)
     T(JSON.parse(xhr.responseText).reason == "Invalid path: \"no_actions\".");;
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/no_actions/foo");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/no_actions/foo");
     T(xhr.status == 500);
     T(/^No actions found/.test(JSON.parse(xhr.responseText).reason));
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/an_action/invalid");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/an_action/invalid");
     T(xhr.status == 500);
     T(/^No action \'invalid\'/.test(JSON.parse(xhr.responseText).reason));
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/errors/syntax");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/errors/syntax");
     T(xhr.status == 500);
     T(/^Failed to compile/.test(JSON.parse(xhr.responseText).reason));
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/errors/except");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/errors/except");
     T(/Failed to execute/.test(JSON.parse(xhr.responseText).reason));
 
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/an_action/times_two");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/an_action/times_two");
     T(xhr.status == 200);
     T(JSON.parse(xhr.responseText).val == null);
 
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/an_action/bad_return");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/an_action/bad_return");
     T(xhr.status == 500);
     T(/^Invalid data from external server/.test(JSON.parse(xhr.responseText).reason));
 
 
     // test that we invoke the action server
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/an_action/times_two?q=3");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/an_action/times_two?q=3");
     T(xhr.status == 200);
     T(JSON.parse(xhr.responseText).val == 6);
     
     // Test that we can return raw text
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/an_action/html");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/an_action/html");
     T(xhr.status == 200);
     T(xhr.responseText == '<p>Lorem ipsum...</p>');
     
     // Test environment
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/an_action/request_object?couchdb=relax");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/an_action/request_object?couchdb=relax");
     T(xhr.status == 200);
     var req = JSON.parse(xhr.responseText);
 
@@ -2107,7 +2104,7 @@
     T(req.path[1] == "request_object");
     T(req.query.couchdb == "relax");
 
-    xhr = CouchDB.request("POST", "/test_suite_db/_external/action/an_action/request_object?couchdb=relax",{
+    xhr = CouchDB.request("POST", "/test_suite_db/_action/an_action/request_object?couchdb=relax",{
       "body" : "some=text",
       "headers" : {
         "Content-Type" : "application/x-www-form-urlencoded"
@@ -2129,11 +2126,11 @@
     T(req.form.some == "text");
 
     // we can send error codes back
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/an_action/requires_put");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/an_action/requires_put");
     T(xhr.status == 405);
     T(xhr.responseText == "Method Not Allowed, Punk!");
     
-    xhr = CouchDB.request("PUT", "/test_suite_db/_external/action/an_action/requires_put");
+    xhr = CouchDB.request("PUT", "/test_suite_db/_action/an_action/requires_put");
     T(xhr.status == 200);
     T(xhr.responseText == "thanks for the PUT");
   },
@@ -2162,23 +2159,23 @@
     // test GET
     var doc = {foo:"bar"};
     var result = db.save(doc);
-    var xhr = CouchDB.request("GET", "/test_suite_db/_external/action/verbs/get?docid="+result.id);
+    var xhr = CouchDB.request("GET", "/test_suite_db/_action/verbs/get?docid="+result.id);
     var resp = JSON.parse(xhr.responseText);
     T(resp.foo == "bar");   
 
     // test POST
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/verbs/post?baz=boom");
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/verbs/post?baz=boom");
     resp = JSON.parse(xhr.responseText);
     doc = db.open(resp.id);
     T(doc.req.query.baz == "boom");
 
     // test PUT
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/verbs/put?setid=mynewdocid&flim=flam");
   
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/verbs/put?setid=mynewdocid&flim=flam");
   
     doc = db.open("mynewdocid");
     T(doc.req.flim == "flam");
 
     // test DELETE
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/verbs/delete?delid=mynewdocid");
   
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/verbs/delete?delid=mynewdocid");
   
     T(db.open("mynewdocid") == null);
 
     // PUT through on top of an existing id and see the error at the client
@@ -2187,7 +2184,7 @@
       key : "value"
     });
     T(created.ok);
-    xhr = CouchDB.request("GET", "/test_suite_db/_external/action/verbs/put?setid=takethisid&flim=flam");
   
+    xhr = CouchDB.request("GET", "/test_suite_db/_action/verbs/put?setid=takethisid&flim=flam");
   
     resp = JSON.parse(xhr.responseText);
     T(resp.error == "conflict");
     T(resp.reason == "Document update conflict.");

Modified: couchdb/trunk/src/couchdb/couch_httpd_external.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_external.erl?rev=727973&r1=727972&r2=727973&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_external.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_external.erl Fri Dec 19 00:25:19 2008
@@ -12,7 +12,7 @@
 
 -module(couch_httpd_external).
 
--export([handle_external_req/2]).
+-export([handle_external_req/2, handle_external_req/3]).
 
 -import(couch_httpd,[send_error/4]).
 
@@ -25,10 +25,9 @@
     headers = []
 }).
 
-handle_external_req(#httpd{mochi_req=Req, 
-                        method=Verb,
-                        path_parts=[_DbName, _External, UrlName | Path]
-                    }=HttpReq, Db) ->
+process_external_req(#httpd{mochi_req=Req, 
+                        method=Verb
+                    }=HttpReq, Db, Name, Path) ->
     ReqBody = Req:recv_body(),
     ParsedForm = case Req:get_primary_header_value("content-type") of
         "application/x-www-form-urlencoded" ++ _ ->
@@ -36,7 +35,7 @@
         _ ->
             []
     end,
-    Response = couch_external_manager:execute(binary_to_list(UrlName), 
+    Response = couch_external_manager:execute(binary_to_list(Name), 
         Db, Verb, Path, Req:parse_qs(), ReqBody, ParsedForm,
         Req:parse_cookie()),
         
@@ -45,12 +44,22 @@
         send_error(HttpReq, 404, <<"external_server_error">>, Msg);
     _ ->
         send_external_response(Req, Response)
-    end;
+    end.
+
+handle_external_req(#httpd{
+                        path_parts=[_DbName, _External, UrlName | Path]
+                    }=HttpReq, Db) ->
+    process_external_req(HttpReq, Db, UrlName, Path);
 handle_external_req(#httpd{path_parts=[_, _]}=Req, _Db) ->
     send_error(Req, 404, <<"external_server_error">>, <<"No server name
specified.">>);
 handle_external_req(Req, _) ->
     send_error(Req, 404, <<"external_server_error">>, <<"Broken assumption">>).
 
+handle_external_req(#httpd{
+                        path_parts=[_DbName, _External | Path]
+                    }=HttpReq, Db, Name) ->
+    process_external_req(HttpReq, Db, Name, Path).
+
 send_external_response(Req, Response) ->
     #extern_resp_args{
         code = Code,



Mime
View raw message