You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/01 11:05:37 UTC

[01/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Repository: couchdb-chttpd
Updated Branches:
  refs/heads/windsor-merge [created] 554ef7486


Honor "w" parameter for update handlers

BugzID: 17936


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

Branch: refs/heads/windsor-merge
Commit: 43a2e967b1815044ea743fb28a14ca07a8e0c5b8
Parents: 1ee2725
Author: Robert Newson <ro...@cloudant.com>
Authored: Sat Mar 9 15:45:40 2013 -0600
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:10:23 2014 +0100

----------------------------------------------------------------------
 src/chttpd_show.erl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/43a2e967/src/chttpd_show.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_show.erl b/src/chttpd_show.erl
index 58c88e6..9db4d07 100644
--- a/src/chttpd_show.erl
+++ b/src/chttpd_show.erl
@@ -118,13 +118,14 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
     JsonReq = chttpd_external:json_req_obj(Req, Db, DocId),
     JsonDoc = couch_query_servers:json_doc(Doc),
     Cmd = [<<"updates">>, UpdateName],
+    W = couch_httpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db))),
     case couch_query_servers:ddoc_prompt(DDoc, Cmd, [JsonDoc, JsonReq]) of
     [<<"up">>, {NewJsonDoc}, JsonResp] ->
         case chttpd:header_value(Req, "X-Couch-Full-Commit", "false") of
         "true" ->
-            Options = [full_commit, {user_ctx, Req#httpd.user_ctx}];
+            Options = [full_commit, {user_ctx, Req#httpd.user_ctx}, {w, W}];
         _ ->
-            Options = [{user_ctx, Req#httpd.user_ctx}]
+            Options = [{user_ctx, Req#httpd.user_ctx}, {w, W}]
         end,
         NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
         case fabric:update_doc(Db, NewDoc, Options) of


[45/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Be more careful when matching attachment data

This code was ported from a list comprehension which used
to properly ignore patterns which didn't match the Fd
tuple. This adds back the ability to ignore stub data
entries as this does come up in one case where att_since is
passed in via the API.


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

Branch: refs/heads/windsor-merge
Commit: 07c2603aeafec99a9b4d353f8656d87ce0fe2a76
Parents: 07bf741
Author: Brian Mitchell <br...@cloudant.com>
Authored: Fri May 16 15:57:53 2014 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/07c2603a/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index ae70aa3..f831389 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1361,12 +1361,27 @@ validate_attachment_name(Name) ->
 
 -spec monitor_attachments(couch_att:att() | [couch_att:att()]) -> [reference()].
 monitor_attachments(Atts) when is_list(Atts) ->
-    lists:map(fun(Att) ->
-        {Fd, _} = couch_att:fetch(data, Att),
-        monitor(process, Fd)
-    end, Atts);
+    lists:foldl(fun(Att, Monitors) ->
+        case couch_att:fetch(data, Att) of
+            {Fd, _} -> [monitor(process, Fd) | Monitors];
+            _ -> Monitors
+        end
+    end, [], Atts);
 monitor_attachments(Att) ->
     monitor_attachments([Att]).
 
 demonitor_refs(Refs) when is_list(Refs) ->
     [demonitor(Ref) || Ref <- Refs].
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+monitor_attachments_test_() ->
+    {"ignore stubs",
+        fun () ->
+            Atts = [couch_att:new([{data, stub}])],
+            ?_assertEqual([], monitor_attachments(Atts))
+        end
+    }.
+
+-endif.


[48/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add cassim


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

Branch: refs/heads/windsor-merge
Commit: 2a2705967db91b43a476e7e3850fad5220ab269b
Parents: 58c203d
Author: Robert Newson <rn...@apache.org>
Authored: Wed Jul 30 12:07:19 2014 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd.app.src          |  3 ++-
 src/chttpd_auth_request.erl |  2 +-
 src/chttpd_db.erl           | 56 ++++++++++++++++++++++++++++++++--------
 3 files changed, 48 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/2a270596/src/chttpd.app.src
----------------------------------------------------------------------
diff --git a/src/chttpd.app.src b/src/chttpd.app.src
index f24716d..5e63d66 100644
--- a/src/chttpd.app.src
+++ b/src/chttpd.app.src
@@ -39,7 +39,8 @@
         config,
         couch,
         ets_lru,
-        fabric
+        fabric,
+        cassim
     ]},
     {mod, {chttpd_app,[]}}
 ]}.

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/2a270596/src/chttpd_auth_request.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_auth_request.erl b/src/chttpd_auth_request.erl
index 0c311a0..c9cc3a9 100644
--- a/src/chttpd_auth_request.erl
+++ b/src/chttpd_auth_request.erl
@@ -74,7 +74,7 @@ server_authorization_check(#httpd{path_parts=[<<"_", _/binary>>|_]}=Req) ->
     require_admin(Req).
 
 db_authorization_check(#httpd{path_parts=[DbName|_],user_ctx=Ctx}=Req) ->
-    {_} = fabric:get_security(DbName, [{user_ctx, Ctx}]),
+    {_} = cassim:get_security(DbName, [{user_ctx, Ctx}]),
     Req.
 
 require_admin(Req) ->

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/2a270596/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 4741502..86e32dd 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -244,7 +244,7 @@ delete_db_req(#httpd{}=Req, DbName) ->
     end.
 
 do_db_req(#httpd{path_parts=[DbName|_], user_ctx=Ctx}=Req, Fun) ->
-    fabric:get_security(DbName, [{user_ctx,Ctx}]), % calls check_is_reader
+    cassim:get_security(DbName, [{user_ctx,Ctx}]), % calls check_is_reader
     Fun(Req, #db{name=DbName, user_ctx=Ctx}).
 
 db_req(#httpd{method='GET',path_parts=[DbName]}=Req, _Db) ->
@@ -462,22 +462,25 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_revs_diff">>]}=Req, Db) ->
 db_req(#httpd{path_parts=[_,<<"_revs_diff">>]}=Req, _Db) ->
     send_method_not_allowed(Req, "POST");
 
-db_req(#httpd{method='PUT',path_parts=[_,<<"_security">>],user_ctx=Ctx}=Req,
-        Db) ->
-    SecObj = chttpd:json_body(Req),
-    case fabric:set_security(Db, SecObj, [{user_ctx, Ctx}]) of
-        ok ->
-            send_json(Req, {[{<<"ok">>, true}]});
-        Else ->
-            throw(Else)
-    end;
+%% DEPRECATED: this endpoint functionality will be replaced by _security_mvcc
+db_req(#httpd{method='PUT',path_parts=[_,<<"_security">>]}=Req, Db) ->
+    put_security(Req, Db, true);
 
 db_req(#httpd{method='GET',path_parts=[_,<<"_security">>],user_ctx=Ctx}=Req, Db) ->
-    send_json(Req, fabric:get_security(Db, [{user_ctx,Ctx}]));
+    send_json(Req, cassim:get_security(Db, [{user_ctx,Ctx}]));
 
 db_req(#httpd{path_parts=[_,<<"_security">>]}=Req, _Db) ->
     send_method_not_allowed(Req, "PUT,GET");
 
+db_req(#httpd{method='PUT',path_parts=[_,<<"_security_mvcc">>]}=Req, Db) ->
+    put_security(Req, Db, false);
+
+db_req(#httpd{method='GET',path_parts=[_,<<"_security_mvcc">>],user_ctx=Ctx}=Req, Db) ->
+    send_json(Req, cassim:get_security(Db, [{user_ctx,Ctx}]));
+
+db_req(#httpd{path_parts=[_,<<"_security_mvcc">>]}=Req, _Db) ->
+    send_method_not_allowed(Req, "PUT,GET");
+
 db_req(#httpd{method='PUT',path_parts=[_,<<"_revs_limit">>],user_ctx=Ctx}=Req,
         Db) ->
     Limit = chttpd:json_body(Req),
@@ -1392,6 +1395,37 @@ monitor_attachments(Att) ->
 demonitor_refs(Refs) when is_list(Refs) ->
     [demonitor(Ref) || Ref <- Refs].
 
+put_security(#httpd{user_ctx=Ctx}=Req, Db, FetchRev) ->
+    DbName = Db#db.name,
+    DocId = cassim_metadata_cache:security_meta_id(DbName),
+    {SecObj0} = chttpd:json_body(Req),
+    {OldSecDoc} = cassim:get_security(DbName),
+    OldRev = couch_util:get_value(<<"_rev">>, OldSecDoc, undefined),
+    %% Maybe update the security doc with the rev when hiding mvcc logic
+    SecObj = case {FetchRev, OldRev} of
+        %% User supplied rev, just use the req body
+        {false, _} ->
+            SecObj0;
+        %% User did not supply rev, but new security doc
+        {true, undefined} ->
+            SecObj0;
+        %% User did not supply rev, use the old rev
+        {true, OldRev} ->
+            [{<<"_rev">>, OldRev} | proplists:delete(<<"_rev">>, SecObj0)]
+    end,
+    SecDoc = couch_doc_from_req(Req, DocId, {SecObj}),
+    Options = [
+        delay_commit,
+        interactive_edit,
+        {user_ctx, Ctx},
+        {w, integer_to_list(mem3:quorum(Db))}
+    ],
+    {Status, {etag, Etag}, Body} =
+        cassim:set_security(Db, SecDoc, Options),
+    HttpCode = http_code_from_status(Status),
+    ResponseHeaders = [{"Etag", Etag}],
+    send_json(Req, HttpCode, ResponseHeaders, Body).
+
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").
 


[30/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Fix case_clause error with POST to _replicate

We were matching without specifying a default value. Rather than end up
causing other errors we just match on false and default true for all
other values.

BugzId: 24355


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

Branch: refs/heads/windsor-merge
Commit: 1cc0ae3abad982e2d5ae48ee92e7784d30eedf82
Parents: 5d50b2b
Author: Paul J. Davis <pa...@gmail.com>
Authored: Mon Oct 21 23:57:37 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Jul 30 11:17:44 2014 +0100

----------------------------------------------------------------------
 src/chttpd_misc.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/1cc0ae3a/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index f4a643c..a2719fd 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -174,7 +174,7 @@ replicate({Props} = PostBody, Ctx) ->
     case couch_util:get_value(<<"cancel">>, Props) of
     true ->
         cancel_replication(PostBody, Ctx);
-    false ->
+    _ ->
         Node = choose_node([
             couch_util:get_value(<<"source">>, Props),
             couch_util:get_value(<<"target">>, Props)


[08/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Give fabric a string, not a number


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

Branch: refs/heads/windsor-merge
Commit: 4e02118c6a0195361455f88faa80953d548ab3a9
Parents: c90a4c0
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Apr 10 23:45:14 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:12:57 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/4e02118c/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 18a1078..86653f9 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -303,7 +303,7 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
     DocsArray = couch_util:get_value(<<"docs">>, JsonProps),
     W = case couch_util:get_value(<<"w">>, JsonProps) of
     Value when is_integer(Value) ->
-        Value;
+        integer_to_list(Value);
     _ ->
         couch_httpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db)))
     end,


[03/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Allow ?deleted=true on doc GET's


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

Branch: refs/heads/windsor-merge
Commit: 57697a8c9fc7af9a454a8808bdd61196ccc32c6a
Parents: ce262ee
Author: Robert Newson <ro...@cloudant.com>
Authored: Fri Mar 15 18:09:59 2013 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:10:44 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/57697a8c/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 7060d02..8839eb1 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1178,6 +1178,9 @@ parse_doc_query(Req) ->
         {"conflicts", "true"} ->
             Options = [conflicts | Args#doc_query_args.options],
             Args#doc_query_args{options=Options};
+        {"deleted", "true"} ->
+            Options = [deleted | Args#doc_query_args.options],
+            Args#doc_query_args{options=Options};
         {"deleted_conflicts", "true"} ->
             Options = [deleted_conflicts | Args#doc_query_args.options],
             Args#doc_query_args{options=Options};


[09/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add _shards db handler auth check


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

Branch: refs/heads/windsor-merge
Commit: e5ecb22a147984d74a5323a7b68cd3a61287b923
Parents: 4e02118
Author: Russell Branca <ch...@gmail.com>
Authored: Fri Apr 12 16:47:20 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:16:19 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/e5ecb22a/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 136a0a0..75fcf6d 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -373,7 +373,8 @@ db_url_handlers() ->
         {<<"_compact">>,        fun chttpd_db:handle_compact_req/2},
         {<<"_design">>,         fun chttpd_db:handle_design_req/2},
         {<<"_temp_view">>,      fun chttpd_view:handle_temp_view_req/2},
-        {<<"_changes">>,        fun chttpd_db:handle_changes_req/2}
+        {<<"_changes">>,        fun chttpd_db:handle_changes_req/2},
+        {<<"_shards">>,         fun mem3_httpd:handle_shards_req/2}
     ].
 
 design_url_handlers() ->


[11/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Throw 400 bad request not 500 for unrecognised _changes feed param


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

Branch: refs/heads/windsor-merge
Commit: 4816754e2513d20c2a1042d6b24331c76f63cb35
Parents: 0ba63fd
Author: Michael Rhodes <mi...@gmail.com>
Authored: Wed May 8 15:52:31 2013 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:20:30 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/4816754e/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index cb13805..c81bf85 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -71,9 +71,11 @@ handle_changes_req(#httpd{method='GET'}=Req, Db) ->
             fabric:changes(Db, fun changes_callback/2, {"normal", {"Etag",Etag}, Req},
                 ChangesArgs)
         end);
-    Feed ->
-        % "longpoll" or "continuous" or "eventsource"
-        fabric:changes(Db, fun changes_callback/2, {Feed, Req}, ChangesArgs)
+    Feed when Feed =:= "continuous"; Feed =:= "longpoll"; Feed =:= "eventsource"  ->
+        fabric:changes(Db, fun changes_callback/2, {Feed, Req}, ChangesArgs);
+    _ ->
+        Msg = <<"Supported `feed` types: normal, continuous, longpoll, eventsource">>,
+        throw({bad_request, Msg})
     end;
 handle_changes_req(#httpd{path_parts=[_,<<"_changes">>]}=Req, _Db) ->
     send_method_not_allowed(Req, "GET,HEAD").


[19/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Validate _bulk_docs POST bodies

This patch supplies some necessary input validation that
couch_doc:from_json_obj/1 can't provide. It eliminates spurious HTTP
500s and stacktraces from _bulk_docs POST bodies of the following
invalid formats:

    {"docs": {"_id": "foo"}}
    {"_id": "foo"}

BugzID: 21746


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

Branch: refs/heads/windsor-merge
Commit: b71d3112286ef00d458c1d858c437ee6a3432358
Parents: 440f5a0
Author: Benjamin Anderson <b...@banjiewen.net>
Authored: Fri Aug 16 15:09:59 2013 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:06:28 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/b71d3112/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 57b0c4f..7d27bd9 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -302,7 +302,14 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
     couch_stats_collector:increment({httpd, bulk_requests}),
     couch_httpd:validate_ctype(Req, "application/json"),
     {JsonProps} = chttpd:json_body_obj(Req),
-    DocsArray = couch_util:get_value(<<"docs">>, JsonProps),
+    DocsArray = case couch_util:get_value(<<"docs">>, JsonProps) of
+    undefined ->
+        throw({bad_request, <<"POST body must include `docs` parameter.">>});
+    DocsArray0 when not is_list(DocsArray0) ->
+        throw({bad_request, <<"`docs` parameter must be an array.">>});
+    DocsArray0 ->
+        DocsArray0
+    end,
     W = case couch_util:get_value(<<"w">>, JsonProps) of
     Value when is_integer(Value) ->
         integer_to_list(Value);


[17/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Handle undefined result from process_info

BugzID: 21827


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

Branch: refs/heads/windsor-merge
Commit: e6d115a854f399620a00823186656ea56aa44afe
Parents: 6c1f455
Author: Robert Newson <ro...@cloudant.com>
Authored: Thu Aug 15 15:21:05 2013 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:03:39 2014 +0100

----------------------------------------------------------------------
 src/chttpd_misc.erl | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/e6d115a8/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 62cd903..12b18f8 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -293,16 +293,20 @@ couch_file_stats() ->
     Candidates = [Pid || {process, Pid} <- M],
     Mailboxes = lists:foldl(
         fun(Pid, Acc) ->
-            PI = process_info(Pid, [message_queue_len, dictionary]),
-            Dictionary = proplists:get_value(dictionary, PI, []),
-            case proplists:get_value('$initial_call', Dictionary) of
-                {couch_file, init, 1} ->
-                    case proplists:get_value(message_queue_len, PI) of
-                        undefined -> Acc;
-                        Len -> [Len|Acc]
-                    end;
-                _  ->
-                    Acc
+            case process_info(Pid, [message_queue_len, dictionary]) of
+                undefined ->
+                    Acc;
+                PI ->
+                    Dictionary = proplists:get_value(dictionary, PI, []),
+                    case proplists:get_value('$initial_call', Dictionary) of
+                        {couch_file, init, 1} ->
+                            case proplists:get_value(message_queue_len, PI) of
+                                undefined -> Acc;
+                                Len -> [Len|Acc]
+                            end;
+                        _  ->
+                            Acc
+                    end
             end
         end, [], Candidates
     ),


[39/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add error_info clause for nodedown errors

BugzId: 26122


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

Branch: refs/heads/windsor-merge
Commit: 57d1078691061e728ab6f856eee40f55ed4bbc3f
Parents: d15303f
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Dec 12 12:42:53 2013 -0600
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:10 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/57d10786/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index a783f91..d671812 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -705,6 +705,8 @@ error_info(file_exists) ->
         "created, the file already exists.">>};
 error_info({r_quorum_not_met, Reason}) ->
     {412, <<"read_quorum_not_met">>, Reason};
+error_info({error, {nodedown, Reason}}) ->
+    {412, <<"nodedown">>, Reason};
 error_info({maintenance_mode, Node}) ->
     {412, <<"nodedown">>, Node};
 error_info({w_quorum_not_met, Reason}) ->


[34/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Improve logging of errors with traces


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

Branch: refs/heads/windsor-merge
Commit: 50ccf2932b9072fefd24111c3b6fb7d54038a8cd
Parents: f4b0fdc
Author: Robert Newson <ro...@cloudant.com>
Authored: Tue Dec 10 00:44:04 2013 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:54:27 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/50ccf293/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 93b56f0..372a61d 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -642,7 +642,7 @@ send_delayed_error(#delayed_resp{req=Req,resp=nil}=DelayedResp, Reason) ->
     {ok, Resp} = send_error(Req, Code, ErrorStr, ReasonStr),
     {ok, DelayedResp#delayed_resp{resp=Resp}};
 send_delayed_error(#delayed_resp{resp=Resp}, Reason) ->
-    log_stack_trace(json_stack(Reason)),
+    log_error_with_stack_trace(Reason),
     throw({http_abort, Resp, Reason}).
 
 end_delayed_json_response(#delayed_resp{}=DelayedResp) ->
@@ -813,11 +813,11 @@ send_error(Req, Code, Headers, ErrorStr, ReasonStr, []) ->
         {[{<<"error">>,  ErrorStr},
         {<<"reason">>, ReasonStr}]});
 send_error(Req, Code, Headers, ErrorStr, ReasonStr, Stack) ->
-    log_stack_trace(Stack),
+    log_error_with_stack_trace({ErrorStr, ReasonStr, Stack}),
     send_json(Req, Code, [stack_trace_id(Stack) | Headers],
         {[{<<"error">>,  ErrorStr},
-        {<<"reason">>, ReasonStr},
-        {<<"ref">>, stack_hash(Stack)}
+        {<<"reason">>, ReasonStr} |
+        case Stack of [] -> []; _ -> [{<<"ref">>, stack_hash(Stack)}] end
     ]}).
 
 % give the option for list functions to output html or other raw errors
@@ -827,12 +827,12 @@ send_chunked_error(Resp, {_Error, {[{<<"body">>, Reason}]}}) ->
 
 send_chunked_error(Resp, Error) ->
     Stack = json_stack(Error),
-    log_stack_trace(Stack),
+    log_error_with_stack_trace(Error),
     {Code, ErrorStr, ReasonStr} = error_info(Error),
     JsonError = {[{<<"code">>, Code},
         {<<"error">>,  ErrorStr},
-        {<<"reason">>, ReasonStr},
-        {<<"ref">>, stack_hash(Stack)}
+        {<<"reason">>, ReasonStr} |
+        case Stack of [] -> []; _ -> [{<<"ref">>, stack_hash(Stack)}] end
     ]},
     send_chunk(Resp, ?l2b([$\n,?JSON_ENCODE(JsonError),$\n])),
     send_chunk(Resp, []).
@@ -890,8 +890,13 @@ maybe_decompress(Httpd, Body) ->
         throw({bad_ctype, [Else, " is not a supported content encoding."]})
     end.
 
-log_stack_trace(Stack) ->
-    couch_log:error("~p failed with trace: ~p", [stack_hash(Stack), Stack]).
+log_error_with_stack_trace({bad_request, _, _}) ->
+    ok;
+log_error_with_stack_trace({Error, Reason, Stack}) ->
+    couch_log:error("ref: ~p req_err ~p:~p ~p",
+             [stack_hash(Stack), Error, Reason, Stack]);
+log_error_with_stack_trace(_) ->
+    ok.
 
 stack_trace_id(Stack) ->
     {"X-Cloudant-Stack-Hash", stack_hash(Stack)}.


[05/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Remove trailing whitespace in chttpd_show


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

Branch: refs/heads/windsor-merge
Commit: 1e0c52a77d963661ba64ff03b99351a0c414c1a2
Parents: 7932e0c
Author: Michael Rhodes <mi...@gmail.com>
Authored: Sat Apr 6 21:52:58 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:11:34 2014 +0100

----------------------------------------------------------------------
 src/chttpd_show.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/1e0c52a7/src/chttpd_show.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_show.erl b/src/chttpd_show.erl
index 9db4d07..7dc5337 100644
--- a/src/chttpd_show.erl
+++ b/src/chttpd_show.erl
@@ -18,7 +18,7 @@
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
 % /db/_design/foo/_show/bar/docid
-% show converts a json doc to a response of any content-type. 
+% show converts a json doc to a response of any content-type.
 % it looks up the doc an then passes it to the query server.
 % then it sends the response from the query server to the http client.
 
@@ -44,7 +44,7 @@ handle_doc_show_req(#httpd{
 handle_doc_show_req(#httpd{
         path_parts=[_, _, _, _, ShowName, DocId|Rest]
     }=Req, Db, DDoc) ->
-    
+
     DocParts = [DocId|Rest],
     DocId1 = ?l2b(string:join([?b2l(P)|| P <- DocParts], "/")),
 
@@ -75,7 +75,7 @@ handle_doc_show(Req, Db, DDoc, ShowName, Doc, DocId) ->
     chttpd:etag_respond(Req, CurrentEtag, fun() ->
         JsonReq = chttpd_external:json_req_obj(Req, Db, DocId),
         JsonDoc = couch_query_servers:json_doc(Doc),
-        [<<"resp">>, ExternalResp] = 
+        [<<"resp">>, ExternalResp] =
             couch_query_servers:ddoc_prompt(DDoc, [<<"shows">>, ShowName],
                 [JsonDoc, JsonReq]),
         JsonResp = apply_etag(ExternalResp, CurrentEtag),


[20/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add boilerplate for global_changes


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

Branch: refs/heads/windsor-merge
Commit: 1fc39d29525d00c5e8338986481e0db0c230fc30
Parents: b71d311
Author: Benjamin Bastian <be...@gmail.com>
Authored: Sat Sep 21 12:33:16 2013 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:08:56 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/1fc39d29/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 632eb3d..982aa9a 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -368,6 +368,7 @@ url_handler("_session") ->      fun chttpd_auth:handle_session_req/1;
 url_handler("_oauth") ->        fun couch_httpd_oauth:handle_oauth_req/1;
 url_handler("_up") ->           fun chttpd_misc:handle_up_req/1;
 url_handler("_membership") ->   fun mem3_httpd:handle_membership_req/1;
+url_handler("_db_updates") ->   fun global_changes_httpd:handle_global_changes_req/1;
 url_handler(_) ->               fun chttpd_db:handle_request/1.
 
 db_url_handlers() ->


[43/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
 Only use cassim:set_security if cassim is enabled

BugzId: 32070


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

Branch: refs/heads/windsor-merge
Commit: 554ef748625f97d21e6808b8ba09981b3ae076c5
Parents: 2a27059
Author: Russell Branca <ch...@apache.org>
Authored: Mon Jun 30 13:31:04 2014 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 72 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 43 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/554ef748/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 86e32dd..14e9594 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1395,36 +1395,50 @@ monitor_attachments(Att) ->
 demonitor_refs(Refs) when is_list(Refs) ->
     [demonitor(Ref) || Ref <- Refs].
 
+%% This function should exist in cassim, but its depedence on the #httpd{}
+%% record makes it difficult to separate. This function should be refactored and
+%% moved into cassim once couch_doc_from_req and update_doc are reworked.
 put_security(#httpd{user_ctx=Ctx}=Req, Db, FetchRev) ->
-    DbName = Db#db.name,
-    DocId = cassim_metadata_cache:security_meta_id(DbName),
-    {SecObj0} = chttpd:json_body(Req),
-    {OldSecDoc} = cassim:get_security(DbName),
-    OldRev = couch_util:get_value(<<"_rev">>, OldSecDoc, undefined),
-    %% Maybe update the security doc with the rev when hiding mvcc logic
-    SecObj = case {FetchRev, OldRev} of
-        %% User supplied rev, just use the req body
-        {false, _} ->
-            SecObj0;
-        %% User did not supply rev, but new security doc
-        {true, undefined} ->
-            SecObj0;
-        %% User did not supply rev, use the old rev
-        {true, OldRev} ->
-            [{<<"_rev">>, OldRev} | proplists:delete(<<"_rev">>, SecObj0)]
-    end,
-    SecDoc = couch_doc_from_req(Req, DocId, {SecObj}),
-    Options = [
-        delay_commit,
-        interactive_edit,
-        {user_ctx, Ctx},
-        {w, integer_to_list(mem3:quorum(Db))}
-    ],
-    {Status, {etag, Etag}, Body} =
-        cassim:set_security(Db, SecDoc, Options),
-    HttpCode = http_code_from_status(Status),
-    ResponseHeaders = [{"Etag", Etag}],
-    send_json(Req, HttpCode, ResponseHeaders, Body).
+    case cassim:is_enabled() of
+        true ->
+            DbName = Db#db.name,
+            DocId = cassim_metadata_cache:security_meta_id(DbName),
+            {SecObj0} = chttpd:json_body(Req),
+            {OldSecDoc} = cassim:get_security(DbName),
+            OldRev = couch_util:get_value(<<"_rev">>, OldSecDoc, undefined),
+            %% Maybe update the security doc with the rev when hiding mvcc logic
+            SecObj = case {FetchRev, OldRev} of
+                %% User supplied rev, just use the req body
+                {false, _} ->
+                    SecObj0;
+                %% User did not supply rev, but new security doc
+                {true, undefined} ->
+                    SecObj0;
+                %% User did not supply rev, use the old rev
+                {true, OldRev} ->
+                    [{<<"_rev">>, OldRev}|proplists:delete(<<"_rev">>, SecObj0)]
+            end,
+            SecDoc = couch_doc_from_req(Req, DocId, {SecObj}),
+            Options = [
+                delay_commit,
+                interactive_edit,
+                {user_ctx, Ctx},
+                {w, integer_to_list(mem3:quorum(Db))}
+            ],
+            {Status, {etag, Etag}, Body} =
+                cassim:set_security(Db, SecDoc, Options),
+            HttpCode = http_code_from_status(Status),
+            ResponseHeaders = [{"Etag", Etag}],
+            send_json(Req, HttpCode, ResponseHeaders, Body);
+        false ->
+            SecObj = chttpd:json_body(Req),
+            case fabric:set_security(Db, SecObj, [{user_ctx, Ctx}]) of
+                ok ->
+                    send_json(Req, {[{<<"ok">>, true}]});
+                Else ->
+                    throw(Else)
+            end
+    end.
 
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").


[18/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Remove unnecessary pattern match and associated extraneous _rev check

The pattern match breaks when users submit _bulk_docs requests of the
format:

    {"docs": [[{"_id": "foo"}]]}

couch_doc:from_json_obj/1 already performs the appropriate _rev logic,
so that check is unnecessary.

BugzID: 21746


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

Branch: refs/heads/windsor-merge
Commit: 440f5a0ffedded1d33ba382810c7145c881d1f55
Parents: e6d115a
Author: Benjamin Anderson <b...@banjiewen.net>
Authored: Fri Aug 16 15:07:25 2013 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:06:18 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/440f5a0f/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index c81bf85..57b0c4f 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -320,21 +320,14 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
     case couch_util:get_value(<<"new_edits">>, JsonProps, true) of
     true ->
         Docs = lists:map(
-            fun({ObjProps} = JsonObj) ->
+            fun(JsonObj) ->
                 Doc = couch_doc:from_json_obj(JsonObj),
                 validate_attachment_names(Doc),
                 Id = case Doc#doc.id of
                     <<>> -> couch_uuids:new();
                     Id0 -> Id0
                 end,
-                case couch_util:get_value(<<"_rev">>, ObjProps) of
-                undefined ->
-                    Revs = {0, []};
-                Rev  ->
-                    {Pos, RevId} = couch_doc:parse_rev(Rev),
-                    Revs = {Pos, [RevId]}
-                end,
-                Doc#doc{id=Id,revs=Revs}
+                Doc#doc{id=Id}
             end,
             DocsArray),
         Options2 =


[47/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Log unexpected return value from att data fetch

BugzID: 30891


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

Branch: refs/heads/windsor-merge
Commit: 5e2f7c3ceba8ad3d355ea02cb0fc2c64e74f0fe6
Parents: 07c2603
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Mon May 19 16:52:01 2014 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/5e2f7c3c/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index f831389..c1a3297 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1363,8 +1363,13 @@ validate_attachment_name(Name) ->
 monitor_attachments(Atts) when is_list(Atts) ->
     lists:foldl(fun(Att, Monitors) ->
         case couch_att:fetch(data, Att) of
-            {Fd, _} -> [monitor(process, Fd) | Monitors];
-            _ -> Monitors
+            {Fd, _} ->
+                [monitor(process, Fd) | Monitors];
+            stub ->
+                Monitors;
+            Else ->
+                ?LOG_ERROR("~p from couch_att:fetch(data, ~p)", [Else, Att]),
+                Monitors
         end
     end, [], Atts);
 monitor_attachments(Att) ->


[35/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Fix JSON encoding for missing revisions

This is a super old bug from when we switched to Jiffy. Jiffy doesn't
support Erlang strings as object keys due to Unicode issues. This just
changes the "missing" string to a <<"missing">> binary.

BugzId: 26050


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

Branch: refs/heads/windsor-merge
Commit: 3f3e916b0dad1f27d6762ded2f57a4bcd6067030
Parents: 50ccf29
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Dec 11 11:11:52 2013 -0600
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:54:29 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/3f3e916b/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 7a1d69d..8491004 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -588,7 +588,7 @@ db_doc_req(#httpd{method='GET'}=Req, Db, DocId) ->
                         send_chunk(Resp, AccSeparator ++ Json);
                     {{not_found, missing}, RevId} ->
                         RevStr = couch_doc:rev_to_str(RevId),
-                        Json = ?JSON_ENCODE({[{"missing", RevStr}]}),
+                        Json = ?JSON_ENCODE({[{<<"missing">>, RevStr}]}),
                         send_chunk(Resp, AccSeparator ++ Json)
                     end,
                     "," % AccSeparator now has a comma
@@ -795,7 +795,7 @@ send_docs_multipart(Req, Results, Options1) ->
             end;
         ({{not_found, missing}, RevId}) ->
              RevStr = couch_doc:rev_to_str(RevId),
-             Json = ?JSON_ENCODE({[{"missing", RevStr}]}),
+             Json = ?JSON_ENCODE({[{<<"missing">>, RevStr}]}),
              couch_httpd:send_chunk(Resp,
                 [<<"\r\nContent-Type: application/json; error=\"true\"\r\n\r\n">>,
                 Json,


[36/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Improve HTTP error log formatting

The use of `~p` for binaries and stacks wasn't very useful. This just
changes things around as well as puts the stack on a new line indented
four spaces so that its readable.

BugzId: 26121


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

Branch: refs/heads/windsor-merge
Commit: d15303fb3316e2da610241ce7fd5f238e6907e04
Parents: 3f3e916
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Dec 12 12:38:10 2013 -0600
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:09 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d15303fb/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 372a61d..a783f91 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -893,8 +893,10 @@ maybe_decompress(Httpd, Body) ->
 log_error_with_stack_trace({bad_request, _, _}) ->
     ok;
 log_error_with_stack_trace({Error, Reason, Stack}) ->
-    couch_log:error("ref: ~p req_err ~p:~p ~p",
-             [stack_hash(Stack), Error, Reason, Stack]);
+    EFmt = if is_binary(Error) -> "~s"; true -> "~w" end,
+    RFmt = if is_binary(Reason) -> "~s"; true -> "~w" end,
+    Fmt = "req_err(~w) " ++ EFmt ++ " : " ++ RFmt ++ "~n    ~p",
+    couch_log:error(Fmt, [stack_hash(Stack), Error, Reason, Stack]);
 log_error_with_stack_trace(_) ->
     ok.
 


[33/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Ensure result of send_delayed_error is always a #delayed_resp

BugzID: 25402


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

Branch: refs/heads/windsor-merge
Commit: 516b6da41aff9e796f29b7ec6222da172a1d49f3
Parents: 63378df
Author: Robert Newson <ro...@cloudant.com>
Authored: Sat Nov 16 17:31:04 2013 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:53:43 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/516b6da4/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 0c9d0e0..93b56f0 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -637,9 +637,10 @@ send_delayed_chunk(#delayed_resp{}=DelayedResp, Chunk) ->
 send_delayed_last_chunk(Req) ->
     send_delayed_chunk(Req, []).
 
-send_delayed_error(#delayed_resp{req=Req,resp=nil}, Reason) ->
+send_delayed_error(#delayed_resp{req=Req,resp=nil}=DelayedResp, Reason) ->
     {Code, ErrorStr, ReasonStr} = error_info(Reason),
-    send_error(Req, Code, ErrorStr, ReasonStr);
+    {ok, Resp} = send_error(Req, Code, ErrorStr, ReasonStr),
+    {ok, DelayedResp#delayed_resp{resp=Resp}};
 send_delayed_error(#delayed_resp{resp=Resp}, Reason) ->
     log_stack_trace(json_stack(Reason)),
     throw({http_abort, Resp, Reason}).


[23/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Allows clients to send gzipped JSON bodies

A request with a Content-Encoding other than "gzip" or "identity" will
receive a 415 Unsupported Media Type response.

BugzID: 24000


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

Branch: refs/heads/windsor-merge
Commit: 6ffa347d94248325d7828bee7dfc1ff54ec262e2
Parents: b500211
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Oct 9 11:37:18 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:20:15 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/6ffa347d/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 08be216..82aab96 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -508,7 +508,7 @@ json_body(Httpd) ->
         undefined ->
             throw({bad_request, "Missing request body"});
         Body ->
-            ?JSON_DECODE(Body)
+            ?JSON_DECODE(maybe_decompress(Httpd, Body))
     end.
 
 json_body_obj(Httpd) ->
@@ -868,3 +868,13 @@ json_stack_item(_) ->
 
 json_stack_arity(A) ->
     if is_integer(A) -> A; is_list(A) -> length(A); true -> 0 end.
+
+maybe_decompress(Httpd, Body) ->
+    case header_value(Httpd, "Content-Encoding", "identity") of
+    "gzip" ->
+        zlib:gunzip(Body);
+    "identity" ->
+        Body;
+    Else ->
+        throw({bad_ctype, [Else, " is not a supported content encoding."]})
+    end.


[32/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
set module version to 1


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

Branch: refs/heads/windsor-merge
Commit: f4b0fdc95792e88d82ad37633a42594857e9c0ef
Parents: 516b6da
Author: Robert Newson <ro...@cloudant.com>
Authored: Fri Nov 22 16:44:56 2013 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:53:43 2014 +0100

----------------------------------------------------------------------
 src/chttpd_config_listener.erl | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/f4b0fdc9/src/chttpd_config_listener.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_config_listener.erl b/src/chttpd_config_listener.erl
index 4d07b83..cf90ab5 100644
--- a/src/chttpd_config_listener.erl
+++ b/src/chttpd_config_listener.erl
@@ -12,6 +12,7 @@
 
 -module(chttpd_config_listener).
 -behaviour(gen_server).
+-vsn(1).
 -behaviour(config_listener).
 
 % public interface


[12/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Throw HTTP 413 is max_document_size is exceeded

BugzID: 19888

This is a backport of
Apache/CouchDB@bf1eb135f2b46861474b9276dee02d8edb05fe3b


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

Branch: refs/heads/windsor-merge
Commit: 204ab913463792dd71d8be59468919d7a63b2091
Parents: 4816754
Author: Mike Wallace <mi...@googlemail.com>
Authored: Fri May 24 11:19:00 2013 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:34:16 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/204ab913/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 75fcf6d..6878fa5 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -219,6 +219,8 @@ handle_request(MochiReq) ->
             exit(normal);
         exit:{uri_too_long, _} ->
             send_error(HttpReq, request_uri_too_long);
+        exit:{body_too_large, _} ->
+            send_error(HttpReq, request_entity_too_large);
         throw:Error ->
             send_error(HttpReq, Error);
         error:database_does_not_exist ->
@@ -479,16 +481,8 @@ recv_chunked(#httpd{mochi_req=MochiReq}, MaxChunkSize, ChunkFun, InitState) ->
     % called with Length == 0 on the last time.
     MochiReq:stream_body(MaxChunkSize, ChunkFun, InitState).
 
-body_length(Req) ->
-    case header_value(Req, "Transfer-Encoding") of
-        undefined ->
-            case header_value(Req, "Content-Length") of
-                undefined -> undefined;
-                Length -> list_to_integer(Length)
-            end;
-        "chunked" -> chunked;
-        Unknown -> {unknown_transfer_encoding, Unknown}
-    end.
+body_length(#httpd{mochi_req=MochiReq}) ->
+    MochiReq:get(body_length).
 
 body(#httpd{mochi_req=MochiReq, req_body=ReqBody}) ->
     case ReqBody of
@@ -723,6 +717,8 @@ error_info({error, illegal_database_name}) ->
         "allowed. Moreover, the database name must begin with a letter.">>};
 error_info({missing_stub, Reason}) ->
     {412, <<"missing_stub">>, Reason};
+error_info(request_entity_too_large) ->
+    {413, <<"too_large">>, <<"the request entity is too large">>};
 error_info(not_implemented) ->
     {501, <<"not_implemented">>, <<"this feature is not yet implemented">>};
 error_info({Error, null}) ->


[04/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Use couch_httpd_db:parse_copy_destination_header

Remove parse_copy_destination_header and use the function defined
in couch_httpd_db instead.

Requires cloudant/dbcore@e9745834c164f6ef7f9e583bc4c36cdd83c415f4
so that parse_copy_destination_header is exported and has the
relevant backported code to throw an HTTP 400 if the COPY request
header does not have a Destination field.

BugzID: 18659


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

Branch: refs/heads/windsor-merge
Commit: 7932e0c056de758ba6b0fce026b28e07da23634d
Parents: 57697a8
Author: Mike Wallace <mi...@googlemail.com>
Authored: Tue Apr 2 13:45:33 2013 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:11:14 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/7932e0c0/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 8839eb1..eff1cbf 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -684,7 +684,7 @@ db_doc_req(#httpd{method='COPY', user_ctx=Ctx}=Req, Db, SourceDocId) ->
         missing_rev -> nil;
         Rev -> Rev
     end,
-    {TargetDocId, TargetRevs} = parse_copy_destination_header(Req),
+    {TargetDocId, TargetRevs} = couch_httpd_db:parse_copy_destination_header(Req),
     % open old doc
     Doc = couch_doc_open(Db, SourceDocId, SourceRev, []),
     % save new doc
@@ -1278,18 +1278,6 @@ extract_header_rev(Req, ExplicitRev) ->
     end.
 
 
-parse_copy_destination_header(Req) ->
-    Destination = chttpd:header_value(Req, "Destination"),
-    case re:run(Destination, "\\?", [{capture, none}]) of
-    nomatch ->
-        {list_to_binary(Destination), {0, []}};
-    match ->
-        [DocId, RevQs] = re:split(Destination, "\\?", [{return, list}]),
-        [_RevQueryKey, Rev] = re:split(RevQs, "=", [{return, list}]),
-        {Pos, RevId} = couch_doc:parse_rev(Rev),
-        {list_to_binary(DocId), {Pos, [RevId]}}
-    end.
-
 validate_attachment_names(Doc) ->
     lists:foreach(fun(#att{name=Name}) ->
         validate_attachment_name(Name)


[21/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Support "seq_interval" qs param on _changes

Supplying seq_interval=N will cause the changes feed to include a
sequence on every Nth row but set seq: null otherwise.  It's a
performance hack until we can deploy a more efficient format.

BugzID: 23637


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

Branch: refs/heads/windsor-merge
Commit: 34c147567dc1f94d2bdace0e456834fc4ddcd56a
Parents: 1fc39d2
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Tue Oct 1 21:47:50 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:17:33 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/34c14756/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 7d27bd9..a6c6594 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1224,6 +1224,7 @@ parse_doc_query(Req) ->
     end, #doc_query_args{}, chttpd:qs(Req)).
 
 parse_changes_query(Req) ->
+    erlang:erase(changes_seq_interval),
     ChangesArgs = lists:foldl(fun({Key, Value}, Args) ->
         case {string:to_lower(Key), Value} of
         {"feed", _} ->
@@ -1250,6 +1251,16 @@ parse_changes_query(Req) ->
             Args#changes_args{conflicts=true};
         {"filter", _} ->
             Args#changes_args{filter=Value};
+        {"seq_interval", _} ->
+            try list_to_integer(Value) of
+                V when V > 0 ->
+                    erlang:put(changes_seq_interval, V),
+                    Args;
+                _ ->
+                    throw({bad_request, invalid_seq_interval})
+            catch error:badarg ->
+                throw({bad_request, invalid_seq_interval})
+            end;
         _Else -> % unknown key value pair, ignore.
             Args
         end


[46/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Update chttpd_external with s/couch_httpd/chttpd/

Switch to using chttpd:send_{json,response} from chttpd_external so
that _show and _update functions are properly sending CORS headers.


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

Branch: refs/heads/windsor-merge
Commit: a456f88c2265e895421f131c504f1bb269edba99
Parents: 71d9709
Author: Russell Branca <ch...@gmail.com>
Authored: Fri Mar 28 10:25:46 2014 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_external.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/a456f88c/src/chttpd_external.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_external.erl b/src/chttpd_external.erl
index cfd13b2..d86e13f 100644
--- a/src/chttpd_external.erl
+++ b/src/chttpd_external.erl
@@ -126,9 +126,9 @@ send_external_response(Req, Response) ->
     Headers1 = default_or_content_type(CType, Headers),
     case Json of
     nil ->
-        couch_httpd:send_response(Req, Code, Headers1, Data);
+        chttpd:send_response(Req, Code, Headers1, Data);
     Json ->
-        couch_httpd:send_json(Req, Code, Headers1, Json)
+        chttpd:send_json(Req, Code, Headers1, Json)
     end.
 
 parse_external_response({Response}) ->


[42/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Isolate update_doc logic from http logic


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

Branch: refs/heads/windsor-merge
Commit: 58c203d422bdbbd4adf07c5e34cc96270daede18
Parents: 8d66fa4
Author: Russell Branca <ch...@gmail.com>
Authored: Wed Apr 9 15:04:19 2014 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 55 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/58c203d4/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 27ead6a..4741502 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -17,7 +17,8 @@
 -export([handle_request/1, handle_compact_req/2, handle_design_req/2,
     db_req/2, couch_doc_open/4,handle_changes_req/2,
     update_doc_result_to_json/1, update_doc_result_to_json/2,
-    handle_design_info_req/3, handle_view_cleanup_req/2]).
+    handle_design_info_req/3, handle_view_cleanup_req/2,
+    update_doc/4, http_code_from_status/1]).
 
 -import(chttpd,
     [send_json/2,send_json/3,send_json/4,send_method_not_allowed/2,
@@ -548,7 +549,7 @@ db_doc_req(#httpd{method='DELETE'}=Req, Db, DocId) ->
     Rev ->
         Body = {[{<<"_rev">>, ?l2b(Rev)},{<<"_deleted">>,true}]}
     end,
-    update_doc(Req, Db, DocId, couch_doc_from_req(Req, DocId, Body));
+    send_updated_doc(Req, Db, DocId, couch_doc_from_req(Req, DocId, Body));
 
 db_doc_req(#httpd{method='GET'}=Req, Db, DocId) ->
     #doc_query_args{
@@ -668,7 +669,7 @@ db_doc_req(#httpd{method='PUT', user_ctx=Ctx}=Req, Db, DocId) ->
                 fun() -> receive_request_data(Req) end),
         Doc = couch_doc_from_req(Req, DocId, Doc0),
         try
-            Result = update_doc(Req, Db, DocId, Doc, RespHeaders, UpdateType),
+            Result = send_updated_doc(Req, Db, DocId, Doc, RespHeaders, UpdateType),
             WaitFun(),
             Result
         catch throw:Err ->
@@ -698,7 +699,7 @@ db_doc_req(#httpd{method='PUT', user_ctx=Ctx}=Req, Db, DocId) ->
             % normal
             Body = chttpd:json_body(Req),
             Doc = couch_doc_from_req(Req, DocId, Body),
-            update_doc(Req, Db, DocId, Doc, RespHeaders, UpdateType)
+            send_updated_doc(Req, Db, DocId, Doc, RespHeaders, UpdateType)
         end
     end;
 
@@ -833,13 +834,13 @@ update_doc_result_to_json(DocId, Error) ->
     {[{id, DocId}, {error, ErrorStr}, {reason, Reason}]}.
 
 
-update_doc(Req, Db, DocId, Json) ->
-    update_doc(Req, Db, DocId, Json, []).
+send_updated_doc(Req, Db, DocId, Json) ->
+    send_updated_doc(Req, Db, DocId, Json, []).
 
-update_doc(Req, Db, DocId, Doc, Headers) ->
-    update_doc(Req, Db, DocId, Doc, Headers, interactive_edit).
+send_updated_doc(Req, Db, DocId, Doc, Headers) ->
+    send_updated_doc(Req, Db, DocId, Doc, Headers, interactive_edit).
 
-update_doc(#httpd{user_ctx=Ctx} = Req, Db, DocId, #doc{deleted=Deleted}=Doc,
+send_updated_doc(#httpd{user_ctx=Ctx} = Req, Db, DocId, #doc{deleted=Deleted}=Doc,
         Headers, UpdateType) ->
     W = couch_httpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db))),
     Options =
@@ -851,11 +852,23 @@ update_doc(#httpd{user_ctx=Ctx} = Req, Db, DocId, #doc{deleted=Deleted}=Doc,
         _ ->
             [UpdateType, {user_ctx,Ctx}, {w,W}]
         end,
-    {HttpCode, ResponseHeaders, Body} = update_doc_int(Db, DocId,
-        #doc{deleted=Deleted}=Doc, Headers, Options),
+    {Status, {etag, Etag}, Body} = update_doc(Db, DocId,
+        #doc{deleted=Deleted}=Doc, Options),
+    HttpCode = http_code_from_status(Status),
+    ResponseHeaders = [{"Etag", Etag} | Headers],
     send_json(Req, HttpCode, ResponseHeaders, Body).
 
-update_doc_int(Db, DocId, #doc{deleted=Deleted}=Doc, Headers, Options) ->
+http_code_from_status(Status) ->
+    case Status of
+        accepted ->
+            202;
+        created ->
+            201;
+        ok ->
+            200
+    end.
+
+update_doc(Db, DocId, #doc{deleted=Deleted}=Doc, Options) ->
     {_, Ref} = spawn_monitor(fun() ->
         try fabric:update_doc(Db, Doc, Options) of
             Resp ->
@@ -887,17 +900,17 @@ update_doc_int(Db, DocId, #doc{deleted=Deleted}=Doc, Headers, Options) ->
         Accepted = true
     end,
     NewRevStr = couch_doc:rev_to_str(NewRev),
-    ResponseHeaders = [{"Etag", <<"\"", NewRevStr/binary, "\"">>} | Headers],
-    case {Accepted, Deleted} of
-    {true, _} ->
-        HttpCode = 202;
-    {false, true} ->
-        HttpCode = 200;
-    {false, false} ->
-        HttpCode = 201
+    Etag = <<"\"", NewRevStr/binary, "\"">>,
+    Status = case {Accepted, Deleted} of
+        {true, _} ->
+            accepted;
+        {false, true} ->
+            ok;
+        {false, false} ->
+            created
     end,
     Body = {[{ok, true}, {id, DocId}, {rev, NewRevStr}]},
-    {HttpCode, ResponseHeaders, Body}.
+    {Status, {etag, Etag}, Body}.
 
 couch_doc_from_req(Req, DocId, #doc{revs=Revs} = Doc) ->
     validate_attachment_names(Doc),


[25/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Try to cancel a replication everywhere

Cancelation requests sometimes omit source and target information in
favor of a replication ID.  When that happens the logic that selects the
owner for the replication picks the wrong node, and the cancelation
fails with a not_found error.  This patch causes the request to be
submitted to all nodes in the cluster.  We report success if at least
one node reports success, otherwise we report (one of) the errors that
we received.

BugzID: 21976


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

Branch: refs/heads/windsor-merge
Commit: 2c4d2b3d201ef33411f6dccde61dfdfa9a028977
Parents: d86f68d
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Oct 16 13:23:14 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:22:24 2014 +0100

----------------------------------------------------------------------
 src/chttpd_misc.erl | 42 +++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/2c4d2b3d/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index cb83bc0..fcd8999 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -171,15 +171,39 @@ handle_replicate_req(Req) ->
     send_method_not_allowed(Req, "POST").
 
 replicate({Props} = PostBody, Ctx) ->
-    Node = choose_node([
-        couch_util:get_value(<<"source">>, Props),
-        couch_util:get_value(<<"target">>, Props)
-    ]),
-    case rpc:call(Node, couch_replicator, replicate, [PostBody, Ctx]) of
-    {badrpc, Reason} ->
-        erlang:error(Reason);
-    Res ->
-        Res
+    case couch_util:get_value(<<"cancel">>, Props) of
+    true ->
+        cancel_replication(PostBody, Ctx);
+    false ->
+        Node = choose_node([
+            couch_util:get_value(<<"source">>, Props),
+            couch_util:get_value(<<"target">>, Props)
+        ]),
+        case rpc:call(Node, couch_replicator, replicate, [PostBody, Ctx]) of
+        {badrpc, Reason} ->
+            erlang:error(Reason);
+        Res ->
+            Res
+        end
+    end.
+
+cancel_replication(PostBody, Ctx) ->
+    {Res, Bad} = rpc:multicall(couch_replicator, replicate, [PostBody, Ctx]),
+    case [X || {ok, {cancelled, _}} = X <- Res] of
+    [Success|_] ->
+        % Report success if at least one node canceled the replication
+        Success;
+    [] ->
+        case lists:usort(Res) of
+        [UniqueReply] ->
+            % Report a universally agreed-upon reply
+            UniqueReply;
+        [] ->
+            {error, badrpc};
+        Else ->
+            % Unclear what to do here -- pick the first error?
+            hd(Else)
+        end
     end.
 
 choose_node(Key) when is_binary(Key) ->


[06/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
 Add X-Couch-Update-NewRev and X-Couch-Id to _update response

This is porting commits from CouchDB:

ef7ab7e4e414d53fe5c12993d29b193ed3cdfd42
 - allow client to get new _rev from _update via X-Couch-Update-NewRev
 - I left out porting the JS test
98515bf0b990ca096ec5a47b9cd048427a0ec66c
 - Return X-Couch-Id from show functions if doc is created


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

Branch: refs/heads/windsor-merge
Commit: 31b7d4a721f3f5b7145575d70724f3c6a2d47372
Parents: 1e0c52a
Author: Michael Rhodes <mi...@gmail.com>
Authored: Sat Apr 6 21:54:47 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:12:06 2014 +0100

----------------------------------------------------------------------
 src/chttpd_show.erl | 48 +++++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/31b7d4a7/src/chttpd_show.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_show.erl b/src/chttpd_show.erl
index 7dc5337..18f64cb 100644
--- a/src/chttpd_show.erl
+++ b/src/chttpd_show.erl
@@ -119,27 +119,37 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
     JsonDoc = couch_query_servers:json_doc(Doc),
     Cmd = [<<"updates">>, UpdateName],
     W = couch_httpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db))),
-    case couch_query_servers:ddoc_prompt(DDoc, Cmd, [JsonDoc, JsonReq]) of
-    [<<"up">>, {NewJsonDoc}, JsonResp] ->
-        case chttpd:header_value(Req, "X-Couch-Full-Commit", "false") of
-        "true" ->
-            Options = [full_commit, {user_ctx, Req#httpd.user_ctx}, {w, W}];
-        _ ->
-            Options = [{user_ctx, Req#httpd.user_ctx}, {w, W}]
-        end,
-        NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
-        case fabric:update_doc(Db, NewDoc, Options) of
-        {ok, _} ->
-            Code = 201;
-        {accepted, _} ->
-            Code = 202
-        end;
-    [<<"up">>, _Other, JsonResp] ->
-        Code = 200
+    UpdateResp = couch_query_servers:ddoc_prompt(DDoc, Cmd, [JsonDoc, JsonReq]),
+    JsonResp = case UpdateResp of
+        [<<"up">>, {NewJsonDoc}, {JsonResp0}] ->
+            case chttpd:header_value(Req, "X-Couch-Full-Commit", "false") of
+            "true" ->
+                Options = [full_commit, {user_ctx, Req#httpd.user_ctx}, {w, W}];
+            _ ->
+                Options = [{user_ctx, Req#httpd.user_ctx}, {w, W}]
+            end,
+            NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
+            couch_doc:validate_docid(NewDoc#doc.id),
+            {UpdateResult, NewRev} = fabric:update_doc(Db, NewDoc, Options),
+            NewRevStr = couch_doc:rev_to_str(NewRev),
+            case {UpdateResult, NewRev} of
+            {ok, _} ->
+                Code = 201;
+            {accepted, _} ->
+                Code = 202
+            end,
+            {[
+                {<<"code">>, Code},
+                {<<"headers">>, {[
+                    {<<"X-Couch-Update-NewRev">>, NewRevStr},
+                    {<<"X-Couch-Id">>, NewDoc#doc.id}
+                ]}}
+                | JsonResp0]};
+        [<<"up">>, _Other, {JsonResp0}] ->
+            {[{<<"code">>, 200} | JsonResp0]}
     end,
-    JsonResp2 = json_apply_field({<<"code">>, Code}, JsonResp),
     % todo set location field
-    chttpd_external:send_external_response(Req, JsonResp2).
+    chttpd_external:send_external_response(Req, JsonResp).
 
 
 % view-list request with view and list from same design doc.


[10/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Reject large Range requests

Return a 200 response for any Range request that covers the entire entity
or that contains more than 10 byte ranges.

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1168196 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/windsor-merge
Commit: 0ba63fd341aef9f0762ae942178dc68f926940e7
Parents: e5ecb22
Author: Robert Newson <rn...@apache.org>
Authored: Sun Sep 11 10:50:11 2011 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:18:22 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/0ba63fd3/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 86653f9..cb13805 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -991,7 +991,7 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
                             {ok, Resp} = start_response_length(Req, 206, Headers1, To - From + 1),
                             couch_doc:range_att_foldl(Att, From, To + 1,
                                 fun(Seg, _) -> send(Resp, Seg) end, {ok, Resp});
-                        {identity, Ranges} when is_list(Ranges) ->
+                        {identity, Ranges} when is_list(Ranges) andalso length(Ranges) < 10 ->
                             send_ranges_multipart(Req, Type, Len, Att, Ranges);
                         _ ->
                             Headers1 = Headers ++
@@ -1126,8 +1126,9 @@ parse_ranges(Ranges, Len) ->
 
 parse_ranges([], _Len, Acc) ->
     lists:reverse(Acc);
-parse_ranges([{From, To}|_], _Len, _Acc)
-  when is_integer(From) andalso is_integer(To) andalso To < From ->
+parse_ranges([{0, none}|_], _Len, _Acc) ->
+    undefined;
+parse_ranges([{From, To}|_], _Len, _Acc) when is_integer(From) andalso is_integer(To) andalso To < From ->
     throw(requested_range_not_satisfiable);
 parse_ranges([{From, To}|Rest], Len, Acc)
   when is_integer(To) andalso To >= Len ->


[15/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Provide a dedicated NOLB mode

Setting [cloudant] maintenance_mode = nolb recovers the original
behavior of setting maintenance_mode to true; i.e., the node will not
participate in load balancing but is otherwise an active member of the
cluster.

BugzID: 18955


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

Branch: refs/heads/windsor-merge
Commit: 7bbf680d7c953b02f127dc00669fe5063062b9ee
Parents: 12ea8a3
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Fri Jun 7 11:17:31 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:01:48 2014 +0100

----------------------------------------------------------------------
 src/chttpd_misc.erl | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/7bbf680d/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 570df30..75f2676 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -296,6 +296,8 @@ handle_up_req(#httpd{method='GET'} = Req) ->
     case config:get("couchdb", "maintenance_mode") of
     "true" ->
         send_json(Req, 404, {[{status, maintenance_mode}]});
+    "nolb" ->
+        send_json(Req, 404, {[{status, nolb}]});
     _ ->
         send_json(Req, 200, {[{status, ok}]})
     end;


[26/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Fix unused variable warning


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

Branch: refs/heads/windsor-merge
Commit: 0d85df9ffb2e4af58c0cd2b825c55a7447e370ab
Parents: 2c4d2b3
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Oct 16 14:20:33 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:25:18 2014 +0100

----------------------------------------------------------------------
 src/chttpd_misc.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/0d85df9f/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index fcd8999..f4a643c 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -188,7 +188,7 @@ replicate({Props} = PostBody, Ctx) ->
     end.
 
 cancel_replication(PostBody, Ctx) ->
-    {Res, Bad} = rpc:multicall(couch_replicator, replicate, [PostBody, Ctx]),
+    {Res, _Bad} = rpc:multicall(couch_replicator, replicate, [PostBody, Ctx]),
     case [X || {ok, {cancelled, _}} = X <- Res] of
     [Success|_] ->
         % Report success if at least one node canceled the replication


[24/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add statistics for couch_db_updater message queues

BugzID: 24167


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

Branch: refs/heads/windsor-merge
Commit: d86f68d543c4667a06e8d617c661589a8eab5c46
Parents: 6ffa347
Author: Benjamin Anderson <b...@banjiewen.net>
Authored: Fri Oct 11 22:29:23 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:22:00 2014 +0100

----------------------------------------------------------------------
 src/chttpd_misc.erl | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d86f68d5/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 12b18f8..cb83bc0 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -266,8 +266,9 @@ handle_system_req(Req) ->
         processes_used, binary, code, ets])],
     {NumberOfGCs, WordsReclaimed, _} = statistics(garbage_collection),
     {{input, Input}, {output, Output}} = statistics(io),
-    CouchFile = {couch_file, {couch_file_stats()}},
-    MessageQueues = [CouchFile|message_queues(registered())],
+    {CF, CDU} = db_pid_stats(),
+    MessageQueues0 = [{couch_file, {CF}}, {couch_db_updater, {CDU}}],
+    MessageQueues = MessageQueues0 ++ message_queues(registered()),
     send_json(Req, {[
         {uptime, element(1,statistics(wall_clock)) div 1000},
         {memory, {Memory}},
@@ -288,9 +289,14 @@ handle_system_req(Req) ->
         {distribution, {get_distribution_stats()}}
     ]}).
 
-couch_file_stats() ->
+db_pid_stats() ->
     {monitors, M} = process_info(whereis(couch_stats_collector), monitors),
     Candidates = [Pid || {process, Pid} <- M],
+    CouchFiles = db_pid_stats(couch_file, Candidates),
+    CouchDbUpdaters = db_pid_stats(couch_db_updater, Candidates),
+    {CouchFiles, CouchDbUpdaters}.
+
+db_pid_stats(Mod, Candidates) ->
     Mailboxes = lists:foldl(
         fun(Pid, Acc) ->
             case process_info(Pid, [message_queue_len, dictionary]) of
@@ -299,7 +305,7 @@ couch_file_stats() ->
                 PI ->
                     Dictionary = proplists:get_value(dictionary, PI, []),
                     case proplists:get_value('$initial_call', Dictionary) of
-                        {couch_file, init, 1} ->
+                        {Mod, init, 1} ->
                             case proplists:get_value(message_queue_len, PI) of
                                 undefined -> Acc;
                                 Len -> [Len|Acc]


[40/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Move attachment code into couch_att

This is an attempt to isolate the attachment record and
some related code. This will allow seamless upgrades
over time.


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

Branch: refs/heads/windsor-merge
Commit: d6161e778e777c9fe972eb203a614bd473929dee
Parents: 6deefa1
Author: Brian Mitchell <br...@p2p.io>
Authored: Wed Dec 11 23:09:54 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:10 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 103 +++++++++++++++++++++++++++----------------------
 1 file changed, 56 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d6161e77/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 8491004..d9d720b 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -619,16 +619,19 @@ db_doc_req(#httpd{method='POST', user_ctx=Ctx}=Req, Db, DocId) ->
         {ok, [{ok, Doc}]} = fabric:open_revs(Db, DocId, [Rev], [])
     end,
     UpdatedAtts = [
-        #att{name=validate_attachment_name(Name),
-            type=list_to_binary(ContentType),
-            data=Content} ||
+        couch_att:new([
+            {name, validate_attachment_name(Name)},
+            {type, list_to_binary(ContentType)},
+            {data, Content}
+        ]) ||
         {Name, {ContentType, _}, Content} <-
         proplists:get_all_values("_attachments", Form)
     ],
     #doc{atts=OldAtts} = Doc,
     OldAtts2 = lists:flatmap(
-        fun(#att{name=OldName}=Att) ->
-            case [1 || A <- UpdatedAtts, A#att.name == OldName] of
+        fun(Att) ->
+            OldName = couch_att:fetch(name, Att),
+            case [1 || A <- UpdatedAtts, couch_att:fetch(name, A) == OldName] of
             [] -> [Att]; % the attachment wasn't in the UpdatedAtts, return it
             _ -> [] % the attachment was in the UpdatedAtts, drop it
             end
@@ -951,10 +954,11 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
     #doc{
         atts=Atts
     } = Doc = couch_doc_open(Db, DocId, Rev, Options),
-    case [A || A <- Atts, A#att.name == FileName] of
+    case [A || A <- Atts, couch_att:fetch(name, A) == FileName] of
     [] ->
         throw({not_found, "Document is missing attachment"});
-    [#att{type=Type, encoding=Enc, disk_len=DiskLen, att_len=AttLen}=Att] ->
+    [Att] ->
+        [Type, Enc, DiskLen, AttLen] = couch_att:fetch([type, encoding, disk_len, att_len], Att),
         Refs = monitor_attachments(Att),
         try
         Etag = chttpd:doc_etag(Doc),
@@ -1000,9 +1004,9 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
         end,
         AttFun = case ReqAcceptsAttEnc of
         false ->
-            fun couch_doc:att_foldl_decode/3;
+            fun couch_att:foldl_decode/3;
         true ->
-            fun couch_doc:att_foldl/3
+            fun couch_att:foldl/3
         end,
         chttpd:etag_respond(
             Req,
@@ -1020,14 +1024,14 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
                             Headers1 = [{<<"Content-Range">>, make_content_range(From, To, Len)}]
                                 ++ Headers,
                             {ok, Resp} = start_response_length(Req, 206, Headers1, To - From + 1),
-                            couch_doc:range_att_foldl(Att, From, To + 1,
+                            couch_att:range_foldl(Att, From, To + 1,
                                 fun(Seg, _) -> send(Resp, Seg) end, {ok, Resp});
                         {identity, Ranges} when is_list(Ranges) andalso length(Ranges) < 10 ->
                             send_ranges_multipart(Req, Type, Len, Att, Ranges);
                         _ ->
                             Headers1 = Headers ++
                                 if Enc =:= identity orelse ReqAcceptsAttEnc =:= true ->
-                                    [{"Content-MD5", base64:encode(Att#att.md5)}];
+                                    [{"Content-MD5", base64:encode(couch_att:fetch(md5, Att))}];
                                 true ->
                                     []
                             end,
@@ -1054,38 +1058,39 @@ db_attachment_req(#httpd{method=Method, user_ctx=Ctx}=Req, Db, DocId, FileNamePa
         'DELETE' ->
             [];
         _ ->
-            [#att{
-                name=FileName,
-                type = case couch_httpd:header_value(Req,"Content-Type") of
-                    undefined ->
-                        % We could throw an error here or guess by the FileName.
-                        % Currently, just giving it a default.
-                        <<"application/octet-stream">>;
-                    CType ->
-                        list_to_binary(CType)
-                    end,
-                data = fabric:att_receiver(Req, chttpd:body_length(Req)),
-                att_len = case couch_httpd:header_value(Req,"Content-Length") of
-                    undefined ->
-                        undefined;
-                    Length ->
-                        list_to_integer(Length)
-                    end,
-                md5 = get_md5_header(Req),
-                encoding = case string:to_lower(string:strip(
-                    couch_httpd:header_value(Req,"Content-Encoding","identity")
-                )) of
+            MimeType = case couch_httpd:header_value(Req,"Content-Type") of
+                % We could throw an error here or guess by the FileName.
+                % Currently, just giving it a default.
+                undefined -> <<"application/octet-stream">>;
+                CType -> list_to_binary(CType)
+            end,
+            Data = fabric:att_receiver(Req, chttpd:body_length(Req)),
+            ContentLen = case couch_httpd:header_value(Req,"Content-Length") of
+                undefined -> undefined;
+                Length -> list_to_integer(Length)
+            end,
+            ContentEnc = string:to_lower(string:strip(
+                couch_httpd:header_value(Req, "Content-Encoding", "identity")
+            )),
+            Encoding = case ContentEnc of
                 "identity" ->
-                   identity;
+                    identity;
                 "gzip" ->
-                   gzip;
+                    gzip;
                 _ ->
-                   throw({
-                       bad_ctype,
-                       "Only gzip and identity content-encodings are supported"
-                   })
-                end
-            }]
+                    throw({
+                        bad_ctype,
+                        "Only gzip and identity content-encodings are supported"
+                    })
+            end,
+            [couch_att:new([
+                {name, FileName},
+                {type, MimeType},
+                {data, Data},
+                {att_len, ContentLen},
+                {md5, get_md5_header(Req)},
+                {encoding, Encoding}
+            ])]
     end,
 
     Doc = case extract_header_rev(Req, couch_httpd:qs_value(Req, "rev")) of
@@ -1101,7 +1106,7 @@ db_attachment_req(#httpd{method=Method, user_ctx=Ctx}=Req, Db, DocId, FileNamePa
 
     #doc{atts=Atts} = Doc,
     DocEdited = Doc#doc{
-        atts = NewAtt ++ [A || A <- Atts, A#att.name /= FileName]
+        atts = NewAtt ++ [A || A <- Atts, couch_att:fetch(name, A) /= FileName]
     },
     case fabric:update_doc(Db, DocEdited, [{user_ctx,Ctx}]) of
     {ok, UpdatedRev} ->
@@ -1140,7 +1145,7 @@ send_ranges_multipart(Req, ContentType, Len, Att, Ranges) ->
             <<"\r\nContent-Type: ", ContentType/binary, "\r\n",
             "Content-Range: ", ContentRange/binary, "\r\n",
            "\r\n">>),
-        couch_doc:range_att_foldl(Att, From, To + 1,
+        couch_att:range_foldl(Att, From, To + 1,
             fun(Seg, _) -> send_chunk(Resp, Seg) end, {ok, Resp}),
         couch_httpd:send_chunk(Resp, <<"\r\n--", Boundary/binary>>)
     end, Ranges),
@@ -1327,7 +1332,8 @@ extract_header_rev(Req, ExplicitRev) ->
 
 
 validate_attachment_names(Doc) ->
-    lists:foreach(fun(#att{name=Name}) ->
+    lists:foreach(fun(Att) ->
+        Name = couch_att:fetch(name, Att),
         validate_attachment_name(Name)
     end, Doc#doc.atts).
 
@@ -1342,11 +1348,14 @@ validate_attachment_name(Name) ->
         false -> throw({bad_request, <<"Attachment name is not UTF-8 encoded">>})
     end.
 
--spec monitor_attachments(#att{} | [#att{}]) -> [reference()].
-monitor_attachments(#att{}=Att) ->
-    monitor_attachments([Att]);
+-spec monitor_attachments(couch_att:att() | [couch_att:att()]) -> [reference()].
 monitor_attachments(Atts) when is_list(Atts) ->
-    [monitor(process, Fd) || #att{data={Fd,_}} <- Atts].
+    lists:map(fun(Att) ->
+        {Fd, _} = couch_att:fetch(data, Att),
+        monitor(process, Fd)
+    end, Atts);
+monitor_attachments(Att) ->
+    monitor_attachments([Att]).
 
 demonitor_refs(Refs) when is_list(Refs) ->
     [demonitor(Ref) || Ref <- Refs].


[07/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Allow write quorum control in POST body

BugzID: 18457


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

Branch: refs/heads/windsor-merge
Commit: c90a4c0f602696fa6b6ccf9eda9ed5b5655488bc
Parents: 31b7d4a
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Apr 10 12:24:13 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:12:18 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/c90a4c0f/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index eff1cbf..18a1078 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -301,7 +301,12 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
     couch_httpd:validate_ctype(Req, "application/json"),
     {JsonProps} = chttpd:json_body_obj(Req),
     DocsArray = couch_util:get_value(<<"docs">>, JsonProps),
-    W = couch_httpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db))),
+    W = case couch_util:get_value(<<"w">>, JsonProps) of
+    Value when is_integer(Value) ->
+        Value;
+    _ ->
+        couch_httpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db)))
+    end,
     case chttpd:header_value(Req, "X-Couch-Full-Commit") of
     "true" ->
         Options = [full_commit, {user_ctx,Ctx}, {w,W}];


[49/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
honor ?rev for PUT and validate against _rev/etag

Fixes COUCHDB-1268

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1166945 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/windsor-merge
Commit: 71d9709102dee18b084d480a8ed933383a43f118
Parents: bcac53f
Author: Randall Leeds <ra...@apache.org>
Authored: Fri Sep 9 00:23:50 2011 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/71d97091/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index d9d720b..ae70aa3 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -900,18 +900,29 @@ update_doc(#httpd{user_ctx=Ctx} = Req, Db, DocId, #doc{deleted=Deleted}=Doc,
 
 couch_doc_from_req(Req, DocId, #doc{revs=Revs} = Doc) ->
     validate_attachment_names(Doc),
-    ExplicitDocRev =
-    case Revs of
-        {Start,[RevId|_]} -> {Start, RevId};
-        _ -> undefined
+    Rev = case couch_httpd:qs_value(Req, "rev") of
+    undefined ->
+        undefined;
+    QSRev ->
+        couch_doc:parse_rev(QSRev)
     end,
-    case extract_header_rev(Req, ExplicitDocRev) of
-    missing_rev ->
-        Revs2 = {0, []};
-    ExplicitDocRev ->
-        Revs2 = Revs;
-    {Pos, Rev} ->
-        Revs2 = {Pos, [Rev]}
+    Revs2 =
+    case Revs of
+    {Start, [RevId|_]} ->
+        if Rev /= undefined andalso Rev /= {Start, RevId} ->
+            throw({bad_request, "Document rev from request body and query "
+                   "string have different values"});
+        true ->
+            case extract_header_rev(Req, {Start, RevId}) of
+            missing_rev -> {0, []};
+            _ -> Revs
+            end
+        end;
+    _ ->
+        case extract_header_rev(Req, Rev) of
+        missing_rev -> {0, []};
+        {Pos, RevId2} -> {Pos, [RevId2]}
+        end
     end,
     Doc#doc{id=DocId, revs=Revs2};
 couch_doc_from_req(Req, DocId, Json) ->


[29/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Avoid VM log messages about uncaught errors

We defer doc updates to a child process so that we avoid mixing fabric
messages together between HTTP requests. This just makes the defer
cleaner so that the VM doesn't log when we throw a conflict error.

BugzId: 24264


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

Branch: refs/heads/windsor-merge
Commit: 5d50b2bb18219333f282572b1dd259321201055c
Parents: c14123f
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Oct 17 16:09:42 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Jul 30 11:17:44 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/5d50b2bb/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index b2b766b..7a1d69d 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -848,14 +848,29 @@ update_doc(#httpd{user_ctx=Ctx} = Req, Db, DocId, #doc{deleted=Deleted}=Doc,
         _ ->
             [UpdateType, {user_ctx,Ctx}, {w,W}]
         end,
-    {_, Ref} = spawn_monitor(fun() -> exit(fabric:update_doc(Db, Doc, Options)) end),
-    Result = receive {'DOWN', Ref, _, _, Res} -> Res end,
-    case Result of
-    {{nocatch, Exception}, _Reason} ->
-        % Exceptions from spawned processes are swallowed and returned, rethrow
-        throw(Exception);
-    _ ->
-        ok
+
+    {_, Ref} = spawn_monitor(fun() ->
+        try fabric:update_doc(Db, Doc, Options) of
+            Resp ->
+                exit({exit_ok, Resp})
+        catch
+            throw:Reason ->
+                exit({exit_throw, Reason});
+            error:Reason ->
+                exit({exit_error, Reason});
+            exit:Reason ->
+                exit({exit_exit, Reason})
+        end
+    end),
+    Result = receive
+        {'DOWN', Ref, _, _, {exit_ok, Ret}} ->
+            Ret;
+        {'DOWN', Ref, _, _, {exit_throw, Reason}} ->
+            throw(Reason);
+        {'DOWN', Ref, _, _, {exit_error, Reason}} ->
+            erlang:error(Reason);
+        {'DOWN', Ref, _, _, {exit_exit, Reason}} ->
+            erlang:exit(Reason)
     end,
 
     case Result of


[37/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add CORS support


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

Branch: refs/heads/windsor-merge
Commit: 6deefa1c34bb855ef9304ca2ea4f1f45a7df2193
Parents: 57d1078
Author: Robert Newson <rn...@apache.org>
Authored: Wed Jul 30 11:05:41 2014 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:10 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl      | 53 ++++++++++++++++++++++++++++++++----------------
 src/chttpd_cors.erl | 21 +++++++++++++++++++
 2 files changed, 56 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/6deefa1c/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index d671812..c41707f 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -200,10 +200,15 @@ handle_request(MochiReq) ->
     Result =
     try
         check_request_uri_length(RawUri),
-        case authenticate_request(HttpReq, AuthenticationFuns) of
-        #httpd{} = Req ->
-            HandlerFun = url_handler(HandlerKey),
-            HandlerFun(chttpd_auth_request:authorize_request(possibly_hack(Req)));
+        case chttpd_cors:is_preflight_request(HttpReq) of
+        #httpd{} ->
+            case authenticate_request(HttpReq, AuthenticationFuns) of
+            #httpd{} = Req ->
+                HandlerFun = url_handler(HandlerKey),
+                HandlerFun(chttpd_auth_request:authorize_request(possibly_hack(Req)));
+            Response ->
+                Response
+            end;
         Response ->
             Response
         end
@@ -407,8 +412,10 @@ primary_header_value(#httpd{mochi_req=MochiReq}, Key) ->
     MochiReq:get_primary_header_value(Key).
 
 serve_file(#httpd{mochi_req=MochiReq}=Req, RelativePath, DocumentRoot) ->
+    Headers = server_header() ++
+	couch_httpd_auth:cookie_auth_header(Req, []),
     {ok, MochiReq:serve_file(RelativePath, DocumentRoot,
-        server_header() ++ couch_httpd_auth:cookie_auth_header(Req, []))}.
+        chttpd_cors:headers(Req, Headers))}.
 
 qs_value(Req, Key) ->
     qs_value(Req, Key, undefined).
@@ -536,7 +543,8 @@ etag_respond(Req, CurrentEtag, RespFun) ->
     case etag_match(Req, CurrentEtag) of
     true ->
         % the client has this in their cache.
-        chttpd:send_response(Req, 304, [{"Etag", CurrentEtag}], <<>>);
+        Headers = chttpd_cors:headers(Req, [{"Etag", CurrentEtag}]),
+        chttpd:send_response(Req, 304, Headers, <<>>);
     false ->
         % Run the function.
         RespFun()
@@ -548,10 +556,12 @@ verify_is_server_admin(#httpd{user_ctx=#user_ctx{roles=Roles}}) ->
     false -> throw({unauthorized, <<"You are not a server admin.">>})
     end.
 
-start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Length) ->
+start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Length) ->
     couch_stats_collector:increment({httpd_status_codes, Code}),
-    Resp = MochiReq:start_response_length({Code, Headers ++ server_header() ++
-        couch_httpd_auth:cookie_auth_header(Req, Headers), Length}),
+    Headers = Headers0 ++ server_header() ++
+	couch_httpd_auth:cookie_auth_header(Req, Headers0),
+    Resp = MochiReq:start_response_length({Code,
+        chttpd_cors:headers(Req, Headers), Length}),
     case MochiReq:get(method) of
     'HEAD' -> throw({http_head_abort, Resp});
     _ -> ok
@@ -562,10 +572,12 @@ send(Resp, Data) ->
     Resp:send(Data),
     {ok, Resp}.
 
-start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
+start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
     couch_stats_collector:increment({httpd_status_codes, Code}),
-    Resp = MochiReq:respond({Code, Headers ++ server_header() ++
-        couch_httpd_auth:cookie_auth_header(Req, Headers), chunked}),
+    Headers = Headers0 ++ server_header() ++
+        couch_httpd_auth:cookie_auth_header(Req, Headers0),
+    Resp = MochiReq:respond({Code, chttpd_cors:headers(Req, Headers),
+        chunked}),
     case MochiReq:get(method) of
     'HEAD' -> throw({http_head_abort, Resp});
     _ -> ok
@@ -576,10 +588,12 @@ send_chunk(Resp, Data) ->
     Resp:write_chunk(Data),
     {ok, Resp}.
 
-send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
+send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Body) ->
     couch_stats_collector:increment({httpd_status_codes, Code}),
-    {ok, MochiReq:respond({Code, Headers ++ server_header() ++
-        couch_httpd_auth:cookie_auth_header(Req, Headers), Body})}.
+    Headers = Headers0 ++ server_header() ++
+	couch_httpd_auth:cookie_auth_header(Req, Headers0),
+    {ok, MochiReq:respond({Code, Headers, Body})}.
+
 
 send_method_not_allowed(Req, Methods) ->
     send_error(Req, 405, [{"Allow", Methods}], <<"method_not_allowed">>,
@@ -591,13 +605,15 @@ send_json(Req, Value) ->
 send_json(Req, Code, Value) ->
     send_json(Req, Code, [], Value).
 
-send_json(Req, Code, Headers, Value) ->
+send_json(Req, Code, Headers0, Value) ->
+    Headers = chttpd_cors:headers(Req, Headers0),
     couch_httpd:send_json(Req, Code, [timing(), reqid() | Headers], Value).
 
 start_json_response(Req, Code) ->
     start_json_response(Req, Code, []).
 
-start_json_response(Req, Code, Headers) ->
+start_json_response(Req, Code, Headers0) ->
+    Headers = chttpd_cors:headers(Req, Headers0),
     couch_httpd:start_json_response(Req, Code, [timing(), reqid() | Headers]).
 
 end_json_response(Resp) ->
@@ -840,7 +856,8 @@ send_chunked_error(Resp, Error) ->
     send_chunk(Resp, []).
 
 send_redirect(Req, Path) ->
-     Headers = [{"Location", chttpd:absolute_uri(Req, Path)}],
+     Headers = chttpd_cors:headers(Req,
+         [{"Location", chttpd:absolute_uri(Req, Path)}]),
      send_response(Req, 301, Headers, <<>>).
 
 server_header() ->

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/6deefa1c/src/chttpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_cors.erl b/src/chttpd_cors.erl
new file mode 100644
index 0000000..03ec289
--- /dev/null
+++ b/src/chttpd_cors.erl
@@ -0,0 +1,21 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(chttpd_cors).
+
+-export([is_preflight_request/1, headers/2]).
+
+is_preflight_request(Req) ->
+    couch_httpd_cors:is_preflight_request(Req).
+
+headers(Req, Headers) ->
+    couch_httpd_cors:cors_headers(Req, Headers).


[31/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Don't return stacktraces, log them instead.

BugzID: 17674


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

Branch: refs/heads/windsor-merge
Commit: 63378dfeeefa17621bb0fbb4f8f094029195c380
Parents: 1cc0ae3
Author: Robert Newson <ro...@cloudant.com>
Authored: Thu Nov 7 19:36:33 2013 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:53:33 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/63378dfe/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 7489d3a..0c9d0e0 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -234,8 +234,6 @@ handle_request(MochiReq) ->
                 {exit, normal, [{mochiweb_request, send, _} | _]} ->
                     exit(normal); % Client disconnect (R14)
                 _Else ->
-                    JsonStack = json_stack({Error, nil, Stack}),
-                    couch_log:error("req_err ~p:~p ~p", [Tag, Error, JsonStack]),
                     send_error(HttpReq, {Error, nil, Stack})
             end
     end,
@@ -643,6 +641,7 @@ send_delayed_error(#delayed_resp{req=Req,resp=nil}, Reason) ->
     {Code, ErrorStr, ReasonStr} = error_info(Reason),
     send_error(Req, Code, ErrorStr, ReasonStr);
 send_delayed_error(#delayed_resp{resp=Resp}, Reason) ->
+    log_stack_trace(json_stack(Reason)),
     throw({http_abort, Resp, Reason}).
 
 end_delayed_json_response(#delayed_resp{}=DelayedResp) ->
@@ -808,11 +807,16 @@ send_error(Req, Error) ->
 send_error(Req, Code, ErrorStr, ReasonStr) ->
     send_error(Req, Code, [], ErrorStr, ReasonStr, []).
 
-send_error(Req, Code, Headers, ErrorStr, ReasonStr, Stack) ->
+send_error(Req, Code, Headers, ErrorStr, ReasonStr, []) ->
     send_json(Req, Code, Headers,
         {[{<<"error">>,  ErrorStr},
-        {<<"reason">>, ReasonStr} |
-        case Stack of [] -> []; _ -> [{stack, Stack}] end
+        {<<"reason">>, ReasonStr}]});
+send_error(Req, Code, Headers, ErrorStr, ReasonStr, Stack) ->
+    log_stack_trace(Stack),
+    send_json(Req, Code, [stack_trace_id(Stack) | Headers],
+        {[{<<"error">>,  ErrorStr},
+        {<<"reason">>, ReasonStr},
+        {<<"ref">>, stack_hash(Stack)}
     ]}).
 
 % give the option for list functions to output html or other raw errors
@@ -821,11 +825,13 @@ send_chunked_error(Resp, {_Error, {[{<<"body">>, Reason}]}}) ->
     send_chunk(Resp, []);
 
 send_chunked_error(Resp, Error) ->
+    Stack = json_stack(Error),
+    log_stack_trace(Stack),
     {Code, ErrorStr, ReasonStr} = error_info(Error),
     JsonError = {[{<<"code">>, Code},
         {<<"error">>,  ErrorStr},
-        {<<"reason">>, ReasonStr} |
-        case json_stack(Error) of [] -> []; Stack -> [{stack, Stack}] end
+        {<<"reason">>, ReasonStr},
+        {<<"ref">>, stack_hash(Stack)}
     ]},
     send_chunk(Resp, ?l2b([$\n,?JSON_ENCODE(JsonError),$\n])),
     send_chunk(Resp, []).
@@ -882,3 +888,12 @@ maybe_decompress(Httpd, Body) ->
     Else ->
         throw({bad_ctype, [Else, " is not a supported content encoding."]})
     end.
+
+log_stack_trace(Stack) ->
+    couch_log:error("~p failed with trace: ~p", [stack_hash(Stack), Stack]).
+
+stack_trace_id(Stack) ->
+    {"X-Cloudant-Stack-Hash", stack_hash(Stack)}.
+
+stack_hash(Stack) ->
+    erlang:crc32(term_to_binary(Stack)).


[28/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Report pending count in _changes

BugzID: 24236


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

Branch: refs/heads/windsor-merge
Commit: c14123fdc6ff6ce0c69db6339160ad7c1c9cc6f0
Parents: 5dc3640
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Thu Oct 17 14:36:11 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Jul 30 11:17:38 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/c14123fd/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index a6c6594..b2b766b 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -88,9 +88,15 @@ changes_callback({change, Change}, {"continuous", Resp}) ->
     {ok, Resp1} = chttpd:send_delayed_chunk(Resp, [?JSON_ENCODE(Change) | "\n"]),
     {ok, {"continuous", Resp1}};
 changes_callback({stop, EndSeq0}, {"continuous", Resp}) ->
+    % Temporary upgrade clause - Case 24236
+    changes_callback({stop, EndSeq0, null}, {"continuous", Resp});
+changes_callback({stop, EndSeq0, Pending}, {"continuous", Resp}) ->
     EndSeq = case is_old_couch(Resp) of true -> 0; false -> EndSeq0 end,
-    {ok, Resp1} = chttpd:send_delayed_chunk(Resp,
-        [?JSON_ENCODE({[{<<"last_seq">>, EndSeq}]}) | "\n"]),
+    Row = {[
+        {<<"last_seq">>, EndSeq},
+        {<<"pending">>, Pending}
+    ]},
+    {ok, Resp1} = chttpd:send_delayed_chunk(Resp, [?JSON_ENCODE(Row) | "\n"]),
     chttpd:end_delayed_json_response(Resp1);
 
 % callbacks for eventsource feed (newline-delimited eventsource Objects)
@@ -130,13 +136,21 @@ changes_callback(start, {_, Req}) ->
 changes_callback({change, Change}, {Prepend, Resp}) ->
     {ok, Resp1} = chttpd:send_delayed_chunk(Resp, [Prepend, ?JSON_ENCODE(Change)]),
     {ok, {",\r\n", Resp1}};
-changes_callback({stop, EndSeq}, {_, Resp}) ->
+changes_callback({stop, EndSeq}, Acc) ->
+    % Temporary upgrade clause - Case 24236
+    changes_callback({stop, EndSeq, null}, Acc);
+changes_callback({stop, EndSeq, Pending}, {_, Resp}) ->
     {ok, Resp1} = case is_old_couch(Resp) of
     true ->
         chttpd:send_delayed_chunk(Resp, "\n],\n\"last_seq\":0}\n");
     false ->
-        chttpd:send_delayed_chunk(Resp,
-            ["\n],\n\"last_seq\":", ?JSON_ENCODE(EndSeq), "}\n"])
+        chttpd:send_delayed_chunk(Resp, [
+            "\n],\n\"last_seq\":",
+            ?JSON_ENCODE(EndSeq),
+            ",\"pending\":",
+            ?JSON_ENCODE(Pending),
+            "}\n"
+        ])
     end,
     chttpd:end_delayed_json_response(Resp1);
 


[27/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Wrap decompression in a try/catch, report 400

BugzID: 24000


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

Branch: refs/heads/windsor-merge
Commit: 5dc36408b1431754ca6d8dabb5dc5c465c617aa8
Parents: 0d85df9
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Oct 16 15:20:21 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:25:28 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/5dc36408/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 82aab96..7489d3a 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -872,7 +872,11 @@ json_stack_arity(A) ->
 maybe_decompress(Httpd, Body) ->
     case header_value(Httpd, "Content-Encoding", "identity") of
     "gzip" ->
-        zlib:gunzip(Body);
+        try
+            zlib:gunzip(Body)
+        catch error:data_error ->
+            throw({bad_request, "Request body is not properly gzipped."})
+        end;
     "identity" ->
         Body;
     Else ->


[13/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add _reload_query_servers, report stale proc count

BugzID: 19529


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

Branch: refs/heads/windsor-merge
Commit: 12ea8a313352567917bfbc2a1209904c1b9a88e2
Parents: 204ab91
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Thu Jun 6 12:13:00 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:01:43 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl      |  1 +
 src/chttpd_misc.erl | 31 ++++++++++++++++++++++++-------
 2 files changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/12ea8a31/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 6878fa5..632eb3d 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -360,6 +360,7 @@ url_handler("_utils") ->        fun chttpd_misc:handle_utils_dir_req/1;
 url_handler("_all_dbs") ->      fun chttpd_misc:handle_all_dbs_req/1;
 url_handler("_active_tasks") -> fun chttpd_misc:handle_task_status_req/1;
 url_handler("_config") ->       fun chttpd_misc:handle_config_req/1;
+url_handler("_reload_query_servers") -> fun chttpd_misc:handle_reload_query_servers_req/1;
 url_handler("_replicate") ->    fun chttpd_misc:handle_replicate_req/1;
 url_handler("_uuids") ->        fun chttpd_misc:handle_uuids_req/1;
 url_handler("_sleep") ->        fun chttpd_misc:handle_sleep_req/1;

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/12ea8a31/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 0a4badf..570df30 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -12,13 +12,24 @@
 
 -module(chttpd_misc).
 
--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_task_status_req/1,handle_sleep_req/1,handle_welcome_req/1,
-    handle_utils_dir_req/1, handle_favicon_req/1, handle_system_req/1,
-    handle_up_req/1]).
-
+-export([
+    handle_all_dbs_req/1,
+    handle_config_req/1,
+    handle_favicon_req/1,
+    handle_favicon_req/2,
+    handle_replicate_req/1,
+    handle_reload_query_servers_req/1,
+    handle_restart_req/1,
+    handle_sleep_req/1,
+    handle_system_req/1,
+    handle_task_status_req/1,
+    handle_up_req/1,
+    handle_utils_dir_req/1,
+    handle_utils_dir_req/2,
+    handle_uuids_req/1,
+    handle_welcome_req/1,
+    handle_welcome_req/2
+]).
 
 -include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
@@ -184,6 +195,11 @@ handle_restart_req(#httpd{method='POST'}=Req) ->
 handle_restart_req(Req) ->
     send_method_not_allowed(Req, "POST").
 
+handle_reload_query_servers_req(#httpd{method='POST'}=Req) ->
+    ok = couch_proc_manager:reload(),
+    send_json(Req, 200, {[{ok, true}]});
+handle_reload_query_servers_req(Req) ->
+    send_method_not_allowed(Req, "POST").
 
 handle_uuids_req(Req) ->
     couch_httpd_misc_handlers:handle_uuids_req(Req).
@@ -262,6 +278,7 @@ handle_system_req(Req) ->
         {io_input, Input},
         {io_output, Output},
         {os_proc_count, couch_proc_manager:get_proc_count()},
+        {stale_proc_count, couch_proc_manager:get_stale_proc_count()},
         {process_count, erlang:system_info(process_count)},
         {process_limit, erlang:system_info(process_limit)},
         {message_queues, message_queues(registered())},


[22/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add error formatting for maintenance mode

If all nodes end up in maintenance mode we need to report that progress
isn't possible due to a "nodedown".


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

Branch: refs/heads/windsor-merge
Commit: b50021125276e3d8042a2ca03b526c47181b562b
Parents: 34c1475
Author: Paul J. Davis <pa...@gmail.com>
Authored: Fri Oct 4 17:36:55 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:20:05 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/b5002112/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 982aa9a..08be216 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -705,6 +705,8 @@ error_info(file_exists) ->
         "created, the file already exists.">>};
 error_info({r_quorum_not_met, Reason}) ->
     {412, <<"read_quorum_not_met">>, Reason};
+error_info({maintenance_mode, Node}) ->
+    {412, <<"nodedown">>, Node};
 error_info({w_quorum_not_met, Reason}) ->
     {500, <<"write_quorum_not_met">>, Reason};
 error_info(request_uri_too_long) ->


[02/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Fix cancel by replication_id

BugzID: 17969


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

Branch: refs/heads/windsor-merge
Commit: ce262eedc429fe6d5fba6a6382e227895754899d
Parents: 43a2e96
Author: Robert Newson <ro...@cloudant.com>
Authored: Sun Mar 10 21:35:32 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 17:10:36 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/ce262eed/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index c9247c9..136a0a0 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -289,12 +289,17 @@ check_request_uri_length(Uri, MaxUriLen) when is_list(MaxUriLen) ->
     end.
 
 fix_uri(Req, Props, Type) ->
-    case is_http(replication_uri(Type, Props)) of
-    true ->
+    case replication_uri(Type, Props) of
+    undefined ->
         Props;
-    false ->
-        Uri = make_uri(Req,replication_uri(Type, Props)),
-        [{Type,Uri}|proplists:delete(Type,Props)]
+    Uri0 ->
+        case is_http(Uri0) of
+        true ->
+            Props;
+        false ->
+            Uri = make_uri(Req,replication_uri(Type, Props)),
+            [{Type,Uri}|proplists:delete(Type,Props)]
+        end
     end.
 
 replication_uri(Type, PostProps) ->


[14/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
allow case-insensitive content-type from external, and other cleanup

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@823378 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/windsor-merge
Commit: d98c8572637f655c7c5b9c52760ba8d36fb0886c
Parents: 7bbf680
Author: Adam Kocoloski <ko...@apache.org>
Authored: Fri Oct 9 01:54:48 2009 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:01:48 2014 +0100

----------------------------------------------------------------------
 src/chttpd_external.erl | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d98c8572/src/chttpd_external.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_external.erl b/src/chttpd_external.erl
index 4d07059..e8ea919 100644
--- a/src/chttpd_external.erl
+++ b/src/chttpd_external.erl
@@ -160,18 +160,10 @@ parse_external_response({Response}) ->
         end, #extern_resp_args{}, Response).
 
 default_or_content_type(DefaultContentType, Headers) ->
-    {ContentType, OtherHeaders} = lists:partition(
-        fun({HeaderName, _}) ->
-            HeaderName == "Content-Type"
-        end, Headers),
-
-    % XXX: What happens if we were passed multiple content types? We add another?
-    case ContentType of
-        [{"Content-Type", SetContentType}] ->
-            TrueContentType = SetContentType;
-        _Else ->
-            TrueContentType = DefaultContentType
-    end,
-
-    HeadersWithContentType = lists:append(OtherHeaders, [{"Content-Type", TrueContentType}]),
-    HeadersWithContentType.
+    IsContentType = fun({X, _}) -> string:to_lower(X) == "content-type" end,
+    case lists:any(IsContentType, Headers) of
+    false ->
+        [{"Content-Type", DefaultContentType} | Headers];
+    true ->
+        Headers
+    end.


[38/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Honor max_document_size when receiving body in externals

BugzID: 26773


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

Branch: refs/heads/windsor-merge
Commit: bcac53f776c52e29a5b8b4357f88ec585ef55e93
Parents: d6161e7
Author: Robert Newson <ro...@cloudant.com>
Authored: Wed Jan 8 18:05:57 2014 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:10 2014 +0100

----------------------------------------------------------------------
 src/chttpd_external.erl | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/bcac53f7/src/chttpd_external.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_external.erl b/src/chttpd_external.erl
index e8ea919..cfd13b2 100644
--- a/src/chttpd_external.erl
+++ b/src/chttpd_external.erl
@@ -61,7 +61,10 @@ json_req_obj(#httpd{mochi_req=Req,
                req_body=ReqBody
             }, Db, DocId) ->
     Body = case ReqBody of
-        undefined -> Req:recv_body();
+        undefined ->
+            MaxSize = list_to_integer(
+                config:get("couchdb", "max_document_size", "4294967296")),
+            Req:recv_body(MaxSize);
         Else -> Else
     end,
     ParsedForm = case Req:get_primary_header_value("content-type") of


[44/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Separate update doc and sending the response in update_doc


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

Branch: refs/heads/windsor-merge
Commit: 8d66fa43b0f0ab6a4c69db873a124b66dcb99571
Parents: 5e2f7c3
Author: Russell Branca <ch...@gmail.com>
Authored: Tue Apr 8 15:42:22 2014 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/8d66fa43/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index c1a3297..27ead6a 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -851,7 +851,11 @@ update_doc(#httpd{user_ctx=Ctx} = Req, Db, DocId, #doc{deleted=Deleted}=Doc,
         _ ->
             [UpdateType, {user_ctx,Ctx}, {w,W}]
         end,
+    {HttpCode, ResponseHeaders, Body} = update_doc_int(Db, DocId,
+        #doc{deleted=Deleted}=Doc, Headers, Options),
+    send_json(Req, HttpCode, ResponseHeaders, Body).
 
+update_doc_int(Db, DocId, #doc{deleted=Deleted}=Doc, Headers, Options) ->
     {_, Ref} = spawn_monitor(fun() ->
         try fabric:update_doc(Db, Doc, Options) of
             Resp ->
@@ -892,11 +896,8 @@ update_doc(#httpd{user_ctx=Ctx} = Req, Db, DocId, #doc{deleted=Deleted}=Doc,
     {false, false} ->
         HttpCode = 201
     end,
-    send_json(Req, HttpCode, ResponseHeaders, {[
-        {ok, true},
-        {id, DocId},
-        {rev, NewRevStr}
-    ]}).
+    Body = {[{ok, true}, {id, DocId}, {rev, NewRevStr}]},
+    {HttpCode, ResponseHeaders, Body}.
 
 couch_doc_from_req(Req, DocId, #doc{revs=Revs} = Doc) ->
     validate_attachment_names(Doc),


[16/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Return stats for couch_file mailboxes in _system requests


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

Branch: refs/heads/windsor-merge
Commit: 6c1f455e8c3a00b856f3be487e1837c0de87b4ed
Parents: d98c857
Author: Benjamin Anderson <b...@banjiewen.net>
Authored: Fri Aug 2 13:27:52 2013 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:02:57 2014 +0100

----------------------------------------------------------------------
 src/chttpd_misc.erl | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/6c1f455e/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 75f2676..62cd903 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -266,6 +266,8 @@ handle_system_req(Req) ->
         processes_used, binary, code, ets])],
     {NumberOfGCs, WordsReclaimed, _} = statistics(garbage_collection),
     {{input, Input}, {output, Output}} = statistics(io),
+    CouchFile = {couch_file, {couch_file_stats()}},
+    MessageQueues = [CouchFile|message_queues(registered())],
     send_json(Req, {[
         {uptime, element(1,statistics(wall_clock)) div 1000},
         {memory, {Memory}},
@@ -281,11 +283,40 @@ handle_system_req(Req) ->
         {stale_proc_count, couch_proc_manager:get_stale_proc_count()},
         {process_count, erlang:system_info(process_count)},
         {process_limit, erlang:system_info(process_limit)},
-        {message_queues, message_queues(registered())},
+        {message_queues, {MessageQueues}},
         {internal_replication_jobs, mem3_sync:get_backlog()},
         {distribution, {get_distribution_stats()}}
     ]}).
 
+couch_file_stats() ->
+    {monitors, M} = process_info(whereis(couch_stats_collector), monitors),
+    Candidates = [Pid || {process, Pid} <- M],
+    Mailboxes = lists:foldl(
+        fun(Pid, Acc) ->
+            PI = process_info(Pid, [message_queue_len, dictionary]),
+            Dictionary = proplists:get_value(dictionary, PI, []),
+            case proplists:get_value('$initial_call', Dictionary) of
+                {couch_file, init, 1} ->
+                    case proplists:get_value(message_queue_len, PI) of
+                        undefined -> Acc;
+                        Len -> [Len|Acc]
+                    end;
+                _  ->
+                    Acc
+            end
+        end, [], Candidates
+    ),
+    Sorted = lists:sort(Mailboxes),
+    Count = length(Sorted),
+    [
+        {count, Count},
+        {min, hd(Sorted)},
+        {max, lists:nth(Count, Sorted)},
+        {'50', lists:nth(round(Count * 0.5), Sorted)},
+        {'90', lists:nth(round(Count * 0.9), Sorted)},
+        {'99', lists:nth(round(Count * 0.99), Sorted)}
+    ].
+
 get_distribution_stats() ->
     lists:map(fun({Node, Socket}) ->
         {ok, Stats} = inet:getstat(Socket),
@@ -306,9 +337,8 @@ handle_up_req(Req) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
 message_queues(Registered) ->
-    Queues = lists:map(fun(Name) ->
+    lists:map(fun(Name) ->
         Type = message_queue_len,
         {Type, Length} = process_info(whereis(Name), Type),
         {Name, Length}
-    end, Registered),
-    {Queues}.
+    end, Registered).


[41/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Posted by rn...@apache.org.
Add the request id and timing info in chttpd:send_response


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

Branch: refs/heads/windsor-merge
Commit: 07bf741c809767a71a1066472f0851d275514eb4
Parents: a456f88
Author: Russell Branca <ch...@gmail.com>
Authored: Fri Mar 28 10:33:43 2014 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/07bf741c/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index c41707f..fab6695 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -591,7 +591,7 @@ send_chunk(Resp, Data) ->
 send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Body) ->
     couch_stats_collector:increment({httpd_status_codes, Code}),
     Headers = Headers0 ++ server_header() ++
-	couch_httpd_auth:cookie_auth_header(Req, Headers0),
+	[timing(), reqid() | couch_httpd_auth:cookie_auth_header(Req, Headers0)],
     {ok, MochiReq:respond({Code, Headers, Body})}.