couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [01/11] couch commit: updated refs/heads/master to 7ab7995
Date Wed, 21 May 2014 16:53:16 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master c35005e11 -> 7ab79953b


Allow optional max_uri_length server setting


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/270f5a76
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/270f5a76
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/270f5a76

Branch: refs/heads/master
Commit: 270f5a769435e6cafde414003c37cc80fb4c058f
Parents: c35005e
Author: Robert Newson <rnewson@apache.org>
Authored: Wed May 21 14:53:32 2014 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed May 21 14:53:32 2014 +0100

----------------------------------------------------------------------
 src/couch_httpd.erl | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/270f5a76/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 8e46b94..852bc7b 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -283,6 +283,7 @@ handle_request_int(MochiReq, DefaultFun,
 
     {ok, Resp} =
     try
+        check_request_uri_length(RawUri),
         case couch_httpd_cors:is_preflight_request(HttpReq) of
         #httpd{} ->
             case authenticate_request(HttpReq, AuthHandlers) of
@@ -316,6 +317,8 @@ handle_request_int(MochiReq, DefaultFun,
             send_error(HttpReq, {bad_otp_release, ErrorReason});
         exit:{body_too_large, _} ->
             send_error(HttpReq, request_entity_too_large);
+        exit:{uri_too_long, _} ->
+            send_error(HttpReq, request_uri_too_long);
         throw:Error ->
             Stack = erlang:get_stacktrace(),
             ?LOG_DEBUG("Minor error in HTTP request: ~p",[Error]),
@@ -342,6 +345,19 @@ handle_request_int(MochiReq, DefaultFun,
     couch_stats_collector:increment({httpd, requests}),
     {ok, Resp}.
 
+check_request_uri_length(Uri) ->
+    check_request_uri_length(Uri, config:get("httpd", "max_uri_length")).
+
+check_request_uri_length(_Uri, undefined) ->
+    ok;
+check_request_uri_length(Uri, MaxUriLen) when is_list(MaxUriLen) ->
+    case length(Uri) > list_to_integer(MaxUriLen) of
+        true ->
+            throw(request_uri_too_long);
+        false ->
+            ok
+    end.
+
 % Try authentication handlers in order until one sets a user_ctx
 % the auth funs also have the option of returning a response
 % move this to couch_httpd_auth?
@@ -798,6 +814,8 @@ error_info(file_exists) ->
         "created, the file already exists.">>};
 error_info(request_entity_too_large) ->
     {413, <<"too_large">>, <<"the request entity is too large">>};
+error_info(request_uri_too_long) ->
+    {414, <<"too_long">>, <<"the request entity is too long">>};
 error_info({bad_ctype, Reason}) ->
     {415, <<"bad_content_type">>, Reason};
 error_info(requested_range_not_satisfiable) ->


Mime
View raw message