couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [2/9] chttpd commit: updated refs/heads/1843-feature-bigcouch-clustered-eventsource-changes-feed to 002a908
Date Wed, 28 May 2014 22:45:08 GMT
Allow optional max_uri_length server setting


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

Branch: refs/heads/1843-feature-bigcouch-clustered-eventsource-changes-feed
Commit: eaf1b56ae63fa6f5708348246933de2aa1602130
Parents: 76d82fc
Author: Robert Newson <rnewson@apache.org>
Authored: Thu May 22 11:52:02 2014 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu May 22 11:52:02 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/eaf1b56a/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index dd184c0..f9ed560 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -203,6 +203,7 @@ handle_request(MochiReq) ->
 
     Result =
     try
+        check_request_uri_length(RawUri),
         case authenticate_request(HttpReq, AuthenticationFuns) of
         #httpd{} = Req ->
             HandlerFun = url_handler(HandlerKey),
@@ -220,6 +221,8 @@ handle_request(MochiReq) ->
         exit:{mochiweb_recv_error, E} ->
             couch_log:notice(LogForClosedSocket ++ " - ~p", [E]),
             exit(normal);
+        exit:{uri_too_long, _} ->
+            send_error(HttpReq, request_uri_too_long);
         throw:Error ->
             send_error(HttpReq, Error);
         error:database_does_not_exist ->
@@ -276,6 +279,19 @@ possibly_hack(#httpd{path_parts=[<<"_replicate">>]}=Req)
->
 possibly_hack(Req) ->
     Req.
 
+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.
+
 fix_uri(Req, Props, Type) ->
     case is_http(replication_uri(Type, Props)) of
     true ->
@@ -694,6 +710,8 @@ error_info({r_quorum_not_met, Reason}) ->
     {412, <<"read_quorum_not_met">>, Reason};
 error_info({w_quorum_not_met, Reason}) ->
     {500, <<"write_quorum_not_met">>, Reason};
+error_info(request_uri_too_long) ->
+    {414, <<"too_long">>, <<"the request uri is too long">>};
 error_info({bad_ctype, Reason}) ->
     {415, <<"bad_content_type">>, Reason};
 error_info(requested_range_not_satisfiable) ->


Mime
View raw message