You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2010/06/15 15:52:34 UTC
svn commit: r954884 - in /couchdb/branches/0.11.x:
etc/couchdb/default.ini.tpl.in src/couchdb/couch_httpd.erl
test/etap/160-vhosts.t
Author: jan
Date: Tue Jun 15 13:52:34 2010
New Revision: 954884
URL: http://svn.apache.org/viewvc?rev=954884&view=rev
Log:
Merge r943764 from trunk:
vhost_global_handlers bypass rewrite rules and are available in all vhosts
Modified:
couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in
couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl
couchdb/branches/0.11.x/test/etap/160-vhosts.t
Modified: couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in?rev=954884&r1=954883&r2=954884&view=diff
==============================================================================
--- couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in (original)
+++ couchdb/branches/0.11.x/etc/couchdb/default.ini.tpl.in Tue Jun 15 13:52:34 2010
@@ -20,6 +20,7 @@ authentication_handlers = {couch_httpd_o
default_handler = {couch_httpd_db, handle_request}
secure_rewrites = true
allow_jsonp = false
+vhost_global_handlers = _utils, _uuids, _session, _oauth, _users
[log]
file = %localstatelogdir%/couch.log
Modified: couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl?rev=954884&r1=954883&r2=954884&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_httpd.erl Tue Jun 15 13:52:34 2010
@@ -13,7 +13,7 @@
-module(couch_httpd).
-include("couch_db.hrl").
--export([start_link/0, stop/0, handle_request/6]).
+-export([start_link/0, stop/0, handle_request/7]).
-export([header_value/2,header_value/3,qs_value/2,qs_value/3,qs/1,path/1,absolute_uri/2,body_length/1]).
-export([verify_is_server_admin/1,unquote/1,quote/1,recv/2,recv_chunked/4,error_info/1]).
@@ -37,7 +37,11 @@ start_link() ->
Port = couch_config:get("httpd", "port", "5984"),
MaxConnections = couch_config:get("httpd", "max_connections", "2048"),
VirtualHosts = couch_config:get("vhosts"),
-
+ VhostGlobals = re:split(
+ couch_config:get("httpd", "vhost_global_handlers", ""),
+ ", ?",
+ [{return, list}]
+ ),
DefaultSpec = "{couch_httpd_db, handle_request}",
DefaultFun = make_arity_1_fun(
couch_config:get("httpd", "default_handler", DefaultSpec)
@@ -64,7 +68,7 @@ start_link() ->
Loop = fun(Req)->
apply(?MODULE, handle_request, [
Req, DefaultFun, UrlHandlers, DbUrlHandlers, DesignUrlHandlers,
- VirtualHosts
+ VirtualHosts, VhostGlobals
])
end,
@@ -157,19 +161,26 @@ redirect_to_vhost(MochiReq, DefaultFun,
UrlHandlers, DbUrlHandlers, DesignUrlHandlers).
handle_request(MochiReq, DefaultFun,
- UrlHandlers, DbUrlHandlers, DesignUrlHandlers, VirtualHosts) ->
+ UrlHandlers, DbUrlHandlers, DesignUrlHandlers, VirtualHosts, VhostGlobals) ->
% grab Host from Req
Vhost = MochiReq:get_header_value("Host"),
% find Vhost in config
case proplists:get_value(Vhost, VirtualHosts) of
- undefined -> % business as usual
+ undefined -> % business as usual
+ handle_request_int(MochiReq, DefaultFun,
+ UrlHandlers, DbUrlHandlers, DesignUrlHandlers);
+ VhostTarget ->
+ case vhost_global(VhostGlobals, MochiReq) of
+ true -> % global handler for vhosts
handle_request_int(MochiReq, DefaultFun,
- UrlHandlers, DbUrlHandlers, DesignUrlHandlers);
- VhostTarget ->
+ UrlHandlers, DbUrlHandlers, DesignUrlHandlers);
+ _Else ->
+ % do rewrite
redirect_to_vhost(MochiReq, DefaultFun,
UrlHandlers, DbUrlHandlers, DesignUrlHandlers, VhostTarget)
+ end
end.
@@ -297,6 +308,11 @@ authenticate_request(Response, _AuthSrcs
increment_method_stats(Method) ->
couch_stats_collector:increment({httpd_request_methods, Method}).
+% if so, then it will not be rewritten, but will run as a normal couchdb request.
+% normally you'd use this for _uuids _utils and a few of the others you want to keep available on vhosts. You can also use it to make databases 'global'.
+vhost_global(VhostGlobals, MochiReq) ->
+ "/"++Path = MochiReq:get(path),
+ [true] == [true||V <- VhostGlobals, V == Path].
% Utilities
Modified: couchdb/branches/0.11.x/test/etap/160-vhosts.t
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/test/etap/160-vhosts.t?rev=954884&r1=954883&r2=954884&view=diff
==============================================================================
--- couchdb/branches/0.11.x/test/etap/160-vhosts.t (original)
+++ couchdb/branches/0.11.x/test/etap/160-vhosts.t Tue Jun 15 13:52:34 2010
@@ -54,7 +54,7 @@ config_files() ->
main(_) ->
test_util:init_code_path(),
- etap:plan(3),
+ etap:plan(4),
case (catch test()) of
ok ->
etap:end_tests();
@@ -85,6 +85,7 @@ test() ->
test_regular_request(),
test_vhost_request(),
test_vhost_request_with_qs(),
+ test_vhost_request_with_global(),
%% restart boilerplate
couch_db:close(Db),
@@ -119,3 +120,13 @@ test_vhost_request_with_qs() ->
etap:is(HasRevsInfo, true, "should return _revs_info");
_Else -> false
end.
+
+test_vhost_request_with_global() ->
+ Url = server() ++ "_uuids",
+ case ibrowse:send_req(Url, [], get, [], [{host_header, "example.com"}]) of
+ {ok, _, _, Body} ->
+ {JsonProps} = couch_util:json_decode(Body),
+ HasUuids = proplists:is_defined(<<"uuids">>, JsonProps),
+ etap:is(HasUuids, true, "should return _uuids");
+ _Else -> false
+ end.