Permalink
Browse files

support for adding a nonce to requests, api for accessing _rexi_calls

  • Loading branch information...
1 parent 03cc264 commit bcc3f3e32b69a174894b75ef5d2c8100dedbe542 Robert Dionne committed Nov 18, 2010
Showing with 28 additions and 2 deletions.
  1. +22 −1 apps/couch/src/couch_httpd_misc_handlers.erl
  2. +5 −1 apps/couch/src/couch_util.erl
  3. +1 −0 rel/overlay/etc/default.ini
@@ -15,7 +15,7 @@
-export([handle_welcome_req/2,handle_favicon_req/2,handle_utils_dir_req/2,
handle_all_dbs_req/1,handle_replicate_req/1,handle_restart_req/1,
handle_uuids_req/1,handle_config_req/1,handle_log_req/1,
- handle_task_status_req/1]).
+ handle_task_status_req/1, handle_rexi_calls_req/1]).
-export([increment_update_seq_req/2]).
@@ -216,4 +216,25 @@ handle_log_req(#httpd{method='GET'}=Req) ->
handle_log_req(Req) ->
send_method_not_allowed(Req, "GET").
+% httpd rexi_calls
+
+handle_rexi_calls_req(#httpd{method='GET'}=Req) ->
+ ok = couch_httpd:verify_is_server_admin(Req),
+ NoCalls = list_to_integer(couch_httpd:qs_value(Req, "n", "20")),
+ {ok, Data} = rexi_server:calls(NoCalls),
+ {ok, Resp} = start_chunked_response(Req, 200, [
+ % send a plaintext response
+ {"Content-Type", "text/plain; charset=utf-8"},
+ {"Content-Length", integer_to_list(length(Data))}
+ ]),
+ send_chunk(Resp,Data),
+ last_chunk(Resp);
+handle_rexi_calls_req(#httpd{method='PUT'}=Req) ->
+ ok = couch_httpd:verify_is_server_admin(Req),
+ NewSize = list_to_integer(couch_httpd:qs_value(Req, "cache_size", "20")),
+ {ok, OldSize} = rexi_server:set_call_cache_size(NewSize),
+ send_json(Req, 200, OldSize);
+handle_rexi_calls_req(Req) ->
+ send_method_not_allowed(Req, "GET,PUT").
+
@@ -14,7 +14,7 @@
-export([priv_dir/0, start_driver/1, normpath/1]).
-export([should_flush/0, should_flush/1, to_existing_atom/1]).
--export([rand32/0, implode/2, collate/2, collate/3]).
+-export([rand32/0, nonce/0, implode/2, collate/2, collate/3]).
-export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]).
-export([encodeBase64Url/1, decodeBase64Url/1]).
-export([to_hex/1, parse_term/1, dict_find/3]).
@@ -167,6 +167,10 @@ json_user_ctx(#db{name=DbName, user_ctx=Ctx}) ->
rand32() ->
crypto:rand_uniform(0, 16#100000000).
+% generate a random 5 digit string
+nonce() ->
+ lists:sublist(integer_to_list(couch_util:rand32()),1,5).
+
% given a pathname "../foo/bar/" it gives back the fully qualified
% absolute pathname.
abs_pathname(" " ++ Filename) ->
@@ -71,6 +71,7 @@ _session = {couch_httpd_auth, handle_session_req}
_oauth = {couch_httpd_oauth, handle_oauth_req}
_user = {couch_httpd_auth, handle_user_req}
_system = {chttpd_misc, handle_system_req}
+_rexi_calls = {couch_httpd_misc_handlers, handle_rexi_calls_req}
[httpd_db_handlers]
_view_cleanup = {couch_httpd_db, handle_view_cleanup_req}

0 comments on commit bcc3f3e

Please sign in to comment.