summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2008-12-19 08:25:19 +0000
committerJohn Christopher Anderson <jchris@apache.org>2008-12-19 08:25:19 +0000
commit1326c40d66563279dcce712f130c10e5d1d80a03 (patch)
tree587485404908ad79321556a2119cc92212bf1ac0
parent2a6ad51f1acd4cae30a6e976d00444a1a6931702 (diff)
shorter path to _action servers, external supports better routing control
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@727973 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--etc/couchdb/default.ini.tpl.in8
-rw-r--r--share/www/script/couch_tests.js43
-rw-r--r--src/couchdb/couch_httpd_external.erl23
3 files changed, 43 insertions, 31 deletions
diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
index 863ec1f7..a56e05bc 100644
--- a/etc/couchdb/default.ini.tpl.in
+++ b/etc/couchdb/default.ini.tpl.in
@@ -45,4 +45,10 @@ _restart = {couch_httpd_misc_handlers, handle_restart_req}
[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}
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index 0ad6eee0..a57f38c1 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -2054,48 +2054,45 @@ var tests = {
// 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 @@ var tests = {
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 @@ var tests = {
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 @@ var tests = {
// 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 @@ var tests = {
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.");
diff --git a/src/couchdb/couch_httpd_external.erl b/src/couchdb/couch_httpd_external.erl
index 7ed3d51a..84f1c444 100644
--- a/src/couchdb/couch_httpd_external.erl
+++ b/src/couchdb/couch_httpd_external.erl
@@ -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 @@ handle_external_req(#httpd{mochi_req=Req,
_ ->
[]
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 @@ handle_external_req(#httpd{mochi_req=Req,
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,