couch-httpd commit: updated refs/heads/master to 6bb6e79

2016-03-01 Thread iilyak
Repository: couchdb-couch-httpd
Updated Branches:
  refs/heads/master [created] 6bb6e79ba


Add .gitignore


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

Branch: refs/heads/master
Commit: 6bb6e79ba57efbb8f4900e2ba95d1fc707f9218f
Parents: 
Author: ILYA Khlopotov 
Authored: Tue Mar 1 12:10:57 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 1 12:10:57 2016 -0800

--
 .gitignore | 13 +
 1 file changed, 13 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/6bb6e79b/.gitignore
--
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000..c1a4701
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+*.o
+*.so
+ebin/
+
+priv/couch_js/config.h
+priv/couchjs
+priv/couchspawnkillable
+priv/*.exp
+priv/*.lib
+vc120.pdb
+
+.rebar/
+.eunit



[30/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack to e44a372

2016-03-01 Thread iilyak
Bring validate_bind_address/1 from original


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

Branch: refs/heads/split_out_httpd_stack
Commit: a8e03e2f7c614bb171ad55149659035dcb91b28e
Parents: ebf1b53
Author: ILYA Khlopotov 
Authored: Fri Feb 26 09:55:27 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 1 08:35:08 2016 -0800

--
 src/couch_httpd.erl  | 10 +-
 src/couch_httpd_original.erl | 10 ++
 2 files changed, 11 insertions(+), 9 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/a8e03e2f/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 4f78bac..53b98e3 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -89,7 +89,8 @@
 -export([
 validate_ctype/2,
 validate_referer/1,
-validate_host/1
+validate_host/1,
+validate_bind_address/1
 ]).
 
 -export([
@@ -459,6 +460,13 @@ validate_host(#httpd{} = Req) ->
 ok
 end.
 
+validate_bind_address(any) -> ok;
+validate_bind_address(Address) ->
+case inet_parse:address(Address) of
+{ok, _} -> ok;
+_ -> throw({error, invalid_bind_address})
+end.
+
 host_for_request(#httpd{mochi_req = MochiReq}) ->
 XHost = config:get("httpd", "x_forwarded_host", "X-Forwarded-Host"),
 case MochiReq:get_header_value(XHost) of

http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/a8e03e2f/src/couch_httpd_original.erl
--
diff --git a/src/couch_httpd_original.erl b/src/couch_httpd_original.erl
index 8fa926b..abbce0e 100644
--- a/src/couch_httpd_original.erl
+++ b/src/couch_httpd_original.erl
@@ -23,7 +23,6 @@
 -export([send_error/2,send_error/4, send_chunked_error/2]).
 -export([handle_request_int/5]).
 
--export([validate_bind_address/1]).
 
 -import(couch_httpd, [
 server_header/0,
@@ -72,7 +71,8 @@
 start_chunked_response/3,
 validate_host/1,
 accepted_encodings/1,
-validate_referer/1
+validate_referer/1,
+validate_bind_address/1
 ]).
 
 -define(HANDLER_NAME_IN_MODULE_POS, 6).
@@ -558,12 +558,6 @@ send_chunked_error(Resp, Error) ->
 
 
 
-validate_bind_address(any) -> ok;
-validate_bind_address(Address) ->
-case inet_parse:address(Address) of
-{ok, _} -> ok;
-_ -> throw({error, invalid_bind_address})
-end.
 
 
  module tests below 



[10/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack to e44a372

2016-03-01 Thread iilyak
Bring log_request/2 from original


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

Branch: refs/heads/split_out_httpd_stack
Commit: d81ba2dd433a29a8954785f4f185ba3da87c93d9
Parents: 17375fd
Author: ILYA Khlopotov 
Authored: Thu Feb 25 11:06:48 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 1 08:35:07 2016 -0800

--
 src/couch_httpd.erl  | 15 +++
 src/couch_httpd_original.erl | 19 +++
 2 files changed, 18 insertions(+), 16 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/d81ba2dd/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 83c39cc..bf44e96 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -48,6 +48,7 @@
 ]).
 
 -export([
+log_request/2,
 server_header/0,
 send_chunk/2,
 last_chunk/1
@@ -487,6 +488,20 @@ chunked_response_buffer_size() ->
 %% 
 %% Helper functions
 
+log_request(#httpd{mochi_req=MochiReq,peer=Peer}=Req, Code) ->
+case erlang:get(dont_log_request) of
+true ->
+ok;
+_ ->
+couch_log:notice("~s - - ~s ~s ~B", [
+Peer,
+MochiReq:get(method),
+MochiReq:get(raw_path),
+Code
+]),
+gen_event:notify(couch_plugin, {log_request, Req, Code})
+end.
+
 server_header() ->
 [{"Server", "CouchDB/" ++ couch_server:get_version() ++
 " (Erlang OTP/" ++ erlang:system_info(otp_release) ++ ")"}].

http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/d81ba2dd/src/couch_httpd_original.erl
--
diff --git a/src/couch_httpd_original.erl b/src/couch_httpd_original.erl
index 3ac0a7e..b003fea 100644
--- a/src/couch_httpd_original.erl
+++ b/src/couch_httpd_original.erl
@@ -21,7 +21,7 @@
 
 -export([etag_match/2, etag_respond/3, etag_maybe/2]).
 
--export([start_chunked_response/3,send_chunk/2,log_request/2]).
+-export([start_chunked_response/3,send_chunk/2]).
 -export([start_response_length/4, start_response/3]).
 -export([send_response/4,send_error/2,send_error/4, send_chunked_error/2]).
 -export([parse_multipart_request/3]).
@@ -65,7 +65,8 @@
 send_method_not_allowed/2,
 send_redirect/2,
 absolute_uri/2,
-body/1
+body/1,
+log_request/2
 ]).
 
 -define(HANDLER_NAME_IN_MODULE_POS, 6).
@@ -509,20 +510,6 @@ verify_is_server_admin(#user_ctx{roles=Roles}) ->
 false -> throw({unauthorized, <<"You are not a server admin.">>})
 end.
 
-log_request(#httpd{mochi_req=MochiReq,peer=Peer}=Req, Code) ->
-case erlang:get(dont_log_request) of
-true ->
-ok;
-_ ->
-couch_log:notice("~s - - ~s ~s ~B", [
-Peer,
-MochiReq:get(method),
-MochiReq:get(raw_path),
-Code
-]),
-gen_event:notify(couch_plugin, {log_request, Req, Code})
-end.
-
 start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Length) ->
 log_request(Req, Code),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),



[1/2] couch commit: updated refs/heads/master to ad1f8bd

2016-03-15 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 07ba2c035 -> ad1f8bd96


Fix incorrect use of eunit fixtures


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

Branch: refs/heads/master
Commit: bc8f1862fb93503af02db5aad2cf144098daa2d0
Parents: 07ba2c0
Author: ILYA Khlopotov 
Authored: Mon Mar 14 08:58:33 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 12:28:48 2016 -0700

--
 test/couch_db_plugin_tests.erl | 52 ++---
 1 file changed, 20 insertions(+), 32 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bc8f1862/test/couch_db_plugin_tests.erl
--
diff --git a/test/couch_db_plugin_tests.erl b/test/couch_db_plugin_tests.erl
index 3222eb0..2fb6e3a 100644
--- a/test/couch_db_plugin_tests.erl
+++ b/test/couch_db_plugin_tests.erl
@@ -114,77 +114,65 @@ callback_test_() ->
 
 
 validate_dbname_match() ->
-?_assertMatch(
-{true, [validate_dbname, db]},
-couch_db_plugin:validate_dbname({true, [db]}, db)).
+?assert(couch_db_plugin:validate_dbname({true, [db]}, db)).
 
 validate_dbname_no_match() ->
-?_assertMatch(
-{false, [db]},
-couch_db_plugin:validate_dbname({false, [db]}, db)).
+?assertNot(couch_db_plugin:validate_dbname({false, [db]}, db)).
 
 validate_dbname_throw() ->
-?_assertThrow(
+?assertThrow(
 validate_dbname,
 couch_db_plugin:validate_dbname({fail, [db]}, db)).
 
 before_doc_update_match() ->
-?_assertMatch(
+?assertMatch(
 {true, [before_doc_update, doc]},
 couch_db_plugin:before_doc_update(#db{}, {true, [doc]})).
 
 before_doc_update_no_match() ->
-?_assertMatch(
+?assertMatch(
 {false, [doc]},
 couch_db_plugin:before_doc_update(#db{}, {false, [doc]})).
 
 before_doc_update_throw() ->
-?_assertThrow(
+?assertThrow(
 before_doc_update,
 couch_db_plugin:before_doc_update(#db{}, {fail, [doc]})).
 
 
 after_doc_read_match() ->
-?_assertMatch(
+?assertMatch(
 {true, [after_doc_read, doc]},
 couch_db_plugin:after_doc_read(#db{}, {true, [doc]})).
 
 after_doc_read_no_match() ->
-?_assertMatch(
+?assertMatch(
 {false, [doc]},
 couch_db_plugin:after_doc_read(#db{}, {false, [doc]})).
 
 after_doc_read_throw() ->
-?_assertThrow(
+?assertThrow(
 after_doc_read,
 couch_db_plugin:after_doc_read(#db{}, {fail, [doc]})).
 
 
 validate_docid_match() ->
-?_assertMatch(
-{true, [validate_docid, doc]},
-couch_db_plugin:validate_docid({true, [doc]})).
+?assert(couch_db_plugin:validate_docid({true, [doc]})).
 
 validate_docid_no_match() ->
-?_assertMatch(
-{false, [doc]},
-couch_db_plugin:validate_docid({false, [doc]})).
+?assertNot(couch_db_plugin:validate_docid({false, [doc]})).
 
 validate_docid_throw() ->
-?_assertThrow(
+?assertThrow(
 validate_docid,
 couch_db_plugin:validate_docid({fail, [doc]})).
 
 
 check_is_admin_match() ->
-?_assertMatch(
-true,
-couch_db_plugin:check_is_admin({true, [db]})).
+?assert(couch_db_plugin:check_is_admin({true, [db]})).
 
 check_is_admin_no_match() ->
-?assertMatch(
-false,
-couch_db_plugin:check_is_admin({false, [db]})).
+?assertNot(couch_db_plugin:check_is_admin({false, [db]})).
 
 check_is_admin_throw() ->
 ?assertThrow(
@@ -192,14 +180,14 @@ check_is_admin_throw() ->
 couch_db_plugin:check_is_admin({fail, [db]})).
 
 on_delete_match() ->
-?_assertMatch(
-true,
-couch_db_plugin:on_delete(true, [])).
+?assertMatch(
+   [true],
+   couch_db_plugin:on_delete(true, [])).
 
 on_delete_no_match() ->
-?_assertMatch(
-false,
-couch_db_plugin:on_delete(false, [])).
+?assertMatch(
+   [false],
+   couch_db_plugin:on_delete(false, [])).
 
 on_delete_throw() ->
 ?assertThrow(



[2/2] couch commit: updated refs/heads/master to ad1f8bd

2016-03-15 Thread iilyak
Merge remote branch 'github/pr/151'

This closes #151

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: ad1f8bd966329a4aa43015b8d9dc4746c5e490ef
Parents: 07ba2c0 bc8f186
Author: ILYA Khlopotov 
Authored: Tue Mar 15 12:29:37 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 12:29:37 2016 -0700

--
 test/couch_db_plugin_tests.erl | 52 ++---
 1 file changed, 20 insertions(+), 32 deletions(-)
--




[1/2] couch commit: updated refs/heads/master to 85d5406

2016-03-18 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master ad1f8bd96 -> 85d54067a


Fix time:sleep -> timer:sleep typo


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

Branch: refs/heads/master
Commit: 74caa6cd5b6ced758b731a15475696b6976c3cd8
Parents: ad1f8bd
Author: ILYA Khlopotov 
Authored: Wed Mar 16 07:05:27 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed Mar 16 07:05:27 2016 -0700

--
 test/couchdb_views_tests.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/74caa6cd/test/couchdb_views_tests.erl
--
diff --git a/test/couchdb_views_tests.erl b/test/couchdb_views_tests.erl
index ab0f6f2..289ecb8 100644
--- a/test/couchdb_views_tests.erl
+++ b/test/couchdb_views_tests.erl
@@ -288,7 +288,7 @@ couchdb_1309(DbName) ->
 ?assertNotEqual(IndexerPid, NewIndexerPid),
 UserCnt = case count_users(DbName) of
   N when N > 2 ->
-  time:sleep(1000),
+  timer:sleep(1000),
   count_users(DbName);
   N -> N
   end,



[1/6] chttpd commit: updated refs/heads/master to ab299eb

2016-03-15 Thread iilyak
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master 599b0953c -> ab299ebfc


Add test suite for chttpd_plugin

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 23faa75beedeea08ec9d758c0cd61572ab82db42
Parents: 1d7d0f1
Author: ILYA Khlopotov 
Authored: Tue Mar 8 12:30:00 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:43:56 2016 -0700

--
 test/chttpd_plugin_tests.erl | 189 ++
 1 file changed, 189 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/23faa75b/test/chttpd_plugin_tests.erl
--
diff --git a/test/chttpd_plugin_tests.erl b/test/chttpd_plugin_tests.erl
new file mode 100644
index 000..e8d68b5
--- /dev/null
+++ b/test/chttpd_plugin_tests.erl
@@ -0,0 +1,189 @@
+% 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_plugin_tests).
+
+-export([
+before_request/1,
+after_request/2,
+handle_error/1,
+before_response/4,
+before_serve_file/5
+]).
+
+-export([ %% couch_epi_plugin behaviour
+app/0,
+providers/0,
+services/0,
+data_providers/0,
+data_subscriptions/0,
+processes/0,
+notify/3
+]).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+%% couch_epi_plugin behaviour
+
+app() -> test_app.
+providers() -> [{chttpd, ?MODULE}].
+services() -> [].
+data_providers() -> [].
+data_subscriptions() -> [].
+processes() -> [].
+notify(_, _, _) -> ok.
+
+setup() ->
+application:stop(couch_epi), % in case it's already running from other 
tests...
+application:unload(couch_epi),
+ok = application:load(couch_epi),
+ok = application:set_env(couch_epi, plugins, [?MODULE]), % only this plugin
+ok = application:start(couch_epi).
+
+teardown(_) ->
+ok = application:stop(couch_epi),
+ok = application:unload(couch_epi).
+
+before_request({true, Id}) -> [{true, [{before_request, Id}]}];
+before_request({false, Id}) -> [{false, Id}];
+before_request({fail, Id}) -> throw({before_request, Id}).
+
+after_request({true, Id}, A) -> [{true, [{after_request, Id}]}, A];
+after_request({false, Id}, A) ->  [{false, Id}, A];
+after_request({fail, Id}, _A) -> throw({after_request, Id}).
+
+handle_error({true, Id}) -> [{true, [{handle_error, Id}]}];
+handle_error({false, Id}) -> [{false, Id}];
+handle_error({fail, Id}) -> throw({handle_error, Id}).
+
+before_response({true, Id}, A, B, C) ->
+[{true, [{before_response, Id}]}, A, B, C];
+before_response({false, Id}, A, B, C) ->
+[{false, Id}, A, B, C];
+before_response({fail, Id}, _A, _B, _C) ->
+throw({before_response, Id}).
+
+before_serve_file({true, Id}, A, B, C, D) ->
+[{true, [{before_serve_file, Id}]}, A, B, C, D];
+before_serve_file({false, Id}, A, B, C, D) ->
+[{false, Id}, A, B, C, D];
+before_serve_file({fail, _Id}, _A, _B, _C, _D) ->
+throw(before_serve_file).
+
+callback_test_() ->
+{
+"callback tests",
+{
+setup, fun setup/0, fun teardown/1,
+[
+fun before_request_match/0,
+fun before_request_no_match/0,
+fun before_request_throw/0,
+
+fun after_request_match/0,
+fun after_request_no_match/0,
+fun after_request_throw/0,
+
+fun handle_error_match/0,
+fun handle_error_no_match/0,
+fun handle_error_throw/0,
+
+fun before_response_match/0,
+fun before_response_no_match/0,
+fun before_response_throw/0,
+
+fun before_serve_file_match/0,
+fun before_serve_file_no_match/0,
+fun before_serve_file_throw/0
+]
+}
+}.
+
+
+before_request_match() ->
+?assertEqual(
+{ok, {true, [{before_request, foo}]}},
+chttpd_plugin:before_request({true, foo})).
+
+before_request_no_match() ->
+?assertEqual(
+   

[3/6] chttpd commit: updated refs/heads/master to ab299eb

2016-03-15 Thread iilyak
Extract basic_headers/2 function

COUCHDB-2966


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

Branch: refs/heads/master
Commit: b32f2b6cb4df9ee82b779bf5aa097bf006eca468
Parents: 599b095
Author: ILYA Khlopotov 
Authored: Tue Mar 8 08:32:24 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:43:56 2016 -0700

--
 src/chttpd.erl | 25 -
 1 file changed, 12 insertions(+), 13 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/b32f2b6c/src/chttpd.erl
--
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 56b6445..673465e 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -506,11 +506,8 @@ serve_file(Req, RelativePath, DocumentRoot) ->
 
 serve_file(#httpd{mochi_req=MochiReq}=Req, RelativePath, DocumentRoot,
ExtraHeaders) ->
-Headers = server_header() ++
-   couch_httpd_auth:cookie_auth_header(Req, []) ++
-   ExtraHeaders,
-Headers1 = chttpd_cors:headers(Req, Headers),
-{ok, MochiReq:serve_file(RelativePath, DocumentRoot, Headers1)}.
+Headers = basic_headers(Req, ExtraHeaders),
+{ok, MochiReq:serve_file(RelativePath, DocumentRoot, Headers)}.
 
 qs_value(Req, Key) ->
 qs_value(Req, Key, undefined).
@@ -660,10 +657,8 @@ 
verify_is_server_admin(#httpd{user_ctx=#user_ctx{roles=Roles}}) ->
 
 start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Length) 
->
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-Headers1 = Headers0 ++ server_header() ++
-   couch_httpd_auth:cookie_auth_header(Req, Headers0),
-Headers2 = chttpd_cors:headers(Req, Headers1),
-Resp = MochiReq:start_response_length({Code, Headers2, Length}),
+Headers1 = basic_headers(Req, Headers0),
+Resp = MochiReq:start_response_length({Code, Headers1, Length}),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -676,10 +671,8 @@ send(Resp, Data) ->
 
 start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-Headers1 = Headers0 ++ server_header() ++
-couch_httpd_auth:cookie_auth_header(Req, Headers0),
-Headers2 = chttpd_cors:headers(Req, Headers1),
-Resp = MochiReq:respond({Code, Headers2, chunked}),
+Headers1 = basic_headers(Req, Headers0),
+Resp = MochiReq:respond({Code, Headers1, chunked}),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -1068,3 +1061,9 @@ stack_hash(Stack) ->
 %% dedicated chunk.
 chunked_response_buffer_size() ->
 config:get_integer("httpd", "chunked_response_buffer", 1490).
+
+basic_headers(Req, Headers0) ->
+Headers = Headers0
+++ server_header()
+++ couch_httpd_auth:cookie_auth_header(Req, Headers0),
+chttpd_cors:headers(Req, Headers).



[5/6] chttpd commit: updated refs/heads/master to ab299eb

2016-03-15 Thread iilyak
Introduce chttpd_plugin:before_response/4 EPI hook

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 3d6f28189014fcc372930024a173fed3cb028899
Parents: 34bd294
Author: ILYA Khlopotov 
Authored: Tue Mar 8 10:24:49 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:43:56 2016 -0700

--
 src/chttpd.erl| 8 +---
 src/chttpd_plugin.erl | 8 +++-
 2 files changed, 12 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/3d6f2818/src/chttpd.erl
--
diff --git a/src/chttpd.erl b/src/chttpd.erl
index f653a3d..6ca1258 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -1066,9 +1066,11 @@ basic_headers(Req, Headers0) ->
 ++ couch_httpd_auth:cookie_auth_header(Req, Headers0),
 chttpd_cors:headers(Req, Headers).
 
-handle_response(Req, Code, Headers, Args, Type) ->
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-respond_(Req, Code, Headers, Args, Type).
+handle_response(Req0, Code0, Headers0, Args0, Type) ->
+{ok, {Req1, Code1, Headers1, Args1}} =
+chttpd_plugin:before_response(Req0, Code0, Headers0, Args0),
+couch_stats:increment_counter([couchdb, httpd_status_codes, Code1]),
+respond_(Req1, Code1, Headers1, Args1, Type).
 
 respond_(#httpd{mochi_req = MochiReq}, Code, Headers, _Args, start_response) ->
 MochiReq:start_response({Code, Headers});

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/3d6f2818/src/chttpd_plugin.erl
--
diff --git a/src/chttpd_plugin.erl b/src/chttpd_plugin.erl
index 711d0a9..7286b28 100644
--- a/src/chttpd_plugin.erl
+++ b/src/chttpd_plugin.erl
@@ -15,7 +15,8 @@
 -export([
 before_request/1,
 after_request/2,
-handle_error/1
+handle_error/1,
+before_response/4
 ]).
 
 -define(SERVICE_ID, chttpd).
@@ -38,6 +39,11 @@ handle_error(Error) ->
 [Error1] = with_pipe(handle_error, [Error]),
 Error1.
 
+before_response(HttpReq0, Code0, Headers0, Value0) ->
+[HttpReq, Code, Headers, Value] =
+with_pipe(before_response, [HttpReq0, Code0, Headers0, Value0]),
+{ok, {HttpReq, Code, Headers, Value}}.
+
 %% --
 %% Internal Function Definitions
 %% --



[4/6] couch commit: updated refs/heads/master to 171b751

2016-03-15 Thread iilyak
Extract handle_response function

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 1cb955aac81b8734aaf1b3366061f1f783022eb8
Parents: 4f80b40
Author: ILYA Khlopotov 
Authored: Tue Mar 8 08:53:21 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:14:17 2016 -0700

--
 src/couch_httpd.erl | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/1cb955aa/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index d4b56f8..7946788 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -659,10 +659,8 @@ log_response(Code, Body) ->
 end.
 
 start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Length) 
->
-log_request(Req, Code),
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = basic_headers(Req, Headers0),
-Resp = MochiReq:start_response_length({Code, Headers1, Length}),
+Resp = handle_response(Req, Code, Headers1, Length, start_response_length),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -670,10 +668,8 @@ start_response_length(#httpd{mochi_req=MochiReq}=Req, 
Code, Headers0, Length) ->
 {ok, Resp}.
 
 start_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
-log_request(Req, Code),
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = basic_headers(Req, Headers0),
-Resp = MochiReq:start_response({Code, Headers1}),
+Resp = handle_response(Req, Code, Headers1, undefined, start_response),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -704,10 +700,8 @@ http_1_0_keep_alive(Req, Headers) ->
 end.
 
 start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
-log_request(Req, Code),
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = add_headers(Req, Headers0),
-Resp = MochiReq:respond({Code, Headers1, chunked}),
+Resp = handle_response(Req, Code, Headers1, chunked, respond),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -730,12 +724,11 @@ send_response(Req, Code, Headers0, Body) ->
 send_response_no_cors(Req, Code, Headers1, Body).
 
 send_response_no_cors(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
-log_request(Req, Code),
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = http_1_0_keep_alive(MochiReq, Headers),
 Headers2 = basic_headers_no_cors(Req, Headers1),
+Resp = handle_response(Req, Code, Headers2, Body, respond),
 log_response(Code, Body),
-{ok, MochiReq:respond({Code, Headers2, Body})}.
+{ok, Resp}.
 
 send_method_not_allowed(Req, Methods) ->
 send_error(Req, 405, [{"Allow", Methods}], <<"method_not_allowed">>, 
?l2b("Only " ++ Methods ++ " allowed")).
@@ -1124,6 +1117,15 @@ basic_headers_no_cors(Req, Headers) ->
 ++ server_header()
 ++ couch_httpd_auth:cookie_auth_header(Req, Headers).
 
+handle_response(Req, Code, Headers, Args, Type) ->
+log_request(Req, Code),
+couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
+respond_(Req, Code, Headers, Args, Type).
+
+respond_(#httpd{mochi_req = MochiReq}, Code, Headers, _Args, start_response) ->
+MochiReq:start_response({Code, Headers});
+respond_(#httpd{mochi_req = MochiReq}, Code, Headers, Args, Type) ->
+MochiReq:Type({Code, Headers, Args}).
 
  module tests below 
 



[6/6] couch commit: updated refs/heads/master to 171b751

2016-03-15 Thread iilyak
Merge remote branch 'github/pr/150'

This closes #150

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 171b7513ab7c690e82696f6be2d605eaba3d5993
Parents: 9d28c57 3be6796
Author: ILYA Khlopotov 
Authored: Tue Mar 15 10:33:57 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:33:57 2016 -0700

--
 src/couch_httpd.erl | 91 
 1 file changed, 54 insertions(+), 37 deletions(-)
--




[2/6] couch commit: updated refs/heads/master to 171b751

2016-03-15 Thread iilyak
Add chttpd_plugin:before_serve_file/5 EPI hook

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 92283020d4fff94c82a077b4cb04d6b120f4cc2c
Parents: 44773a2
Author: ILYA Khlopotov 
Authored: Tue Mar 8 11:27:38 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:14:17 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/92283020/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 6a1289e..ebfa5c3 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -476,11 +476,14 @@ accepted_encodings(#httpd{mochi_req=MochiReq}) ->
 serve_file(Req, RelativePath, DocumentRoot) ->
 serve_file(Req, RelativePath, DocumentRoot, []).
 
-serve_file(#httpd{mochi_req=MochiReq}=Req, RelativePath, DocumentRoot,
-   ExtraHeaders) ->
-log_request(Req, 200),
-Headers = basic_headers(Req, ExtraHeaders),
-{ok, MochiReq:serve_file(RelativePath, DocumentRoot, Headers)}.
+serve_file(Req0, RelativePath0, DocumentRoot0, ExtraHeaders) ->
+Headers0 = basic_headers(Req0, ExtraHeaders),
+{ok, {Req1, Code1, Headers1, RelativePath1, DocumentRoot1}} =
+chttpd_plugin:before_serve_file(
+Req0, 200, Headers0, RelativePath0, DocumentRoot0),
+log_request(Req1, Code1),
+#httpd{mochi_req = MochiReq} = Req1,
+{ok, MochiReq:serve_file(RelativePath1, DocumentRoot1, Headers1)}.
 
 qs_value(Req, Key) ->
 qs_value(Req, Key, undefined).



[4/6] chttpd commit: updated refs/heads/master to ab299eb

2016-03-15 Thread iilyak
Extract handle_response function

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 34bd2946074dd1ecd6b1952d315e000b1c85007c
Parents: b32f2b6
Author: ILYA Khlopotov 
Authored: Tue Mar 8 08:57:55 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:43:56 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/34bd2946/src/chttpd.erl
--
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 673465e..f653a3d 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -656,9 +656,8 @@ 
verify_is_server_admin(#httpd{user_ctx=#user_ctx{roles=Roles}}) ->
 end.
 
 start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Length) 
->
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = basic_headers(Req, Headers0),
-Resp = MochiReq:start_response_length({Code, Headers1, Length}),
+Resp = handle_response(Req, Code, Headers1, Length, start_response_length),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -670,9 +669,8 @@ send(Resp, Data) ->
 {ok, Resp}.
 
 start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = basic_headers(Req, Headers0),
-Resp = MochiReq:respond({Code, Headers1, chunked}),
+Resp = handle_response(Req, Code, Headers1, chunked, respond),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -1067,3 +1065,12 @@ basic_headers(Req, Headers0) ->
 ++ server_header()
 ++ couch_httpd_auth:cookie_auth_header(Req, Headers0),
 chttpd_cors:headers(Req, Headers).
+
+handle_response(Req, Code, Headers, Args, Type) ->
+couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
+respond_(Req, Code, Headers, Args, Type).
+
+respond_(#httpd{mochi_req = MochiReq}, Code, Headers, _Args, start_response) ->
+MochiReq:start_response({Code, Headers});
+respond_(#httpd{mochi_req = MochiReq}, Code, Headers, Args, Type) ->
+MochiReq:Type({Code, Headers, Args}).



[2/6] chttpd commit: updated refs/heads/master to ab299eb

2016-03-15 Thread iilyak
Add chttpd_plugin:before_serve_file/5 EPI hook

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 1d7d0f168d0afb3f7bb27c3f9bedfbce5ae5de8b
Parents: 3d6f281
Author: ILYA Khlopotov 
Authored: Tue Mar 8 10:46:17 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:43:56 2016 -0700

--
 src/chttpd.erl| 6 ++
 src/chttpd_plugin.erl | 9 -
 2 files changed, 10 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/1d7d0f16/src/chttpd.erl
--
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 6ca1258..6e7682a 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -504,10 +504,8 @@ primary_header_value(#httpd{mochi_req=MochiReq}, Key) ->
 serve_file(Req, RelativePath, DocumentRoot) ->
 serve_file(Req, RelativePath, DocumentRoot, []).
 
-serve_file(#httpd{mochi_req=MochiReq}=Req, RelativePath, DocumentRoot,
-   ExtraHeaders) ->
-Headers = basic_headers(Req, ExtraHeaders),
-{ok, MochiReq:serve_file(RelativePath, DocumentRoot, Headers)}.
+serve_file(Req0, RelativePath0, DocumentRoot0, ExtraHeaders) ->
+couch_httpd:serve_file(Req0, RelativePath0, DocumentRoot0, ExtraHeaders).
 
 qs_value(Req, Key) ->
 qs_value(Req, Key, undefined).

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/1d7d0f16/src/chttpd_plugin.erl
--
diff --git a/src/chttpd_plugin.erl b/src/chttpd_plugin.erl
index 7286b28..7ab4581 100644
--- a/src/chttpd_plugin.erl
+++ b/src/chttpd_plugin.erl
@@ -16,7 +16,8 @@
 before_request/1,
 after_request/2,
 handle_error/1,
-before_response/4
+before_response/4,
+before_serve_file/5
 ]).
 
 -define(SERVICE_ID, chttpd).
@@ -44,6 +45,12 @@ before_response(HttpReq0, Code0, Headers0, Value0) ->
 with_pipe(before_response, [HttpReq0, Code0, Headers0, Value0]),
 {ok, {HttpReq, Code, Headers, Value}}.
 
+before_serve_file(Req0, Code0, Headers0, RelativePath0, DocumentRoot0) ->
+[HttpReq, Code, Headers, RelativePath, DocumentRoot] =
+with_pipe(before_serve_file, [
+Req0, Code0, Headers0, RelativePath0, DocumentRoot0]),
+{ok, {HttpReq, Code, Headers, RelativePath, DocumentRoot}}.
+
 %% --
 %% Internal Function Definitions
 %% --



[6/6] chttpd commit: updated refs/heads/master to ab299eb

2016-03-15 Thread iilyak
Merge remote branch 'github/pr/106'

This closes #106

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: ab299ebfcb833a819ccc9ddff3a2074ee25e0523
Parents: 599b095 23faa75
Author: ILYA Khlopotov 
Authored: Tue Mar 15 10:44:42 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:44:42 2016 -0700

--
 src/chttpd.erl   |  40 
 src/chttpd_plugin.erl|  15 ++-
 test/chttpd_plugin_tests.erl | 189 ++
 3 files changed, 226 insertions(+), 18 deletions(-)
--




[5/6] couch commit: updated refs/heads/master to 171b751

2016-03-15 Thread iilyak
Introduce chttpd_plugin:before_response/4 EPI hook

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 44773a2b0e936acbec301ba7afef3fb7a307e3b1
Parents: 1cb955a
Author: ILYA Khlopotov 
Authored: Tue Mar 8 10:23:20 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:14:17 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/44773a2b/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 7946788..6a1289e 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -1117,10 +1117,12 @@ basic_headers_no_cors(Req, Headers) ->
 ++ server_header()
 ++ couch_httpd_auth:cookie_auth_header(Req, Headers).
 
-handle_response(Req, Code, Headers, Args, Type) ->
-log_request(Req, Code),
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-respond_(Req, Code, Headers, Args, Type).
+handle_response(Req0, Code0, Headers0, Args0, Type) ->
+{ok, {Req1, Code1, Headers1, Args1}} =
+chttpd_plugin:before_response(Req0, Code0, Headers0, Args0),
+couch_stats:increment_counter([couchdb, httpd_status_codes, Code1]),
+log_request(Req0, Code1),
+respond_(Req1, Code1, Headers1, Args1, Type).
 
 respond_(#httpd{mochi_req = MochiReq}, Code, Headers, _Args, start_response) ->
 MochiReq:start_response({Code, Headers});



[3/6] couch commit: updated refs/heads/master to 171b751

2016-03-15 Thread iilyak
Use helper functions for headers generation

Following functions were introduced:

 - add_headers/2
 - basic_headers/2
 - basic_headers_no_cors/2

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 4f80b40666d9ac77d4bca038eb7bdbe9a9ff3a84
Parents: 9d28c57
Author: ILYA Khlopotov 
Authored: Tue Mar 8 08:29:58 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:14:17 2016 -0700

--
 src/couch_httpd.erl | 50 ++--
 1 file changed, 27 insertions(+), 23 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4f80b406/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 645176b..d4b56f8 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -479,11 +479,8 @@ serve_file(Req, RelativePath, DocumentRoot) ->
 serve_file(#httpd{mochi_req=MochiReq}=Req, RelativePath, DocumentRoot,
ExtraHeaders) ->
 log_request(Req, 200),
-ResponseHeaders = server_header()
-++ couch_httpd_auth:cookie_auth_header(Req, [])
-++ ExtraHeaders,
-ResponseHeaders1 = chttpd_cors:headers(Req, ResponseHeaders),
-{ok, MochiReq:serve_file(RelativePath, DocumentRoot, ResponseHeaders1)}.
+Headers = basic_headers(Req, ExtraHeaders),
+{ok, MochiReq:serve_file(RelativePath, DocumentRoot, Headers)}.
 
 qs_value(Req, Key) ->
 qs_value(Req, Key, undefined).
@@ -661,26 +658,22 @@ log_response(Code, Body) ->
 ok
 end.
 
-start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Length) ->
+start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Length) 
->
 log_request(Req, Code),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-Headers1 = Headers ++ server_header() ++
-   couch_httpd_auth:cookie_auth_header(Req, Headers),
-Headers2 = chttpd_cors:headers(Req, Headers1),
-Resp = MochiReq:start_response_length({Code, Headers2, Length}),
+Headers1 = basic_headers(Req, Headers0),
+Resp = MochiReq:start_response_length({Code, Headers1, Length}),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
 end,
 {ok, Resp}.
 
-start_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
+start_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
 log_request(Req, Code),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-CookieHeader = couch_httpd_auth:cookie_auth_header(Req, Headers),
-Headers1 = Headers ++ server_header() ++ CookieHeader,
-Headers2 = chttpd_cors:headers(Req, Headers1),
-Resp = MochiReq:start_response({Code, Headers2}),
+Headers1 = basic_headers(Req, Headers0),
+Resp = MochiReq:start_response({Code, Headers1}),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -699,6 +692,8 @@ no_resp_conn_header([{Hdr, _}|Rest]) ->
 _ -> no_resp_conn_header(Rest)
 end.
 
+http_1_0_keep_alive(#httpd{mochi_req = MochiReq}, Headers) ->
+http_1_0_keep_alive(MochiReq, Headers);
 http_1_0_keep_alive(Req, Headers) ->
 KeepOpen = Req:should_close() == false,
 IsHttp10 = Req:get(version) == {1, 0},
@@ -708,14 +703,11 @@ http_1_0_keep_alive(Req, Headers) ->
 false -> Headers
 end.
 
-start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
+start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0) ->
 log_request(Req, Code),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-Headers1 = http_1_0_keep_alive(MochiReq, Headers),
-Headers2 = Headers1 ++ server_header() ++
-   couch_httpd_auth:cookie_auth_header(Req, Headers1),
-Headers3 = chttpd_cors:headers(Req, Headers2),
-Resp = MochiReq:respond({Code, Headers3, chunked}),
+Headers1 = add_headers(Req, Headers0),
+Resp = MochiReq:respond({Code, Headers1, chunked}),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
 _ -> ok
@@ -741,8 +733,7 @@ send_response_no_cors(#httpd{mochi_req=MochiReq}=Req, Code, 
Headers, Body) ->
 log_request(Req, Code),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = http_1_0_keep_alive(MochiReq, Headers),
-Headers2 = Headers1 ++ server_header() ++
-   couch_httpd_auth:cookie_auth_header(Req, Headers1),
+Headers2 = 

[1/6] couch commit: updated refs/heads/master to 171b751

2016-03-15 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 9d28c5715 -> 171b7513a


Pass unencoded JsonObj to before_request

It is much easier to write epi plugins if the object
it receives is not encoded yet.
So we pass unencoded JSON object to chttpd_plugin:before_response

COUCHDB-2966


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

Branch: refs/heads/master
Commit: 3be679625e1054d897d6a905e895548ea7949b13
Parents: 9228302
Author: ILYA Khlopotov 
Authored: Thu Mar 10 07:53:43 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 10:14:17 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/3be67962/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index ebfa5c3..40f5c99 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -745,8 +745,7 @@ send_json(Req, Code, Value) ->
 send_json(Req, Code, Headers, Value) ->
 initialize_jsonp(Req),
 AllHeaders = maybe_add_default_headers(Req, Headers),
-Body = [start_jsonp(), ?JSON_ENCODE(Value), end_jsonp(), $\n],
-send_response(Req, Code, AllHeaders, Body).
+send_response(Req, Code, AllHeaders, {json, Value}).
 
 start_json_response(Req, Code) ->
 start_json_response(Req, Code, []).
@@ -1121,12 +1120,19 @@ basic_headers_no_cors(Req, Headers) ->
 ++ couch_httpd_auth:cookie_auth_header(Req, Headers).
 
 handle_response(Req0, Code0, Headers0, Args0, Type) ->
-{ok, {Req1, Code1, Headers1, Args1}} =
-chttpd_plugin:before_response(Req0, Code0, Headers0, Args0),
+{ok, {Req1, Code1, Headers1, Args1}} = before_response(Req0, Code0, 
Headers0, Args0),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code1]),
 log_request(Req0, Code1),
 respond_(Req1, Code1, Headers1, Args1, Type).
 
+before_response(Req0, Code0, Headers0, {json, JsonObj}) ->
+{ok, {Req1, Code1, Headers1, Body1}} =
+chttpd_plugin:before_response(Req0, Code0, Headers0, JsonObj),
+Body2 = [start_jsonp(), ?JSON_ENCODE(Body1), end_jsonp(), $\n],
+{ok, {Req1, Code1, Headers1, Body2}};
+before_response(Req0, Code0, Headers0, Args0) ->
+chttpd_plugin:before_response(Req0, Code0, Headers0, Args0).
+
 respond_(#httpd{mochi_req = MochiReq}, Code, Headers, _Args, start_response) ->
 MochiReq:start_response({Code, Headers});
 respond_(#httpd{mochi_req = MochiReq}, Code, Headers, Args, Type) ->



[1/2] couchdb commit: updated refs/heads/master to 266183a

2016-03-15 Thread iilyak
Repository: couchdb
Updated Branches:
  refs/heads/master d1ad70714 -> 266183aa0


Introduce chttpd_plugin:before_response

Update dependencies to include following EPI hooks:

 - chttpd_plugin:before_response/4
 - chttp_plugin:before_serve_file/5

COUCHDB-2966


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

Branch: refs/heads/master
Commit: a362cffec622f92006f61af54008d6ee966fa9f8
Parents: d1ad707
Author: ILYA Khlopotov 
Authored: Tue Mar 15 11:05:01 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 11:07:48 2016 -0700

--
 rebar.config.script | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb/blob/a362cffe/rebar.config.script
--
diff --git a/rebar.config.script b/rebar.config.script
index 6ad277b..6831b8c 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -30,8 +30,8 @@ DepDescs = [
 {cassim,   "cassim",   
"ab1ef1cee5f7b7ec1733e44845c1df99fc7a66a3"},
 {couch_log,"couch-log",
"e4abbd3874356dc7a201b09676e27ff7dc8bed7c"},
 {couch_log_lager,  "couch-log-lager",  
"b2a0471a87765de50c5eb05c65c121f68a9ae9fa"},
-{chttpd,   "chttpd",   
"599b0953c26da40850e43e9ca125940eff8a12e7"},
-{couch,"couch",
"9d28c5715be292d6028848dabafb41646c29b742"},
+{chttpd,   "chttpd",   
"ab299ebfcb833a819ccc9ddff3a2074ee25e0523"},
+{couch,"couch",
"171b7513ab7c690e82696f6be2d605eaba3d5993"},
 {couch_index,  "couch-index",  
"e8c8ca8b0bb66193f1ba7e4b1d7e4a3817d661ab"},
 {couch_mrview, "couch-mrview", 
"6ec35971ebd96133cc6a34fa29f1d364049a7ecd"},
 {couch_replicator, "couch-replicator", 
"197950631b8a73a8c36b744fc9eb00debc15ac03"},



[2/2] couchdb commit: updated refs/heads/master to 266183a

2016-03-15 Thread iilyak
Merge remote branch 'github/pr/391'

This closes #391

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 266183aa0946aee5a48cedac08ad81264888d3c6
Parents: d1ad707 a362cff
Author: ILYA Khlopotov 
Authored: Tue Mar 15 11:30:30 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 15 11:30:30 2016 -0700

--
 rebar.config.script | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
--




[2/2] couch commit: updated refs/heads/master to 05b40a8

2016-04-07 Thread iilyak
Merge remote branch 'github/pr/158'

This closes #158

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 05b40a8ef7e544b1313018d000f0c6d3d6255f1a
Parents: c256ef5 910770d
Author: ILYA Khlopotov 
Authored: Thu Apr 7 09:35:26 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Apr 7 09:35:26 2016 -0700

--
 src/couch_db.erl | 80 +--
 1 file changed, 77 insertions(+), 3 deletions(-)
--




couch commit: updated refs/heads/master to 79c98d8

2016-04-07 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 05b40a8ef -> 79c98d8ce


Revert "Merge remote branch 'github/pr/158'"

This reverts commit 05b40a8ef7e544b1313018d000f0c6d3d6255f1a, reversing
changes made to c256ef5d098dce5b9624e117dab912205334c327.


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

Branch: refs/heads/master
Commit: 79c98d8ceef2004350c6c3086c083ee021f3a854
Parents: 05b40a8
Author: ILYA Khlopotov 
Authored: Thu Apr 7 10:50:54 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Apr 7 10:50:54 2016 -0700

--
 src/couch_db.erl | 80 ++-
 1 file changed, 3 insertions(+), 77 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/79c98d8c/src/couch_db.erl
--
diff --git a/src/couch_db.erl b/src/couch_db.erl
index c34d59a..1a9f669 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -1513,8 +1513,10 @@ select_gt(V1, _V2) -> V1.
 select_lt(V1, V2) when V1 > V2 -> V2;
 select_lt(V1, _V2) -> V1.
 
+normalize_dbname(<<"shards/", _/binary>> = Path) ->
+lists:last(binary:split(mem3:dbname(Path), <<"/">>, [global]));
 normalize_dbname(DbName) ->
-mem3:dbname(DbName).
+DbName.
 
 validate_dbname(DbName) when is_list(DbName) ->
 validate_dbname(?l2b(DbName));
@@ -1544,79 +1546,3 @@ is_systemdb(<<"shards/", _/binary>> = Path) when 
is_binary(Path) ->
 is_systemdb(normalize_dbname(Path));
 is_systemdb(DbName) when is_binary(DbName) ->
 lists:member(DbName, ?SYSTEM_DATABASES).
-
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
-
-setup() ->
-ok = meck:new(couch_db_plugin, [passthrough]),
-ok = meck:expect(couch_db_plugin, validate_dbname, fun(_, _) -> false end),
-ok.
-
-teardown(_) ->
-(catch meck:unload(couch_db_plugin)).
-
-validate_dbname_success_test_() ->
-Cases =
-generate_cases_with_shards("long/co$mplex-/path+/_something")
-++ generate_cases_with_shards("something")
-++ lists:append(
-[generate_cases_with_shards(?b2l(SystemDb))
-|| SystemDb <- ?SYSTEM_DATABASES]),
-{
-foreach, fun setup/0, fun teardown/1,
-[{test_name(A), fun() -> should_pass_validate_dbname(A) end} || {_, A} 
<- Cases]
-}.
-
-validate_dbname_fail_test_() ->
-Cases = generate_cases("_long/co$mplex-/path+/_something")
-   ++ generate_cases("_something")
-   ++ generate_cases_with_shards("long/co$mplex-/path+/_something#")
-   ++ generate_cases_with_shards("long/co$mplex-/path+/some.thing"),
-{
-foreach, fun setup/0, fun teardown/1,
-[{test_name(A), fun() -> should_fail_validate_dbname(A) end} || {_, A} 
<- Cases]
-}.
-
-validate_normalize_dbname_test_() ->
-Cases = generate_cases_with_shards("long/co$mplex-/path+/_something")
-   ++ generate_cases_with_shards("something"),
-[{test_name(B), fun() -> should_normalize_dbname(A, B) end} || {A, B} <- 
Cases].
-
-
-should_pass_validate_dbname(DbName) ->
-{test_name(DbName), ?_assertEqual(ok, validate_dbname(DbName))}.
-
-should_fail_validate_dbname(DbName) ->
-{test_name(DbName), ?_test(begin
-Result = validate_dbname(DbName),
-?assertMatch({error, {illegal_database_name, _}}, Result),
-{error, {illegal_database_name, FailedDbName}} = Result,
-?assertEqual(to_binary(DbName), FailedDbName),
-ok
-end)}.
-
-should_normalize_dbname(Arg, DbName) ->
-Result = ?l2b(filename:rootname(Arg)),
-{test_name(DbName), ?_assertEqual(Result, normalize_dbname(DbName))}.
-
-to_binary(DbName) when is_list(DbName) ->
-?l2b(DbName);
-to_binary(DbName) when is_binary(DbName) ->
-DbName.
-
-test_name(DbName) ->
-lists:flatten(io_lib:format("~p", [DbName])).
-
-generate_cases_with_shards(DbName) ->
-DbNameWithShard = add_shard(DbName),
-Cases = [DbName, ?l2b(DbName), DbNameWithShard, ?l2b(DbNameWithShard)],
-[{DbName, Case} || Case <- Cases].
-
-add_shard(DbName) ->
-"shards/-3fff/" ++ DbName ++ ".1415960794".
-
-generate_cases(DbName) ->
-[{DbName, DbName}, {DbName, ?l2b(DbName)}].
-
--endif.



[1/2] couch commit: updated refs/heads/master to 05b40a8

2016-04-07 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master c256ef5d0 -> 05b40a8ef


Fix normalize_dbname to work with slashes

We shouldn't rely on dbname being the last part of path. Since database
name could include slashes.
normalize_dbname as the name suggests should accept either binary or
list and return only binary.


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

Branch: refs/heads/master
Commit: 910770d3faf0a23bd8dfb08abc6906fe45de4a41
Parents: c256ef5
Author: ILYA Khlopotov 
Authored: Wed Mar 30 15:02:52 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Apr 7 09:34:19 2016 -0700

--
 src/couch_db.erl | 80 +--
 1 file changed, 77 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/910770d3/src/couch_db.erl
--
diff --git a/src/couch_db.erl b/src/couch_db.erl
index 1a9f669..c34d59a 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -1513,10 +1513,8 @@ select_gt(V1, _V2) -> V1.
 select_lt(V1, V2) when V1 > V2 -> V2;
 select_lt(V1, _V2) -> V1.
 
-normalize_dbname(<<"shards/", _/binary>> = Path) ->
-lists:last(binary:split(mem3:dbname(Path), <<"/">>, [global]));
 normalize_dbname(DbName) ->
-DbName.
+mem3:dbname(DbName).
 
 validate_dbname(DbName) when is_list(DbName) ->
 validate_dbname(?l2b(DbName));
@@ -1546,3 +1544,79 @@ is_systemdb(<<"shards/", _/binary>> = Path) when 
is_binary(Path) ->
 is_systemdb(normalize_dbname(Path));
 is_systemdb(DbName) when is_binary(DbName) ->
 lists:member(DbName, ?SYSTEM_DATABASES).
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+setup() ->
+ok = meck:new(couch_db_plugin, [passthrough]),
+ok = meck:expect(couch_db_plugin, validate_dbname, fun(_, _) -> false end),
+ok.
+
+teardown(_) ->
+(catch meck:unload(couch_db_plugin)).
+
+validate_dbname_success_test_() ->
+Cases =
+generate_cases_with_shards("long/co$mplex-/path+/_something")
+++ generate_cases_with_shards("something")
+++ lists:append(
+[generate_cases_with_shards(?b2l(SystemDb))
+|| SystemDb <- ?SYSTEM_DATABASES]),
+{
+foreach, fun setup/0, fun teardown/1,
+[{test_name(A), fun() -> should_pass_validate_dbname(A) end} || {_, A} 
<- Cases]
+}.
+
+validate_dbname_fail_test_() ->
+Cases = generate_cases("_long/co$mplex-/path+/_something")
+   ++ generate_cases("_something")
+   ++ generate_cases_with_shards("long/co$mplex-/path+/_something#")
+   ++ generate_cases_with_shards("long/co$mplex-/path+/some.thing"),
+{
+foreach, fun setup/0, fun teardown/1,
+[{test_name(A), fun() -> should_fail_validate_dbname(A) end} || {_, A} 
<- Cases]
+}.
+
+validate_normalize_dbname_test_() ->
+Cases = generate_cases_with_shards("long/co$mplex-/path+/_something")
+   ++ generate_cases_with_shards("something"),
+[{test_name(B), fun() -> should_normalize_dbname(A, B) end} || {A, B} <- 
Cases].
+
+
+should_pass_validate_dbname(DbName) ->
+{test_name(DbName), ?_assertEqual(ok, validate_dbname(DbName))}.
+
+should_fail_validate_dbname(DbName) ->
+{test_name(DbName), ?_test(begin
+Result = validate_dbname(DbName),
+?assertMatch({error, {illegal_database_name, _}}, Result),
+{error, {illegal_database_name, FailedDbName}} = Result,
+?assertEqual(to_binary(DbName), FailedDbName),
+ok
+end)}.
+
+should_normalize_dbname(Arg, DbName) ->
+Result = ?l2b(filename:rootname(Arg)),
+{test_name(DbName), ?_assertEqual(Result, normalize_dbname(DbName))}.
+
+to_binary(DbName) when is_list(DbName) ->
+?l2b(DbName);
+to_binary(DbName) when is_binary(DbName) ->
+DbName.
+
+test_name(DbName) ->
+lists:flatten(io_lib:format("~p", [DbName])).
+
+generate_cases_with_shards(DbName) ->
+DbNameWithShard = add_shard(DbName),
+Cases = [DbName, ?l2b(DbName), DbNameWithShard, ?l2b(DbNameWithShard)],
+[{DbName, Case} || Case <- Cases].
+
+add_shard(DbName) ->
+"shards/-3fff/" ++ DbName ++ ".1415960794".
+
+generate_cases(DbName) ->
+[{DbName, DbName}, {DbName, ?l2b(DbName)}].
+
+-endif.



[2/2] couch commit: updated refs/heads/master to 85d5406

2016-03-19 Thread iilyak
Merge remote branch 'github/pr/152'

This closes #152

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 85d54067ae3e4eba61273a16c9f5c8f285deb3e2
Parents: ad1f8bd 74caa6c
Author: ILYA Khlopotov 
Authored: Wed Mar 16 07:35:28 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed Mar 16 07:35:28 2016 -0700

--
 test/couchdb_views_tests.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--




[1/3] chttpd commit: updated refs/heads/master to cefabd0

2016-03-22 Thread iilyak
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master ab299ebfc -> cefabd0ec


Use couch_tests applications for chttpd_plugin_tests


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

Branch: refs/heads/master
Commit: 46de497cddf2785e7afdf7f3f5c92132b819a762
Parents: ab299eb
Author: ILYA Khlopotov 
Authored: Thu Mar 17 10:36:53 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Mar 17 10:36:53 2016 -0700

--
 test/chttpd_plugin_tests.erl | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/46de497c/test/chttpd_plugin_tests.erl
--
diff --git a/test/chttpd_plugin_tests.erl b/test/chttpd_plugin_tests.erl
index e8d68b5..4b6334f 100644
--- a/test/chttpd_plugin_tests.erl
+++ b/test/chttpd_plugin_tests.erl
@@ -43,16 +43,14 @@ data_subscriptions() -> [].
 processes() -> [].
 notify(_, _, _) -> ok.
 
+
 setup() ->
-application:stop(couch_epi), % in case it's already running from other 
tests...
-application:unload(couch_epi),
-ok = application:load(couch_epi),
-ok = application:set_env(couch_epi, plugins, [?MODULE]), % only this plugin
-ok = application:start(couch_epi).
-
-teardown(_) ->
-ok = application:stop(couch_epi),
-ok = application:unload(couch_epi).
+couch_tests:setup([
+couch_epi_dispatch:dispatch(chttpd, ?MODULE)
+], [], []).
+
+teardown(Ctx) ->
+couch_tests:teardown(Ctx).
 
 before_request({true, Id}) -> [{true, [{before_request, Id}]}];
 before_request({false, Id}) -> [{false, Id}];



[2/3] chttpd commit: updated refs/heads/master to cefabd0

2016-03-22 Thread iilyak
Use couch_tests:setup/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/54e8f614
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/54e8f614
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/54e8f614

Branch: refs/heads/master
Commit: 54e8f6147486d9afc5245e0143d15a4dd1185654
Parents: 46de497
Author: ILYA Khlopotov 
Authored: Thu Mar 17 10:59:01 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Mar 17 10:59:01 2016 -0700

--
 test/chttpd_plugin_tests.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/54e8f614/test/chttpd_plugin_tests.erl
--
diff --git a/test/chttpd_plugin_tests.erl b/test/chttpd_plugin_tests.erl
index 4b6334f..36572a4 100644
--- a/test/chttpd_plugin_tests.erl
+++ b/test/chttpd_plugin_tests.erl
@@ -47,7 +47,7 @@ notify(_, _, _) -> ok.
 setup() ->
 couch_tests:setup([
 couch_epi_dispatch:dispatch(chttpd, ?MODULE)
-], [], []).
+]).
 
 teardown(Ctx) ->
 couch_tests:teardown(Ctx).



[3/3] chttpd commit: updated refs/heads/master to cefabd0

2016-03-22 Thread iilyak
Merge remote branch 'github/pr/108'

This closes #108

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: cefabd0ece7db0e1cf4bf4abe7214d226340280a
Parents: ab299eb 54e8f61
Author: ILYA Khlopotov 
Authored: Tue Mar 22 05:33:56 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 22 05:33:56 2016 -0700

--
 test/chttpd_plugin_tests.erl | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)
--




[3/3] couch commit: updated refs/heads/master to 5fa9098

2016-03-22 Thread iilyak
Merge remote branch 'github/pr/154'

This closes #154

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 5fa90987132c275b30183f48f02e347c648cfc28
Parents: b4295bf 0a45b3f
Author: ILYA Khlopotov 
Authored: Tue Mar 22 05:35:03 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 22 05:35:03 2016 -0700

--
 test/couch_db_plugin_tests.erl | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)
--




[2/3] couch commit: updated refs/heads/master to 5fa9098

2016-03-22 Thread iilyak
Use couch_tests:setup/1


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

Branch: refs/heads/master
Commit: 0a45b3f58ab11962c0dcbaeda7519a07a4520cea
Parents: 2a7387c
Author: ILYA Khlopotov 
Authored: Thu Mar 17 10:58:26 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Mar 17 10:58:26 2016 -0700

--
 test/couch_db_plugin_tests.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/0a45b3f5/test/couch_db_plugin_tests.erl
--
diff --git a/test/couch_db_plugin_tests.erl b/test/couch_db_plugin_tests.erl
index 3f69e79..337207e 100644
--- a/test/couch_db_plugin_tests.erl
+++ b/test/couch_db_plugin_tests.erl
@@ -47,7 +47,7 @@ notify(_, _, _) -> ok.
 setup() ->
 couch_tests:setup([
 couch_epi_dispatch:dispatch(chttpd, ?MODULE)
-], [], []).
+]).
 
 teardown(Ctx) ->
 couch_tests:teardown(Ctx).



[1/3] couch commit: updated refs/heads/master to 5fa9098

2016-03-22 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master b4295bfe5 -> 5fa909871


Use couch_tests applications for couch_db_plugin_tests


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

Branch: refs/heads/master
Commit: 2a7387c6009c147bf7a5901345bd3239df70d1e0
Parents: b4295bf
Author: ILYA Khlopotov 
Authored: Thu Mar 17 10:43:43 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Mar 17 10:43:43 2016 -0700

--
 test/couch_db_plugin_tests.erl | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2a7387c6/test/couch_db_plugin_tests.erl
--
diff --git a/test/couch_db_plugin_tests.erl b/test/couch_db_plugin_tests.erl
index 2fb6e3a..3f69e79 100644
--- a/test/couch_db_plugin_tests.erl
+++ b/test/couch_db_plugin_tests.erl
@@ -45,15 +45,12 @@ processes() -> [].
 notify(_, _, _) -> ok.
 
 setup() ->
-application:stop(couch_epi), % in case it's already running from other 
tests...
-application:unload(couch_epi),
-ok = application:load(couch_epi),
-ok = application:set_env(couch_epi, plugins, [?MODULE]), % only this plugin
-ok = application:start(couch_epi).
-
-teardown(_) ->
-ok = application:stop(couch_epi),
-ok = application:unload(couch_epi).
+couch_tests:setup([
+couch_epi_dispatch:dispatch(chttpd, ?MODULE)
+], [], []).
+
+teardown(Ctx) ->
+couch_tests:teardown(Ctx).
 
 validate_dbname({true, _Db}, _) -> true;
 validate_dbname({false, _Db}, _) -> false;



[2/2] couchdb commit: updated refs/heads/master to 3ee8d2f

2016-03-24 Thread iilyak
Merge remote branch 'github/pr/397'

This closes #397

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 3ee8d2f04ac79671ea0a09625f2382d63e5e4f4c
Parents: 479aa2d efe9ad7
Author: ILYA Khlopotov 
Authored: Thu Mar 24 09:51:49 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Mar 24 09:51:49 2016 -0700

--
 rebar.config.script | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--




[1/2] couchdb commit: updated refs/heads/master to 3ee8d2f

2016-03-24 Thread iilyak
Repository: couchdb
Updated Branches:
  refs/heads/master 479aa2d85 -> 3ee8d2f04


Update couch_epi to fix test suite


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

Branch: refs/heads/master
Commit: efe9ad78d7a00f6c29684b2e453df508776468c0
Parents: 479aa2d
Author: ILYA Khlopotov 
Authored: Wed Mar 23 06:38:28 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed Mar 23 06:38:28 2016 -0700

--
 rebar.config.script | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb/blob/efe9ad78/rebar.config.script
--
diff --git a/rebar.config.script b/rebar.config.script
index 3badecd..b727eef 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -23,7 +23,7 @@ os:putenv("COUCHDB_APPS_CONFIG_DIR", 
filename:join([COUCHDB_ROOT, "rel/apps"])).
 
 DepDescs = [
 %% must be compiled first as it has a custom behavior
-{couch_epi,"couch-epi",
"de32c655443d75d58cd36cef2bd6b4c67b6a91b6"},
+{couch_epi,"couch-epi",
"5a7f2868c720bc428e6c888dc61d988b9a5f63f1"},
 {config,   "config",   
"a2d5ad2eedc960248b806f61df0a1009462bdb46"},
 %% keep these sorted
 {b64url,   "b64url",   
"319fc604235ab1fde37047b38a432450161db750"},



[2/2] couchdb-couch-epi git commit: Merge remote branch 'github/pr/18'

2016-03-23 Thread iilyak
Merge remote branch 'github/pr/18'

This closes #18

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 5a7f2868c720bc428e6c888dc61d988b9a5f63f1
Parents: de32c65 6fe3b2a
Author: ILYA Khlopotov 
Authored: Wed Mar 23 06:32:09 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed Mar 23 06:32:09 2016 -0700

--
 test/couch_epi_tests.erl | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)
--




[1/2] couchdb-couch-epi git commit: Don't rely on timer:sleep after update in tests

2016-03-23 Thread iilyak
Repository: couchdb-couch-epi
Updated Branches:
  refs/heads/master de32c6554 -> 5a7f2868c


Don't rely on timer:sleep after update in tests

To fix currently broken build we do not use timer:sleep/1 after update/2.


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

Branch: refs/heads/master
Commit: 6fe3b2a3d80dd6ab4a667ddb02f2f5833a4eda64
Parents: de32c65
Author: ILYA Khlopotov 
Authored: Tue Mar 22 16:47:33 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 22 16:47:33 2016 -0700

--
 test/couch_epi_tests.erl | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/6fe3b2a3/test/couch_epi_tests.erl
--
diff --git a/test/couch_epi_tests.erl b/test/couch_epi_tests.erl
index 56733b1..bde85a8 100644
--- a/test/couch_epi_tests.erl
+++ b/test/couch_epi_tests.erl
@@ -364,7 +364,6 @@ ensure_notified_when_changed(functions, #ctx{key = Key} = 
Ctx) ->
 ?_test(begin
 subscribe(Ctx, test_app, Key),
 update(functions, Ctx),
-timer:sleep(200),
 Result = get(Ctx, is_called),
 ExpectedDefs = [
 {provider1,[{inc,2},{fail,2}]},
@@ -377,7 +376,6 @@ ensure_notified_when_changed(Case, #ctx{key = Key} = Ctx) ->
 ?_test(begin
 subscribe(Ctx, test_app, Key),
 update(Case, Ctx),
-timer:sleep(200),
 ExpectedData = lists:usort([
 {[complex, key, 1], [{type, counter}, {desc, updated_foo}]},
 {[complex, key, 2], [{type, counter}, {desc, bar}]}
@@ -560,7 +558,8 @@ generate_module(Name, Body) ->
 
 update(Case, #ctx{pid = Pid, modules = Modules} = Ctx) ->
 update_definitions(Case, Ctx),
-upgrade_release(Pid, Modules).
+upgrade_release(Pid, Modules),
+wait_update(Ctx).
 
 update_definitions(data_file, #ctx{file = File}) ->
 {ok, _} = file:copy(?DATA_FILE2, File),
@@ -582,6 +581,14 @@ maybe_wait(Opts) ->
 ok
 end.
 
+wait_update(Ctx) ->
+case get(Ctx, is_called) of
+error ->
+timer:sleep(100),
+wait_update(Ctx);
+_ -> ok
+end.
+
 %% 
 %% State tracer
 



[1/3] couchdb commit: updated refs/heads/master to 479aa2d

2016-03-22 Thread iilyak
Repository: couchdb
Updated Branches:
  refs/heads/master 3f7a26c39 -> 479aa2d85


Introduce couch_tests application to share setups


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

Branch: refs/heads/master
Commit: b1090d69d91470793211e9364a84835b0b320b7f
Parents: 3f7a26c
Author: ILYA Khlopotov 
Authored: Tue Mar 22 05:28:54 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 22 05:28:54 2016 -0700

--
 rebar.config.script | 1 +
 1 file changed, 1 insertion(+)
--


http://git-wip-us.apache.org/repos/asf/couchdb/blob/b1090d69/rebar.config.script
--
diff --git a/rebar.config.script b/rebar.config.script
index fa6a026..232c44f 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -39,6 +39,7 @@ DepDescs = [
 {couch_event,  "couch-event",  
"835a41885d1e276d207758954f8238aa7bba0ae8"},
 {couch_stats,  "couch-stats",  
"7895d4d3f509ed24f09b6d1a0bd0e06af34551dc"},
 {couch_peruser,"peruser",  
"ff7d190970a46722137fbc7a1a75466e8a544ae1"},
+{couch_tests,   "erlang-tests",
"cba29c894aace569f13e6bf83bc6ef06fd448712"},
 {docs, "documentation",
"089f404d26374d8c6942a725d05627d6901a9330", [raw]},
 {ddoc_cache,   "ddoc-cache",   
"c762e90a33ce3cda19ef142dd1120f1087ecd876"},
 {ets_lru,  "ets-lru",  
"c05488c8b1d7ec1c3554a828e0c9bf2888932ed6"},



[3/3] couchdb commit: updated refs/heads/master to 479aa2d

2016-03-22 Thread iilyak
Merge remote branch 'github/pr/396'

This closes #396

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 479aa2d85b6037e3ccb5f3f0a289f7e0b7dd10f5
Parents: 3f7a26c f2ffe13
Author: ILYA Khlopotov 
Authored: Tue Mar 22 07:12:06 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Mar 22 07:12:06 2016 -0700

--
 rebar.config.script | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
--




[1/2] chttpd commit: updated refs/heads/master to fd1ba86

2016-03-08 Thread iilyak
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master ad754a387 -> fd1ba866e


Fix dispatch to handle_error EPI hook


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

Branch: refs/heads/master
Commit: 79677f8a9f0748df0a266f9412d3385d020d2fb1
Parents: ad754a3
Author: ILYA Khlopotov 
Authored: Tue Mar 8 09:59:38 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 8 09:59:38 2016 -0800

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/79677f8a/src/chttpd_plugin.erl
--
diff --git a/src/chttpd_plugin.erl b/src/chttpd_plugin.erl
index c17ffc8..711d0a9 100644
--- a/src/chttpd_plugin.erl
+++ b/src/chttpd_plugin.erl
@@ -35,7 +35,7 @@ after_request(HttpReq, Result) ->
 {ok, Result1}.
 
 handle_error(Error) ->
-[Error1] = with_pipe(after_request, [Error]),
+[Error1] = with_pipe(handle_error, [Error]),
 Error1.
 
 %% --



[2/2] chttpd commit: updated refs/heads/master to fd1ba86

2016-03-08 Thread iilyak
Merge remote branch 'github/pr/105'

This closes #105

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: fd1ba866e1fd0db4b6a386e98a038d8e2973734a
Parents: ad754a3 79677f8
Author: ILYA Khlopotov 
Authored: Tue Mar 8 10:32:32 2016 -0800
Committer: ILYA Khlopotov 
Committed: Tue Mar 8 10:32:32 2016 -0800

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




[2/2] couch-replicator commit: updated refs/heads/master to da86098

2016-03-02 Thread iilyak
Merge remote branch 'github/pr/27'

- https://github.com/apache/couchdb-couch-replicator/pull/27

This closes #27

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: da860981c9718ba3a119236edcb01d1b4ad85d65
Parents: fc49a36 e1fa3c3
Author: ILYA Khlopotov 
Authored: Wed Mar 2 12:36:54 2016 -0800
Committer: ILYA Khlopotov 
Committed: Wed Mar 2 12:36:54 2016 -0800

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




[1/2] couch-replicator commit: updated refs/heads/master to da86098

2016-03-02 Thread iilyak
Repository: couchdb-couch-replicator
Updated Branches:
  refs/heads/master fc49a366c -> da860981c


Remove configurable replicator db name

JIRA: COUCHDB-2954


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

Branch: refs/heads/master
Commit: e1fa3c3fa197ef1bf5a188e567a4f5996e56b30d
Parents: fc49a36
Author: Nick Vatamaniuc 
Authored: Fri Feb 26 16:10:27 2016 -0500
Committer: Nick Vatamaniuc 
Committed: Wed Mar 2 10:26:13 2016 -0500

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/e1fa3c3f/src/couch_replicator_manager.erl
--
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index f0ac7a8..30e1112 100644
--- a/src/couch_replicator_manager.erl
+++ b/src/couch_replicator_manager.erl
@@ -137,9 +137,6 @@ continue(#rep{id = RepId}) ->
 {node() == Owner, Owner}.
 
 
-handle_config_change("replicator", "db", _, _, S) ->
-ok = gen_server:call(S, rep_db_changed),
-remove_handler;
 handle_config_change("replicator", "max_replication_retry_count", V, _, S) ->
 ok = gen_server:cast(S, {set_max_retries, retries_value(V)}),
 {ok, S};
@@ -164,9 +161,8 @@ init(_) ->
 ok = config:listen_for_changes(?MODULE, Server),
 ScanPid = spawn_link(fun() -> scan_all_dbs(Server) end),
 % Automatically start node local changes feed loop
-LocalRepDb = ?l2b(config:get("replicator", "db", "_replicator")),
-ensure_rep_db_exists(LocalRepDb),
-Pid = start_changes_reader(LocalRepDb, 0),
+ensure_rep_db_exists(<<"_replicator">>),
+Pid = start_changes_reader(<<"_replicator">>, 0),
 {ok, #state{
 event_listener = start_event_listener(),
 scan_pid = ScanPid,
@@ -229,9 +225,6 @@ handle_call({rep_db_checkpoint, DbName, EndSeq}, _From, 
State) ->
 true = ets:insert(?DB_TO_SEQ, Entry),
 {reply, ok, State};
 
-handle_call(rep_db_changed, _From, State) ->
-{stop, shutdown, ok, State};
-
 handle_call(Msg, From, State) ->
 couch_log:error("Replication manager received unexpected call ~p from ~p",
 [Msg, From]),



[2/2] documentation commit: updated refs/heads/master to 089f404

2016-03-02 Thread iilyak
Merge remote branch 'github/pr/41'

- https://github.com/apache/couchdb-documentation/pull/41

This closes #41

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 089f404d26374d8c6942a725d05627d6901a9330
Parents: bbc4b71 ec3cc22
Author: ILYA Khlopotov 
Authored: Wed Mar 2 12:37:03 2016 -0800
Committer: ILYA Khlopotov 
Committed: Wed Mar 2 12:37:03 2016 -0800

--
 src/config/replicator.rst  |  7 
 src/replication/replicator.rst | 84 +
 src/whatsnew/2.0.rst   |  6 +++
 3 files changed, 45 insertions(+), 52 deletions(-)
--




[1/2] couch commit: updated refs/heads/master to f2457f3

2016-03-02 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master f7348cbd9 -> f2457f350


Remove configurable replicator db name

JIRA: COUCHDB-2954


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

Branch: refs/heads/master
Commit: 9aa8c65e8413eb7065d5ed2b7e32130ca03681b9
Parents: f7348cb
Author: Nick Vatamaniuc 
Authored: Fri Feb 26 16:12:55 2016 -0500
Committer: Nick Vatamaniuc 
Committed: Wed Mar 2 14:16:40 2016 -0500

--
 src/couch_server.erl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9aa8c65e/src/couch_server.erl
--
diff --git a/src/couch_server.erl b/src/couch_server.erl
index bb93dfe..058ce22 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -119,8 +119,7 @@ maybe_add_sys_db_callbacks(DbName, Options) when 
is_binary(DbName) ->
 maybe_add_sys_db_callbacks(DbName, Options) ->
 DbsDbName = config:get("mem3", "shards_db", "_dbs"),
 NodesDbName = config:get("mem3", "nodes_db", "_nodes"),
-IsReplicatorDb = DbName == config:get("replicator", "db", "_replicator") 
orelse
-   path_ends_with(DbName, <<"_replicator">>),
+IsReplicatorDb = path_ends_with(DbName, <<"_replicator">>),
 IsUsersDb = DbName ==config:get("couch_httpd_auth", "authentication_db", 
"_users") orelse
path_ends_with(DbName, <<"_users">>),
 if



[2/2] couch commit: updated refs/heads/master to f2457f3

2016-03-02 Thread iilyak
Merge remote branch 'github/pr/145'

- https://github.com/apache/couchdb-couch/pull/145

This closes #145

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: f2457f35040f0787e4709b15e5284c339f404bdb
Parents: f7348cb 9aa8c65
Author: ILYA Khlopotov 
Authored: Wed Mar 2 12:36:57 2016 -0800
Committer: ILYA Khlopotov 
Committed: Wed Mar 2 12:36:57 2016 -0800

--
 src/couch_server.erl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
--




[1/2] fabric commit: updated refs/heads/master to 472253f

2016-03-02 Thread iilyak
Repository: couchdb-fabric
Updated Branches:
  refs/heads/master 0e5b33d25 -> 472253f28


Remove configurable replicator db name

JIRA: COUCHDB-2954


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

Branch: refs/heads/master
Commit: 79f006408b97352d620bc4fb5700e29159eb4d49
Parents: 0e5b33d
Author: Nick Vatamaniuc 
Authored: Fri Feb 26 16:11:39 2016 -0500
Committer: Nick Vatamaniuc 
Committed: Mon Feb 29 13:48:08 2016 -0500

--
 src/fabric_util.erl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/79f00640/src/fabric_util.erl
--
diff --git a/src/fabric_util.erl b/src/fabric_util.erl
index 522a1d2..55661d3 100644
--- a/src/fabric_util.erl
+++ b/src/fabric_util.erl
@@ -287,8 +287,7 @@ remove_ancestors_test() ->
 ).
 
 is_replicator_db(DbName) ->
-ConfigName = list_to_binary(config:get("replicator", "db", "_replicator")),
-DbName == ConfigName orelse path_ends_with(DbName, <<"_replicator">>).
+path_ends_with(DbName, <<"_replicator">>).
 
 is_users_db(DbName) ->
 ConfigName = list_to_binary(config:get(



[1/2] couchdb commit: updated refs/heads/master to ca69794

2016-03-02 Thread iilyak
Repository: couchdb
Updated Branches:
  refs/heads/master ec87b44b7 -> ca697949c


Remove configurable replicator db name

JIRA: COUCHDB-2954


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

Branch: refs/heads/master
Commit: 6461d4f831c0934ba5ef80aa0419bbdc090d2173
Parents: ec87b44
Author: Nick Vatamaniuc 
Authored: Wed Mar 2 15:09:26 2016 -0500
Committer: Nick Vatamaniuc 
Committed: Wed Mar 2 15:09:26 2016 -0500

--
 rel/overlay/etc/default.ini | 1 -
 1 file changed, 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb/blob/6461d4f8/rel/overlay/etc/default.ini
--
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 66b4613..26471df 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -259,7 +259,6 @@ compression_level = 8 ; from 1 (lowest, fastest) to 9 
(highest, slowest), 0 to d
 compressible_types = text/*, application/javascript, application/json, 
application/xml
 
 [replicator]
-db = _replicator
 ; minimum time between a replicator job restart (milliseconds)
 start_delay = 0
 ; random splay time between a replicator job restart (milliseconds)



[2/2] couchdb commit: updated refs/heads/master to ca69794

2016-03-02 Thread iilyak
Merge remote branch 'github/pr/386'

- https://github.com/apache/couchdb/pull/386

This closes #386

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: ca697949c95f47e2b843d5e1fe5b21364bb62e45
Parents: ec87b44 6461d4f
Author: ILYA Khlopotov 
Authored: Wed Mar 2 12:36:51 2016 -0800
Committer: ILYA Khlopotov 
Committed: Wed Mar 2 12:36:51 2016 -0800

--
 rel/overlay/etc/default.ini | 1 -
 1 file changed, 1 deletion(-)
--




[2/2] fabric commit: updated refs/heads/master to 472253f

2016-03-02 Thread iilyak
Merge remote branch 'github/pr/39'

- https://github.com/apache/couchdb-fabric/pull/39

This closes #39

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 472253f28ad037f26e54eecb8f56179a03eec435
Parents: 0e5b33d 79f0064
Author: ILYA Khlopotov 
Authored: Wed Mar 2 12:36:37 2016 -0800
Committer: ILYA Khlopotov 
Committed: Wed Mar 2 12:36:38 2016 -0800

--
 src/fabric_util.erl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
--




[1/2] documentation commit: updated refs/heads/master to 089f404

2016-03-02 Thread iilyak
Repository: couchdb-documentation
Updated Branches:
  refs/heads/master bbc4b7191 -> 089f404d2


Remove configurable replicator db name functionality

It was replaced with the ability to have multiple replicator
databases in 2.0

JIRA: COUCHDB-2954


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

Branch: refs/heads/master
Commit: ec3cc220a07adb3089af2844cdc28efdd6740735
Parents: bbc4b71
Author: Nick Vatamaniuc 
Authored: Mon Feb 29 13:33:54 2016 -0500
Committer: Nick Vatamaniuc 
Committed: Mon Feb 29 13:38:29 2016 -0500

--
 src/config/replicator.rst  |  7 
 src/replication/replicator.rst | 84 +
 src/whatsnew/2.0.rst   |  6 +++
 3 files changed, 45 insertions(+), 52 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-documentation/blob/ec3cc220/src/config/replicator.rst
--
diff --git a/src/config/replicator.rst b/src/config/replicator.rst
index 4644a0f..71a218a 100644
--- a/src/config/replicator.rst
+++ b/src/config/replicator.rst
@@ -25,13 +25,6 @@ Replicator Database Configuration
 
 .. versionadded:: 1.2
 
-.. config:option:: db
-
-Specifies replicator database name::
-
-[replicator]
-db = _replicator
-
 .. config:option:: max_replication_retry_count
 
 Maximum replication retry count can be a non-negative integer or

http://git-wip-us.apache.org/repos/asf/couchdb-documentation/blob/ec3cc220/src/replication/replicator.rst
--
diff --git a/src/replication/replicator.rst b/src/replication/replicator.rst
index 31ba686..a09a362 100644
--- a/src/replication/replicator.rst
+++ b/src/replication/replicator.rst
@@ -30,8 +30,9 @@ Replication documents can have a user defined ``_id`` (handy 
for finding a
 specific replication request later). Design Documents (and ``_local`` 
documents)
 added to the replicator database are ignored.
 
-The default name of this database is ``_replicator``. The name can be changed 
in
-the ``local.ini`` configuration, section ``[replicator]``, parameter ``db``.
+The default name of this database is ``_replicator``. Additional replicator
+databases can be created. To be recognized as such by the system, their 
database
+names should end with ``/_replicator``.
 
 Basics
 ==
@@ -43,7 +44,7 @@ Let's say you POST the following document into 
``_replicator``:
 {
 "_id": "my_rep",
 "source":  "http://myserver.com:5984/foo;,
-"target":  "bar",
+"target":  "http://user:pass@localhost:5984/bar;,
 "create_target":  true
 }
 
@@ -62,7 +63,7 @@ CouchDB with 3 new fields:
 {
 "_id": "my_rep",
 "source":  "http://myserver.com:5984/foo;,
-"target":  "bar",
+"target":  "http://user:pass@localhost:5984/bar;,
 "create_target":  true,
 "_replication_id":  "c0ebe9256695ff083347cbf95f93e280",
 "_replication_state":  "triggered",
@@ -96,12 +97,12 @@ Special fields set by the replicator start with the prefix
 {
 "_id": "my_rep",
 "_rev": "2-9f2c0d9372f4ee4dc75652ab8f8e7c70",
-"source": "foodb",
-"target": "bardb",
+"source":  "http://myserver.com:5984/foo;,
+"target":  "http://user:pass@localhost:5984/bar;,
 "_replication_state": "error",
 "_replication_state_time": "2013-12-13T18:48:00+01:00",
 "_replication_state_reason": "db_not_found: could not open foodb",
-"_replication_id": "fe965cdc47b4d5f6c02811d9d351ac3d"
+"_replication_id": "c0ebe9256695ff083347cbf95f93e280"
 }
 
 When the replication finishes, it will update the ``_replication_state``
@@ -113,7 +114,7 @@ the document will look like:
 {
 "_id": "my_rep",
 "source":  "http://myserver.com:5984/foo;,
-"target":  "bar",
+"target":  "http://user:pass@localhost:5984/bar;,
 "create_target":  true,
 "_replication_id":  "c0ebe9256695ff083347cbf95f93e280",
 "_replication_state":  "completed",
@@ -156,7 +157,7 @@ the following order:
 {
 "_id": "doc_A",
 "source":  "http://myserver.com:5984/foo;,
-"target":  "bar"
+"target":  "http://user:pass@localhost:5984/bar;
 }
 
 and
@@ -166,7 +167,7 @@ and
 {
 "_id": "doc_B",
 "source":  "http://myserver.com:5984/foo;,
-"target":  "bar"
+"target":  "http://user:pass@localhost:5984/bar;

[5/5] chttpd commit: updated refs/heads/master to ad754a3

2016-03-03 Thread iilyak
Merge remote branch 'github/pr/101'

This closes #101

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: ad754a387aa884daa0e3c1ff255f51e18ba75c0e
Parents: 41ac33a 02bdd77
Author: ILYA Khlopotov 
Authored: Thu Mar 3 12:01:54 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 12:01:54 2016 -0800

--
 src/chttpd.erl  | 29 ++---
 src/chttpd_cors.erl | 41 +
 src/chttpd_external.erl |  9 -
 3 files changed, 51 insertions(+), 28 deletions(-)
--




[2/5] chttpd commit: updated refs/heads/master to ad754a3

2016-03-03 Thread iilyak
Treat value passed in Origin as case sensitive

According to CORS spec here https://www.w3.org/TR/cors
The value of the Origin header is not a case-sensitive

COUCHDB-2945


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

Branch: refs/heads/master
Commit: 937689eb4c7271817f362716fc386ec782b845e2
Parents: 5b7096d
Author: ILYA Khlopotov 
Authored: Tue Feb 9 14:41:22 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 11:58:49 2016 -0800

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/937689eb/src/chttpd_cors.erl
--
diff --git a/src/chttpd_cors.erl b/src/chttpd_cors.erl
index dcbcad9..a5eaa5a 100644
--- a/src/chttpd_cors.erl
+++ b/src/chttpd_cors.erl
@@ -385,7 +385,7 @@ get_origin(Req) ->
 undefined ->
 undefined;
 Origin ->
-?l2b(to_lower(Origin))
+?l2b(Origin)
 end.
 
 



[4/5] chttpd commit: updated refs/heads/master to ad754a3

2016-03-03 Thread iilyak
Suppress log of a response for clustered interface

COUCHDB-2945


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

Branch: refs/heads/master
Commit: 02bdd77dd36fd850cbb979622c1e703594523e91
Parents: 937689e
Author: ILYA Khlopotov 
Authored: Thu Mar 3 08:07:38 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 11:58:49 2016 -0800

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/02bdd77d/src/chttpd.erl
--
diff --git a/src/chttpd.erl b/src/chttpd.erl
index ffdc928..56b6445 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -222,6 +222,7 @@ handle_request_int(MochiReq) ->
 
 % suppress duplicate log
 erlang:put(dont_log_request, true),
+erlang:put(dont_log_response, true),
 
 {HttpReq2, Response} = case before_request(HttpReq0) of
 {ok, HttpReq1} ->



[1/5] chttpd commit: updated refs/heads/master to ad754a3

2016-03-03 Thread iilyak
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master 41ac33a08 -> ad754a387


Introduce vhosts configuration into CORS

In order to remove code duplication we move vhosts support
from couch_http_cors into chttpd_cors. We also dispatch
chttpd:send_response to couch_http which does call chttpd_cors:headers.
In order to avoid double injection of CORS headers we check for existance of
"Access-Control-Allow-Origin" in response headers.

COUCHDB-2945


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

Branch: refs/heads/master
Commit: 174580824e7c438095448454b0e1a187d7815fcf
Parents: 41ac33a
Author: ILYA Khlopotov 
Authored: Tue Feb 9 13:22:05 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 11:56:59 2016 -0800

--
 src/chttpd.erl  | 28 +++-
 src/chttpd_cors.erl | 51 ++--
 src/chttpd_external.erl |  9 
 3 files changed, 61 insertions(+), 27 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/17458082/src/chttpd.erl
--
diff --git a/src/chttpd.erl b/src/chttpd.erl
index e47c49f..ffdc928 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -25,6 +25,7 @@
 server_header/0, start_chunked_response/3,send_chunk/2,
 start_response_length/4, send/2, start_json_response/2,
 start_json_response/3, end_json_response/1, send_response/4,
+send_response_no_cors/4,
 send_method_not_allowed/2, send_error/2, send_error/4, send_redirect/2,
 send_chunked_error/2, send_json/2,send_json/3,send_json/4,
 validate_ctype/2]).
@@ -643,9 +644,8 @@ etag_respond(Req, CurrentEtag, RespFun) ->
 case etag_match(Req, CurrentEtag) of
 true ->
 % the client has this in their cache.
-Headers0 = [{"Etag", CurrentEtag}],
-Headers1 = chttpd_cors:headers(Req, Headers0),
-chttpd:send_response(Req, 304, Headers1, <<>>);
+Headers = [{"Etag", CurrentEtag}],
+chttpd:send_response(Req, 304, Headers, <<>>);
 false ->
 % Run the function.
 RespFun()
@@ -689,12 +689,13 @@ send_chunk(Resp, Data) ->
 Resp:write_chunk(Data),
 {ok, Resp}.
 
-send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers0, Body) ->
-couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
-Headers = Headers0 ++ server_header() ++
-   [timing(), reqid() | couch_httpd_auth:cookie_auth_header(Req, 
Headers0)],
-{ok, MochiReq:respond({Code, Headers, Body})}.
+send_response(Req, Code, Headers0, Body) ->
+Headers1 = [timing(), reqid() | Headers0],
+couch_httpd:send_response(Req, Code, Headers1, Body).
 
+send_response_no_cors(Req, Code, Headers0, Body) ->
+Headers1 = [timing(), reqid() | Headers0],
+couch_httpd:send_response_no_cors(Req, Code, Headers1, Body).
 
 send_method_not_allowed(Req, Methods) ->
 send_error(Req, 405, [{"Allow", Methods}], <<"method_not_allowed">>,
@@ -708,16 +709,14 @@ send_json(Req, Code, Value) ->
 
 send_json(Req, Code, Headers0, Value) ->
 Headers1 = [timing(), reqid() | Headers0],
-Headers2 = chttpd_cors:headers(Req, Headers1),
-couch_httpd:send_json(Req, Code, Headers2, Value).
+couch_httpd:send_json(Req, Code, Headers1, Value).
 
 start_json_response(Req, Code) ->
 start_json_response(Req, Code, []).
 
 start_json_response(Req, Code, Headers0) ->
 Headers1 = [timing(), reqid() | Headers0],
-Headers2 = chttpd_cors:headers(Req, Headers1),
-couch_httpd:start_json_response(Req, Code, Headers2).
+couch_httpd:start_json_response(Req, Code, Headers1).
 
 end_json_response(Resp) ->
 couch_httpd:end_json_response(Resp).
@@ -989,9 +988,8 @@ send_chunked_error(Resp, Error) ->
 send_chunk(Resp, []).
 
 send_redirect(Req, Path) ->
-Headers0 = [{"Location", chttpd:absolute_uri(Req, Path)}],
-Headers1 = chttpd_cors:headers(Req, Headers0),
-send_response(Req, 301, Headers1, <<>>).
+Headers = [{"Location", chttpd:absolute_uri(Req, Path)}],
+send_response(Req, 301, Headers, <<>>).
 
 server_header() ->
 couch_httpd:server_header().

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/17458082/src/chttpd_cors.erl
--
diff --git a/src/chttpd_cors.erl b/src/chttpd_cors.erl
index 83cfc53..0cb2061 100644
--- a/src/chttpd_cors.erl
+++ b/src/chttpd_cors.erl
@@ -38,7 +38,7 @@ maybe_handle_preflight_request(Req) ->
 not_preflight ->
 not_preflight;
 {ok, 

[1/5] couch commit: updated refs/heads/master to 40adf24

2016-03-03 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master f2457f350 -> 40adf248c


Update test suite for CORS

- Use definitions from chttpd_cors.hrl
- Do not depend on order of methods or headers returned in response.
- Extend list of allowed Exposed headers.

COUCHDB-2945


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

Branch: refs/heads/master
Commit: 9b69868838089569176093380e1b6a6648fcc547
Parents: fe2b6ae
Author: ILYA Khlopotov 
Authored: Tue Feb 9 14:38:32 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 11:35:37 2016 -0800

--
 test/couchdb_cors_tests.erl | 29 -
 1 file changed, 20 insertions(+), 9 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9b698688/test/couchdb_cors_tests.erl
--
diff --git a/test/couchdb_cors_tests.erl b/test/couchdb_cors_tests.erl
index 4b2e2b5..82630bb 100644
--- a/test/couchdb_cors_tests.erl
+++ b/test/couchdb_cors_tests.erl
@@ -15,11 +15,15 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
 
+-include_lib("chttpd/include/chttpd_cors.hrl").
 
--define(SUPPORTED_METHODS,
-"GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT, COPY, OPTIONS").
 -define(TIMEOUT, 1000).
 
+-define(_assertEqualLists(A, B),
+?_assertEqual(lists:usort(A), lists:usort(B))).
+
+-define(assertEqualLists(A, B),
+?assertEqual(lists:usort(A), lists:usort(B))).
 
 start() ->
 Ctx = test_util:start_couch([ioq]),
@@ -182,18 +186,18 @@ should_make_simple_request(_, {_, _, Url, 
DefaultHeaders}) ->
 ?assertEqual(
 "http://example.com;,
 proplists:get_value("Access-Control-Allow-Origin", Resp)),
-?assertEqual(
-"Cache-Control, Content-Type, Server",
-proplists:get_value("Access-Control-Expose-Headers", Resp))
+?assertEqualLists(
+?COUCH_HEADERS ++ list_simple_headers(Resp),
+split_list(proplists:get_value("Access-Control-Expose-Headers", 
Resp)))
 end).
 
 should_make_preflight_request(_, {_, _, Url, DefaultHeaders}) ->
-?_assertEqual(?SUPPORTED_METHODS,
+?_assertEqualLists(?SUPPORTED_METHODS,
 begin
 Headers = DefaultHeaders
   ++ [{"Access-Control-Request-Method", "GET"}],
 {ok, _, Resp, _} = test_request:options(Url, Headers),
-proplists:get_value("Access-Control-Allow-Methods", Resp)
+split_list(proplists:get_value("Access-Control-Allow-Methods", 
Resp))
 end).
 
 should_make_prefligh_request_with_port({_, VHost}, {_, _, Url, _}) ->
@@ -251,7 +255,7 @@ should_make_origin_request_with_auth(_, {_, _, Url, 
DefaultHeaders}) ->
 end).
 
 should_make_preflight_request_with_auth(_, {_, _, Url, DefaultHeaders}) ->
-?_assertEqual(?SUPPORTED_METHODS,
+?_assertEqualLists(?SUPPORTED_METHODS,
 begin
 Hashed = couch_passwords:hash_admin_password(<<"test">>),
 config:set("admins", "test", ?b2l(Hashed), false),
@@ -260,7 +264,7 @@ should_make_preflight_request_with_auth(_, {_, _, Url, 
DefaultHeaders}) ->
 {ok, _, Resp, _} = test_request:options(
 Url, Headers, [{basic_auth, {"test", "test"}}]),
 config:delete("admins", "test", false),
-proplists:get_value("Access-Control-Allow-Methods", Resp)
+split_list(proplists:get_value("Access-Control-Allow-Methods", 
Resp))
 end).
 
 should_not_return_cors_headers_for_invalid_origin({Host, _}) ->
@@ -331,3 +335,10 @@ maybe_append_vhost(true) ->
 [{"Host", "http://example.com"}];
 maybe_append_vhost(false) ->
 [].
+
+split_list(S) ->
+re:split(S, "\\s*,\\s*", [trim, {return, list}]).
+
+list_simple_headers(Headers) ->
+LCHeaders = [string:to_lower(K) || {K, _V} <- Headers],
+lists:filter(fun(H) -> lists:member(H, ?SIMPLE_HEADERS) end, LCHeaders).



[5/5] couch commit: updated refs/heads/master to 40adf24

2016-03-03 Thread iilyak
Merge remote branch 'github/pr/138'

This closes #138

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 40adf248cfed83cc13c0f8fd4ba64a53ca9328ee
Parents: f2457f3 7cf698e
Author: ILYA Khlopotov 
Authored: Thu Mar 3 12:03:01 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 12:03:01 2016 -0800

--
 src/couch_httpd.erl |  44 +++--
 src/couch_httpd_cors.erl| 356 ---
 test/couchdb_cors_tests.erl |  29 +++-
 3 files changed, 47 insertions(+), 382 deletions(-)
--




[3/5] chttpd commit: updated refs/heads/master to ad754a3

2016-03-03 Thread iilyak
Strip scheme out of Host for cors_section

Value returned by `couch_httpd_vhost:host/1` might not contain scheme.
The cors section is named after vhost name (i.e. without scheme).
For example:

[cors:partner.com]
methods =
headers =
exposed_headers =
origins = http://restricted.dev:8000

The origin in origins has to be given with scheme included.

COUCHDB-2945


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

Branch: refs/heads/master
Commit: 5b7096dc1e908b4384aa16190b0469d1e15ef844
Parents: 1745808
Author: ILYA Khlopotov 
Authored: Tue Feb 16 15:23:37 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 11:58:49 2016 -0800

--
 src/chttpd_cors.erl | 28 
 1 file changed, 8 insertions(+), 20 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/5b7096dc/src/chttpd_cors.erl
--
diff --git a/src/chttpd_cors.erl b/src/chttpd_cors.erl
index 0cb2061..dcbcad9 100644
--- a/src/chttpd_cors.erl
+++ b/src/chttpd_cors.erl
@@ -318,28 +318,16 @@ cors_config(Host, Key, Default) ->
 config:get("cors", Key, Default)).
 
 
-cors_section(Host0) ->
-{Host, _Port} = split_host_port(Host0),
+cors_section(HostValue) ->
+HostPort = maybe_strip_scheme(HostValue),
+Host = hd(string:tokens(HostPort, ":")),
 "cors:" ++ Host.
 
-split_host_port(HostAsString) ->
-% split at semicolon ":"
-Split = string:rchr(HostAsString, $:),
-split_host_port(HostAsString, Split).
-
-split_host_port(HostAsString, 0) ->
-% no semicolon
-{HostAsString, '*'};
-split_host_port(HostAsString, N) ->
-HostPart = string:substr(HostAsString, 1, N-1),
-% parse out port
-% is there a nicer way?
-case (catch erlang:list_to_integer(string:substr(HostAsString,
-N+1, length(HostAsString of
-{'EXIT', _} ->
-{HostAsString, '*'};
-Port ->
-{HostPart, Port}
+
+maybe_strip_scheme(Host) ->
+case string:str(Host, "://") of
+0 -> Host;
+N -> string:substr(Host, N + 3)
 end.
 
 



[4/5] couch commit: updated refs/heads/master to 40adf24

2016-03-03 Thread iilyak
Suppress log of a response for clustered interface

COUCHDB-2945


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

Branch: refs/heads/master
Commit: 7cf698e2dfb9986f54ad3d02476727d94299b7fc
Parents: f58817f
Author: ILYA Khlopotov 
Authored: Thu Mar 3 08:08:46 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 11:38:17 2016 -0800

--
 src/couch_httpd.erl | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/7cf698e2/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index c88e2e7..645176b 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -649,6 +649,18 @@ log_request(#httpd{mochi_req=MochiReq,peer=Peer}=Req, 
Code) ->
 gen_event:notify(couch_plugin, {log_request, Req, Code})
 end.
 
+log_response(Code, Body) ->
+case erlang:get(dont_log_response) of
+true ->
+ok;
+_ when Code >= 500 ->
+couch_log:error("httpd ~p error response:~n ~s", [Code, Body]);
+_ when Code >= 400 ->
+couch_log:error("httpd ~p error response:~n ~s", [Code, Body]);
+_ ->
+ok
+end.
+
 start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Length) ->
 log_request(Req, Code),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
@@ -729,15 +741,9 @@ send_response_no_cors(#httpd{mochi_req=MochiReq}=Req, 
Code, Headers, Body) ->
 log_request(Req, Code),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = http_1_0_keep_alive(MochiReq, Headers),
-if Code >= 500 ->
-couch_log:error("httpd ~p error response:~n ~s", [Code, Body]);
-Code >= 400 ->
-couch_log:debug("httpd ~p error response:~n ~s", [Code, Body]);
-true -> ok
-end,
 Headers2 = Headers1 ++ server_header() ++
couch_httpd_auth:cookie_auth_header(Req, Headers1),
-
+log_response(Code, Body),
 {ok, MochiReq:respond({Code, Headers2, Body})}.
 
 send_method_not_allowed(Req, Methods) ->



[3/5] couch commit: updated refs/heads/master to 40adf24

2016-03-03 Thread iilyak
Add send_response_no_cors/4

COUCHDB-2945


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

Branch: refs/heads/master
Commit: f58817f547924f52eef6f01e3b788f3b308a1979
Parents: 9b69868
Author: ILYA Khlopotov 
Authored: Thu Mar 3 07:45:58 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 11:38:04 2016 -0800

--
 src/couch_httpd.erl | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f58817f5/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 34184a1..c88e2e7 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -26,7 +26,8 @@
 -export([start_chunked_response/3,send_chunk/2,log_request/2]).
 -export([start_response_length/4, start_response/3, send/2]).
 -export([start_json_response/2, start_json_response/3, end_json_response/1]).
--export([send_response/4,send_method_not_allowed/2,send_error/2,send_error/4, 
send_redirect/2,send_chunked_error/2]).
+-export([send_response/4,send_response_no_cors/4,send_method_not_allowed/2,
+send_error/2,send_error/4, send_redirect/2,send_chunked_error/2]).
 
-export([send_json/2,send_json/3,send_json/4,last_chunk/1,parse_multipart_request/3]).
 
-export([accepted_encodings/1,handle_request_int/5,validate_referer/1,validate_ctype/2]).
 -export([http_1_0_keep_alive/2]).
@@ -720,7 +721,11 @@ last_chunk(Resp) ->
 Resp:write_chunk([]),
 {ok, Resp}.
 
-send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
+send_response(Req, Code, Headers0, Body) ->
+Headers1 = chttpd_cors:headers(Req, Headers0),
+send_response_no_cors(Req, Code, Headers1, Body).
+
+send_response_no_cors(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
 log_request(Req, Code),
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = http_1_0_keep_alive(MochiReq, Headers),
@@ -732,9 +737,8 @@ send_response(#httpd{mochi_req=MochiReq}=Req, Code, 
Headers, Body) ->
 end,
 Headers2 = Headers1 ++ server_header() ++
couch_httpd_auth:cookie_auth_header(Req, Headers1),
-Headers3 = chttpd_cors:headers(Req, Headers2),
 
-{ok, MochiReq:respond({Code, Headers3, Body})}.
+{ok, MochiReq:respond({Code, Headers2, Body})}.
 
 send_method_not_allowed(Req, Methods) ->
 send_error(Req, 405, [{"Allow", Methods}], <<"method_not_allowed">>, 
?l2b("Only " ++ Methods ++ " allowed")).



[2/5] couch commit: updated refs/heads/master to 40adf24

2016-03-03 Thread iilyak
Remove couch_http_cors in favor of chttpd_cors

In order to avoid code duplication in http stack we remove
couch_http_cors. Vhosts support for CORS is moved into chttpd_cors.
The intend of this refactoring is to make sure we always call
couch_cors:headers for both chttpd and backdoor interface.

COUCHDB-2945


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

Branch: refs/heads/master
Commit: fe2b6ae3b30586f7dab5aedd841bf61d1a0e8a18
Parents: f2457f3
Author: ILYA Khlopotov 
Authored: Tue Feb 9 13:17:26 2016 -0800
Committer: ILYA Khlopotov 
Committed: Thu Mar 3 11:35:37 2016 -0800

--
 src/couch_httpd.erl  |  14 +-
 src/couch_httpd_cors.erl | 356 --
 2 files changed, 7 insertions(+), 363 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/fe2b6ae3/src/couch_httpd.erl
--
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index ef89873..34184a1 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -307,8 +307,8 @@ handle_request_int(MochiReq, DefaultFun,
 try
 validate_host(HttpReq),
 check_request_uri_length(RawUri),
-case couch_httpd_cors:is_preflight_request(HttpReq) of
-#httpd{} ->
+case chttpd_cors:maybe_handle_preflight_request(HttpReq) of
+not_preflight ->
 case authenticate_request(HttpReq) of
 #httpd{} = Req ->
 HandlerFun(Req);
@@ -481,7 +481,7 @@ serve_file(#httpd{mochi_req=MochiReq}=Req, RelativePath, 
DocumentRoot,
 ResponseHeaders = server_header()
 ++ couch_httpd_auth:cookie_auth_header(Req, [])
 ++ ExtraHeaders,
-ResponseHeaders1 = couch_httpd_cors:cors_headers(Req, ResponseHeaders),
+ResponseHeaders1 = chttpd_cors:headers(Req, ResponseHeaders),
 {ok, MochiReq:serve_file(RelativePath, DocumentRoot, ResponseHeaders1)}.
 
 qs_value(Req, Key) ->
@@ -653,7 +653,7 @@ start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, 
Headers, Length) ->
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 Headers1 = Headers ++ server_header() ++
couch_httpd_auth:cookie_auth_header(Req, Headers),
-Headers2 = couch_httpd_cors:cors_headers(Req, Headers1),
+Headers2 = chttpd_cors:headers(Req, Headers1),
 Resp = MochiReq:start_response_length({Code, Headers2, Length}),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
@@ -666,7 +666,7 @@ start_response(#httpd{mochi_req=MochiReq}=Req, Code, 
Headers) ->
 couch_stats:increment_counter([couchdb, httpd_status_codes, Code]),
 CookieHeader = couch_httpd_auth:cookie_auth_header(Req, Headers),
 Headers1 = Headers ++ server_header() ++ CookieHeader,
-Headers2 = couch_httpd_cors:cors_headers(Req, Headers1),
+Headers2 = chttpd_cors:headers(Req, Headers1),
 Resp = MochiReq:start_response({Code, Headers2}),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
@@ -701,7 +701,7 @@ start_chunked_response(#httpd{mochi_req=MochiReq}=Req, 
Code, Headers) ->
 Headers1 = http_1_0_keep_alive(MochiReq, Headers),
 Headers2 = Headers1 ++ server_header() ++
couch_httpd_auth:cookie_auth_header(Req, Headers1),
-Headers3 = couch_httpd_cors:cors_headers(Req, Headers2),
+Headers3 = chttpd_cors:headers(Req, Headers2),
 Resp = MochiReq:respond({Code, Headers3, chunked}),
 case MochiReq:get(method) of
 'HEAD' -> throw({http_head_abort, Resp});
@@ -732,7 +732,7 @@ send_response(#httpd{mochi_req=MochiReq}=Req, Code, 
Headers, Body) ->
 end,
 Headers2 = Headers1 ++ server_header() ++
couch_httpd_auth:cookie_auth_header(Req, Headers1),
-Headers3 = couch_httpd_cors:cors_headers(Req, Headers2),
+Headers3 = chttpd_cors:headers(Req, Headers2),
 
 {ok, MochiReq:respond({Code, Headers3, Body})}.
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/fe2b6ae3/src/couch_httpd_cors.erl
--
diff --git a/src/couch_httpd_cors.erl b/src/couch_httpd_cors.erl
deleted file mode 100644
index abcd9a7..000
--- a/src/couch_httpd_cors.erl
+++ /dev/null
@@ -1,356 +0,0 @@
-% 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 

[1/2] couch-mrview commit: updated refs/heads/master to 3735172

2016-04-25 Thread iilyak
Repository: couchdb-couch-mrview
Updated Branches:
  refs/heads/master 65b7a3a64 -> 37351726a


Use ioq to separately prioritise view updates

COUCHDB-3002


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

Branch: refs/heads/master
Commit: abc94a40da81211395501d91cd5d1fb73e6afbe9
Parents: 65b7a3a
Author: ILYA Khlopotov 
Authored: Thu Apr 21 12:45:34 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Apr 21 12:45:34 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/abc94a40/src/couch_mrview_updater.erl
--
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index 0745c2a..da7381a 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -168,7 +168,8 @@ finish_update(#mrst{doc_acc=Acc}=State) ->
 end.
 
 
-map_docs(Parent, State0) ->
+map_docs(Parent, #mrst{db_name = DbName, idx_name = IdxName} = State0) ->
+erlang:put(io_priority, {view_update, DbName, IdxName}),
 case couch_work_queue:dequeue(State0#mrst.doc_queue) of
 closed ->
 couch_query_servers:stop_doc_map(State0#mrst.qserver),
@@ -201,11 +202,12 @@ map_docs(Parent, State0) ->
 end.
 
 
-write_results(Parent, State) ->
+write_results(Parent, #mrst{db_name = DbName, idx_name = IdxName} = State) ->
 case accumulate_writes(State, State#mrst.write_queue, nil) of
 stop ->
 Parent ! {new_state, State};
 {Go, {Seq, ViewKVs, DocIdKeys, Seqs, Log}} ->
+erlang:put(io_priority, {view_update, DbName, IdxName}),
 NewState = write_kvs(State, Seq, ViewKVs, DocIdKeys, Seqs, Log),
 if Go == stop ->
 Parent ! {new_state, NewState};



[2/2] couch-mrview commit: updated refs/heads/master to 3735172

2016-04-25 Thread iilyak
Merge remote branch 'cloudant:3002-use-ioq-for-view_updades'

This closes #43

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 37351726a03aaa224ba08f475bfb7c403f94d5ee
Parents: 65b7a3a abc94a4
Author: ILYA Khlopotov 
Authored: Mon Apr 25 09:25:56 2016 -0700
Committer: ILYA Khlopotov 
Committed: Mon Apr 25 09:25:56 2016 -0700

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




[2/2] couch commit: updated refs/heads/master to b1127cd

2016-04-21 Thread iilyak
Merge remote branch 'cloudant:3001-use-ioq-for-prompt'

This closes #165

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: b1127cdf5f43787788b87b60209cfa33ad9e17ce
Parents: b49d069 0cd210a
Author: ILYA Khlopotov 
Authored: Thu Apr 21 12:03:14 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Apr 21 12:03:14 2016 -0700

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




[1/2] couch commit: updated refs/heads/master to b1127cd

2016-04-21 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master b49d06916 -> b1127cdf5


Use ioq to separately prioritise prompt requests

COUCHDB-3001


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

Branch: refs/heads/master
Commit: 0cd210a15b0d702c41cfcb7fd17f117e3639a0bc
Parents: b49d069
Author: ILYA Khlopotov 
Authored: Thu Apr 21 11:52:07 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Apr 21 11:52:07 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/0cd210a1/src/couch_os_process.erl
--
diff --git a/src/couch_os_process.erl b/src/couch_os_process.erl
index 5b9a17f..4f1 100644
--- a/src/couch_os_process.erl
+++ b/src/couch_os_process.erl
@@ -51,7 +51,7 @@ send(Pid, Data) ->
 gen_server:cast(Pid, {send, Data}).
 
 prompt(Pid, Data) ->
-case gen_server:call(Pid, {prompt, Data}, infinity) of
+case ioq:call(Pid, {prompt, Data}, erlang:get(io_priority)) of
 {ok, Result} ->
 Result;
 Error ->



[1/2] couch commit: updated refs/heads/master to 636d30a

2016-04-28 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master b1127cdf5 -> 636d30ace


Undo our character advancement when we fixup

We should undo our character advancement after we finish fixup.

COUCHDB-1425


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

Branch: refs/heads/master
Commit: e142672d33ace391f6ded1a3c2dfe3db0955028c
Parents: b1127cd
Author: ILYA Khlopotov 
Authored: Tue Apr 26 17:35:03 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Apr 26 17:45:48 2016 -0700

--
 priv/couch_js/utf8.c | 3 +++
 1 file changed, 3 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/e142672d/priv/couch_js/utf8.c
--
diff --git a/priv/couch_js/utf8.c b/priv/couch_js/utf8.c
index 2d23cc2..fcafff6 100644
--- a/priv/couch_js/utf8.c
+++ b/priv/couch_js/utf8.c
@@ -84,6 +84,9 @@ enc_charbuf(const jschar* src, size_t srclen, char* dst, 
size_t* dstlenp)
 // Invalid second half of surrogate pair
 v = (uint32) 0xFFFD;
 }
+// Undo our character advancement
+src--;
+srclen++;
 }
 else
 {



[2/2] couch commit: updated refs/heads/master to 636d30a

2016-04-28 Thread iilyak
Merge remote branch 'cloudant:1425-fix-character-advancement'

This closes #168

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 636d30aced47dda261a9c0e506c592df16b02646
Parents: b1127cd e142672
Author: ILYA Khlopotov 
Authored: Thu Apr 28 08:35:30 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu Apr 28 08:35:30 2016 -0700

--
 priv/couch_js/utf8.c | 3 +++
 1 file changed, 3 insertions(+)
--




[1/2] couch-mrview commit: updated refs/heads/master to 56b66b4

2016-04-27 Thread iilyak
Repository: couchdb-couch-mrview
Updated Branches:
  refs/heads/master 37351726a -> 56b66b483


Make view updater couch_work_queue configurable

For performance reasons in some cases there is a need to put a cap
on a queue size.

COUCHDB-3005


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

Branch: refs/heads/master
Commit: 3f8230cbfc5b226080364cc9801cb0eeafc1985f
Parents: 3735172
Author: ILYA Khlopotov 
Authored: Tue Apr 26 13:55:11 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue Apr 26 13:58:03 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/3f8230cb/src/couch_mrview_updater.erl
--
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index da7381a..8a85887 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -21,7 +21,9 @@
 
 
 start_update(Partial, State, NumChanges) ->
-QueueOpts = [{max_size, 10}, {max_items, 500}],
+MaxSize = config:get_integer("view_updater", "queue_memory_cap", 10),
+MaxItems = config:get_integer("view_updater", "queue_item_cap", 500),
+QueueOpts = [{max_size, MaxSize}, {max_items, MaxItems}],
 {ok, DocQueue} = couch_work_queue:new(QueueOpts),
 {ok, WriteQueue} = couch_work_queue:new(QueueOpts),
 



[2/2] couch-mrview commit: updated refs/heads/master to 56b66b4

2016-04-27 Thread iilyak
Merge remote branch 'cloudant:3005-configurable_queue_size'

This closes #45

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 56b66b48390732d1bbb2917ca25c4cdb3e196d1e
Parents: 3735172 3f8230c
Author: ILYA Khlopotov 
Authored: Wed Apr 27 17:37:36 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed Apr 27 17:37:36 2016 -0700

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




[1/2] couchdb commit: updated refs/heads/master to 2f51996

2016-05-24 Thread iilyak
Repository: couchdb
Updated Branches:
  refs/heads/master d074b5c7a -> 2f51996d4


Implement a way to disable recompaction

Update deps to enable new functionality:

- couch_index
- couch_tests


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

Branch: refs/heads/master
Commit: fc091fdee9582ecf2f33f2cdd919878008eb7de6
Parents: d074b5c
Author: ILYA Khlopotov 
Authored: Tue May 24 11:34:11 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 11:34:11 2016 -0700

--
 rebar.config.script | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb/blob/fc091fde/rebar.config.script
--
diff --git a/rebar.config.script b/rebar.config.script
index 98f4fd0..2f9f0ce 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -31,14 +31,14 @@ DepDescs = [
 {couch_log_lager,  "couch-log-lager",  
"b2a0471a87765de50c5eb05c65c121f68a9ae9fa"},
 {chttpd,   "chttpd",   
"f3d5d1b0cd8eda814805b5a7290892ee0b3a73ab"},
 {couch,"couch",
"49774f269a6a42af05ead4f17b52edda5f065c78"},
-{couch_index,  "couch-index",  
"e8c8ca8b0bb66193f1ba7e4b1d7e4a3817d661ab"},
+{couch_index,  "couch-index",  
"aa8e6f9573a2dd04bf5a1a98576b1809e1a68035"},
 {couch_mrview, "couch-mrview", 
"e36509b2dfb7bba5f09fcb62f0e23a538451afb5"},
 {couch_replicator, "couch-replicator", 
"ab0afce2d6fdfeeade636a9252327ac09a1e423f"},
 {couch_plugins,"couch-plugins",
"3e73b723cb126cfc471b560d17c24a8b5c540085"},
 {couch_event,  "couch-event",  
"835a41885d1e276d207758954f8238aa7bba0ae8"},
 {couch_stats,  "couch-stats",  
"7895d4d3f509ed24f09b6d1a0bd0e06af34551dc"},
 {couch_peruser,"peruser",  
"ff7d190970a46722137fbc7a1a75466e8a544ae1"},
-{couch_tests,   "erlang-tests",
"cba29c894aace569f13e6bf83bc6ef06fd448712"},
+{couch_tests,   "erlang-tests",
"37b3bfeb4b1a48a592456e67991362e155ed81e0"},
 {docs, "documentation",
"089f404d26374d8c6942a725d05627d6901a9330", [raw]},
 {ddoc_cache,   "ddoc-cache",   
"c762e90a33ce3cda19ef142dd1120f1087ecd876"},
 {ets_lru,  "ets-lru",  
"c05488c8b1d7ec1c3554a828e0c9bf2888932ed6"},



[2/2] couchdb commit: updated refs/heads/master to 2f51996

2016-05-24 Thread iilyak
Merge remote branch 'cloudant:65501-disable-recompaction'

This closes #419

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 2f51996d4b46a8e6ae3d25b68fe1ea69dab6d006
Parents: d074b5c fc091fd
Author: ILYA Khlopotov 
Authored: Tue May 24 15:49:53 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 15:49:53 2016 -0700

--
 rebar.config.script | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
--




[1/2] couch-replicator commit: updated refs/heads/master to 8697441

2016-05-24 Thread iilyak
Repository: couchdb-couch-replicator
Updated Branches:
  refs/heads/master 13326bb4b -> 869744113


gen_event: handle_call suppose to return `{ok, Reply, State}`


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

Branch: refs/heads/master
Commit: 8a4bbc04ae7fe258966ada9a6a7c109174734196
Parents: 13326bb
Author: ILYA Khlopotov 
Authored: Tue May 24 18:39:23 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 18:39:23 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/8a4bbc04/src/couch_replicator_notifier.erl
--
diff --git a/src/couch_replicator_notifier.erl 
b/src/couch_replicator_notifier.erl
index 99b199a..f7640a3 100644
--- a/src/couch_replicator_notifier.erl
+++ b/src/couch_replicator_notifier.erl
@@ -49,7 +49,7 @@ handle_event(Event, {Fun, Acc}) when is_function(Fun, 2) ->
 {ok, {Fun, Acc2}}.
 
 handle_call(_Msg, State) ->
-{reply, ok, State}.
+{ok, ok, State}.
 
 handle_info(_Msg, State) ->
 {ok, State}.



[2/2] couch-replicator commit: updated refs/heads/master to 8697441

2016-05-24 Thread iilyak
Merge remote branch 'cloudant:fix-some-type-errors'

This closes #39

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 8697441137d635fbd6490692cb075912b36c7239
Parents: 13326bb 8a4bbc0
Author: ILYA Khlopotov 
Authored: Tue May 24 19:00:34 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 19:00:34 2016 -0700

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




[1/2] fabric commit: updated refs/heads/master to 2eb1e13

2016-05-24 Thread iilyak
Repository: couchdb-fabric
Updated Branches:
  refs/heads/master 475b90ccd -> 2eb1e132e


Use meck:wait to fix race condition

fabric:update_docs is running in the context of a `read_repair` which is an
independent process started using `erlang:spawn/1`. This leads to a race
when we try to use `meck:history(fabric)`. Use of `meck:wait` ensures that
we call `meck:history` after `fabric:update_docs` has been called.


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

Branch: refs/heads/master
Commit: 19e9959aab87c8050d280f5d255d58cf1a995614
Parents: 475b90c
Author: ILYA Khlopotov 
Authored: Tue May 24 15:52:25 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 15:52:25 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/19e9959a/src/fabric_doc_open_revs.erl
--
diff --git a/src/fabric_doc_open_revs.erl b/src/fabric_doc_open_revs.erl
index 4f0bf89..3534830 100644
--- a/src/fabric_doc_open_revs.erl
+++ b/src/fabric_doc_open_revs.erl
@@ -330,7 +330,9 @@ check_finish_quorum_newer() ->
 S0 = state0(all, false),
 {ok, S1} = handle_message({ok, [foo1(), bar1()]}, w1, S0),
 Expect = {stop, [bar1(), foo2()]},
+ok = meck:reset(fabric),
 ?assertEqual(Expect, handle_message({ok, [foo2(), bar1()]}, w2, S1)),
+ok = meck:wait(fabric, update_docs, '_', 5000),
 ?assertMatch(
 [{_, {fabric, update_docs, [_, _, _]}, _}],
 meck:history(fabric)



[2/2] fabric commit: updated refs/heads/master to 2eb1e13

2016-05-24 Thread iilyak
Merge remote branch 'cloudant:use_meck_wait'

This closes #52

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 2eb1e132e01928a681782c788920c85ce24bfe06
Parents: 475b90c 19e9959
Author: ILYA Khlopotov 
Authored: Tue May 24 16:14:47 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 16:14:47 2016 -0700

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




[2/2] fabric commit: updated refs/heads/master to d20eafd

2016-05-19 Thread iilyak
Merge remote branch 'cloudant:fix-spec-for-get_all_security'

This closes #51

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: d20eafda9045c523f773fbbd06a81d354e1a6ba7
Parents: 087a1aa dbbdb17
Author: ILYA Khlopotov 
Authored: Thu May 19 05:04:59 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu May 19 05:04:59 2016 -0700

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




[1/2] fabric commit: updated refs/heads/master to d20eafd

2016-05-19 Thread iilyak
Repository: couchdb-fabric
Updated Branches:
  refs/heads/master 087a1aa9e -> d20eafda9


Fix return type in get_all_security


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

Branch: refs/heads/master
Commit: dbbdb17ce9241826cd95e655ea8d8d11466c4119
Parents: 087a1aa
Author: ILYA Khlopotov 
Authored: Wed May 18 16:39:09 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed May 18 16:39:09 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/dbbdb17c/src/fabric.erl
--
diff --git a/src/fabric.erl b/src/fabric.erl
index e568179..7e1223b 100644
--- a/src/fabric.erl
+++ b/src/fabric.erl
@@ -147,7 +147,7 @@ get_security(DbName, Options) ->
 
 %% @doc retrieve the security object for all shards of a database
 -spec get_all_security(dbname()) ->
-{ok, json_obj()} |
+{ok, [{#shard{}, json_obj()}]} |
 {error, no_majority | timeout} |
 {error, atom(), any()}.
 get_all_security(DbName) ->
@@ -155,7 +155,7 @@ get_all_security(DbName) ->
 
 %% @doc retrieve the security object for all shards of a database
 -spec get_all_security(dbname(), [option()]) ->
-{ok, json_obj()} |
+{ok, [{#shard{}, json_obj()}]} |
 {error, no_majority | timeout} |
 {error, atom(), any()}.
 get_all_security(DbName, Options) ->



[1/2] mem3 commit: updated refs/heads/master to cea3db5

2016-05-19 Thread iilyak
Repository: couchdb-mem3
Updated Branches:
  refs/heads/master 386545186 -> cea3db578


Fix type spec for range field in #shard{}

Add '_' as a valid value for range field to be able to remove complains
when we create ets match spec in mem3_shards:for_shard_name.


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

Branch: refs/heads/master
Commit: 3a60de689ac25b8e3e5b060faf9a1fb48edc2762
Parents: 3865451
Author: ILYA Khlopotov 
Authored: Wed May 18 16:49:35 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed May 18 16:49:35 2016 -0700

--
 include/mem3.hrl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/3a60de68/include/mem3.hrl
--
diff --git a/include/mem3.hrl b/include/mem3.hrl
index 7c20061..d6ac0be 100644
--- a/include/mem3.hrl
+++ b/include/mem3.hrl
@@ -15,7 +15,7 @@
 name :: binary() | '_',
 node :: node() | '_',
 dbname :: binary(),
-range :: [non_neg_integer() | '$1' | '$2'],
+range :: [non_neg_integer() | '$1' | '$2'] | '_',
 ref :: reference() | 'undefined' | '_'
 }).
 
@@ -24,7 +24,7 @@
 name :: binary() | '_',
 node :: node() | '_',
 dbname :: binary(),
-range :: [non_neg_integer() | '$1' | '$2'],
+range :: [non_neg_integer() | '$1' | '$2'] | '_',
 ref :: reference() | 'undefined' | '_',
 order :: non_neg_integer() | 'undefined' | '_'
 }).



[2/2] mem3 commit: updated refs/heads/master to cea3db5

2016-05-19 Thread iilyak
Merge remote branch 'cloudant:fix-type-spec-for-range-field'

This closes #23

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: cea3db5788a44034d87db3f99225bcaa9e45e69b
Parents: 3865451 3a60de6
Author: ILYA Khlopotov 
Authored: Thu May 19 05:02:09 2016 -0700
Committer: ILYA Khlopotov 
Committed: Thu May 19 05:02:09 2016 -0700

--
 include/mem3.hrl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
--




[2/4] couch-index commit: updated refs/heads/master to aa8e6f9

2016-05-24 Thread iilyak
Implement a way to disable recompaction

In some cases it is a beneficial to be able to temporary disable
recompaction. This commit introduces a way to do so globally or
individually per database or specific index.

The configuration of the feature is as follows:

[view_compaction.recompaction]
enable = true / false %% to set globaly
 = enable / disable %% to set per db
: = enable / disable %% to set per index


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

Branch: refs/heads/master
Commit: 4d4d58915589c0a6957358aa3027443ee60c2b63
Parents: b8bfca7
Author: ILYA Khlopotov 
Authored: Mon May 16 12:54:45 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 10:24:03 2016 -0700

--
 src/couch_index.erl | 39 ---
 1 file changed, 36 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/4d4d5891/src/couch_index.erl
--
diff --git a/src/couch_index.erl b/src/couch_index.erl
index 25fc62a..85d8cb0 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -199,9 +199,14 @@ handle_call({compacted, NewIdxState}, _From, State) ->
 % For indices that require swapping files, we have to make sure we're
 % up to date with the current index. Otherwise indexes could roll back
 % (perhaps considerably) to previous points in history.
-case NewSeq >= OldSeq of
-true -> {reply, ok, commit_compacted(NewIdxState, State)};
-false -> {reply, recompact, State}
+case is_recompaction_enabled(NewIdxState, State) of
+true ->
+case NewSeq >= OldSeq of
+true -> {reply, ok, commit_compacted(NewIdxState, State)};
+false -> {reply, recompact, State}
+end;
+false ->
+{reply, ok, commit_compacted(NewIdxState, State)}
 end.
 
 handle_cast({config_change, NewDelay}, State) ->
@@ -411,3 +416,31 @@ commit_compacted(NewIdxState, State) ->
 idx_state=NewIdxState1,
 committed=false
  }.
+
+is_recompaction_enabled(IdxState, #st{mod = Mod}) ->
+DbName = binary_to_list(Mod:get(db_name, IdxState)),
+IdxName = binary_to_list(Mod:get(idx_name, IdxState)),
+IdxKey = DbName ++ ":" ++ IdxName,
+
+IdxSignature = couch_index_util:hexsig((Mod:get(signature, IdxState))),
+
+Global = get_value("view_compaction", "enabled_recompaction"),
+PerSignature = get_value("view_compaction.recompaction", IdxSignature),
+PerIdx = get_value("view_compaction.recompaction", IdxKey),
+PerDb = get_value("view_compaction.recompaction", DbName),
+
+find_most_specific([Global, PerDb, PerIdx, PerSignature], true).
+
+find_most_specific(Settings, Default) ->
+Reversed = lists:reverse([Default | Settings]),
+[Value | _] = lists:dropwhile(fun(A) -> A =:= undefined end, Reversed),
+Value.
+
+get_value(Section, Key) ->
+case config:get(Section, Key) of
+"enabled" -> true;
+"disabled" -> false;
+"true" -> true;
+"false" -> false;
+undefined -> undefined
+end.



[1/4] couch-index commit: updated refs/heads/master to aa8e6f9

2016-05-24 Thread iilyak
Repository: couchdb-couch-index
Updated Branches:
  refs/heads/master 8ec83cf48 -> aa8e6f957


Extract commit_compacted function


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

Branch: refs/heads/master
Commit: b8bfca7ff0edb6790c57f5d082e296865ff7ff52
Parents: 8ec83cf
Author: ILYA Khlopotov 
Authored: Fri May 13 08:22:55 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 17 11:47:30 2016 -0700

--
 src/couch_index.erl | 46 +-
 1 file changed, 25 insertions(+), 21 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/b8bfca7f/src/couch_index.erl
--
diff --git a/src/couch_index.erl b/src/couch_index.erl
index 2b19cca..25fc62a 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -191,9 +191,7 @@ handle_call(get_compactor_pid, _From, State) ->
 handle_call({compacted, NewIdxState}, _From, State) ->
 #st{
 mod=Mod,
-idx_state=OldIdxState,
-updater=Updater,
-commit_delay=Delay
+idx_state=OldIdxState
 } = State,
 assert_signature_match(Mod, OldIdxState, NewIdxState),
 NewSeq = Mod:get(update_seq, NewIdxState),
@@ -202,26 +200,10 @@ handle_call({compacted, NewIdxState}, _From, State) ->
 % up to date with the current index. Otherwise indexes could roll back
 % (perhaps considerably) to previous points in history.
 case NewSeq >= OldSeq of
-true ->
-{ok, NewIdxState1} = Mod:swap_compacted(OldIdxState, NewIdxState),
-% Restart the indexer if it's running.
-case couch_index_updater:is_running(Updater) of
-true -> ok = couch_index_updater:restart(Updater, 
NewIdxState1);
-false -> ok
-end,
-case State#st.committed of
-true -> erlang:send_after(Delay, self(), commit);
-false -> ok
-end,
-{reply, ok, State#st{
-idx_state=NewIdxState1,
-committed=false
-}};
-_ ->
-{reply, recompact, State}
+true -> {reply, ok, commit_compacted(NewIdxState, State)};
+false -> {reply, recompact, State}
 end.
 
-
 handle_cast({config_change, NewDelay}, State) ->
 MsDelay = 1000 * list_to_integer(NewDelay),
 {noreply, State#st{commit_delay=MsDelay}};
@@ -407,3 +389,25 @@ assert_signature_match(Mod, OldIdxState, NewIdxState) ->
 {Sig, Sig} -> ok;
 _ -> erlang:error(signature_mismatch)
 end.
+
+commit_compacted(NewIdxState, State) ->
+#st{
+mod=Mod,
+idx_state=OldIdxState,
+updater=Updater,
+commit_delay=Delay
+} = State,
+{ok, NewIdxState1} = Mod:swap_compacted(OldIdxState, NewIdxState),
+% Restart the indexer if it's running.
+case couch_index_updater:is_running(Updater) of
+true -> ok = couch_index_updater:restart(Updater, NewIdxState1);
+false -> ok
+end,
+case State#st.committed of
+true -> erlang:send_after(Delay, self(), commit);
+false -> ok
+end,
+State#st{
+idx_state=NewIdxState1,
+committed=false
+ }.



[3/4] couch-index commit: updated refs/heads/master to aa8e6f9

2016-05-24 Thread iilyak
Add test suite for is_recompaction_enabled/2


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

Branch: refs/heads/master
Commit: 2c5cef415e046c89bb0127b7a85be28f681d7bc3
Parents: 4d4d589
Author: ILYA Khlopotov 
Authored: Tue May 17 11:46:33 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 10:24:03 2016 -0700

--
 src/couch_index.erl | 119 +++
 1 file changed, 119 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/2c5cef41/src/couch_index.erl
--
diff --git a/src/couch_index.erl b/src/couch_index.erl
index 85d8cb0..7f54a7f 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -444,3 +444,122 @@ get_value(Section, Key) ->
 "false" -> false;
 undefined -> undefined
 end.
+
+-ifdef(TEST).
+-include_lib("couch/include/couch_eunit.hrl").
+
+get(db_name, _, _) ->
+<<"db_name">>;
+get(idx_name, _, _) ->
+<<"idx_name">>;
+get(signature, _, _) ->
+<<61,237,157,230,136,93,96,201,204,17,137,186,50,249,44,135>>.
+
+setup(Settings) ->
+ok = meck:new([config], [passthrough]),
+ok = meck:new([test_index], [non_strict]),
+ok = meck:expect(config, get, fun(Section, Key) ->
+configure(Section, Key, Settings)
+end),
+ok = meck:expect(test_index, get, fun get/3),
+{undefined, #st{mod = {test_index}}}.
+
+teardown(_, _) ->
+(catch meck:unload(config)),
+(catch meck:unload(test_index)),
+ok.
+
+configure("view_compaction", "enabled_recompaction", [Global, _Db, _Index]) ->
+Global;
+configure("view_compaction.recompaction", "db_name", [_Global, Db, _Index]) ->
+Db;
+configure("view_compaction.recompaction", "db_name:" ++ _, [_, _, Index]) ->
+Index;
+configure(Section, Key, _) ->
+meck:passthrough([Section, Key]).
+
+recompaction_configuration_test_() ->
+{
+"Compaction tests",
+{
+setup,
+fun test_util:start_couch/0, fun test_util:stop_couch/1,
+{
+foreachx,
+fun setup/1, fun teardown/2,
+recompaction_configuration_tests()
+}
+}
+}.
+
+recompaction_configuration_tests() ->
+AllCases = couch_tests_combinatorics:product([
+[undefined, "true", "false"],
+[undefined, "enabled", "disabled"],
+[undefined, "enabled", "disabled"]
+]),
+
+EnabledCases = [
+[undefined, undefined, undefined],
+
+[undefined, undefined,"enabled"],
+[undefined, "enabled", undefined],
+[undefined, "disabled", "enabled"],
+[undefined, "enabled", "enabled"],
+
+["true", undefined, undefined],
+["true", undefined, "enabled"],
+["true", "disabled", "enabled"],
+["true", "enabled", undefined],
+["true", "enabled", "enabled"],
+
+["false", undefined, "enabled"],
+["false", "enabled", undefined],
+["false", "disabled", "enabled"],
+["false", "enabled", "enabled"]
+],
+
+DisabledCases = [
+[undefined, undefined, "disabled"],
+[undefined, "disabled", undefined],
+[undefined, "disabled", "disabled"],
+[undefined, "enabled", "disabled"],
+
+["true", undefined, "disabled"],
+["true", "disabled", undefined],
+["true", "disabled", "disabled"],
+["true", "enabled", "disabled"],
+
+["false", undefined, undefined],
+["false", undefined, "disabled"],
+["false", "disabled", undefined],
+["false", "disabled", "disabled"],
+["false", "enabled", "disabled"]
+],
+
+?assertEqual([], AllCases -- (EnabledCases ++ DisabledCases)),
+
+[{Settings, fun should_not_call_recompact/2} || Settings <- DisabledCases]
+++
+[{Settings, fun should_call_recompact/2} || Settings <- EnabledCases].
+
+should_call_recompact(Settings, {IdxState, State}) ->
+{test_id(Settings), ?_test(begin
+?assert(is_recompaction_enabled(IdxState, State)),
+ok
+end)}.
+
+should_not_call_recompact(Settings, {IdxState, State}) ->
+{test_id(Settings), ?_test(begin
+?assertNot(is_recompaction_enabled(IdxState, State)),
+ok
+end)}.
+
+to_string(undefined) -> "undefined";
+to_string(Value) -> Value.
+
+test_id(Settings0) ->
+Settings1 = [to_string(Value) || Value <- Settings0],
+"[ " ++ lists:flatten(string:join(Settings1, " , ")) ++ " ]".
+
+-endif.



[4/4] couch-index commit: updated refs/heads/master to aa8e6f9

2016-05-24 Thread iilyak
Merge remote branch 'cloudant:65501-disable-recompaction'

This closes #16

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: aa8e6f9573a2dd04bf5a1a98576b1809e1a68035
Parents: 8ec83cf 2c5cef4
Author: ILYA Khlopotov 
Authored: Tue May 24 11:30:13 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 24 11:30:13 2016 -0700

--
 src/couch_index.erl | 198 ++-
 1 file changed, 177 insertions(+), 21 deletions(-)
--




[1/2] twig commit: updated refs/heads/master to 7b58ab2

2016-05-11 Thread iilyak
Repository: couchdb-twig
Updated Branches:
  refs/heads/master ec9498818 -> 7b58ab232


Implement couch_log behaviour

couch_log was updated in such a way that the module name of a couch_log
backend has to follow following convention `couch_log_`.


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

Branch: refs/heads/master
Commit: 72dccc6f1e982cbe00423fa384305e32a556fd3b
Parents: ec94988
Author: ILYA Khlopotov 
Authored: Wed May 11 08:15:50 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed May 11 08:15:50 2016 -0700

--
 src/couch_log_twig.erl | 54 +
 1 file changed, 54 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/couchdb-twig/blob/72dccc6f/src/couch_log_twig.erl
--
diff --git a/src/couch_log_twig.erl b/src/couch_log_twig.erl
new file mode 100644
index 000..fef3d50
--- /dev/null
+++ b/src/couch_log_twig.erl
@@ -0,0 +1,54 @@
+% 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(couch_log_twig).
+
+-behaviour(couch_log).
+
+-export([
+debug/2,
+info/2,
+notice/2,
+warning/2,
+error/2,
+critical/2,
+alert/2,
+emergency/2,
+set_level/1
+]).
+
+debug(Fmt, Args) ->
+twig:log(debug, Fmt, Args).
+
+info(Fmt, Args) ->
+twig:log(info, Fmt, Args).
+
+notice(Fmt, Args) ->
+twig:log(notice, Fmt, Args).
+
+warning(Fmt, Args) ->
+twig:log(warning, Fmt, Args).
+
+error(Fmt, Args) ->
+twig:log(error, Fmt, Args).
+
+critical(Fmt, Args) ->
+twig:log(crit, Fmt, Args).
+
+alert(Fmt, Args) ->
+twig:log(alert, Fmt, Args).
+
+emergency(Fmt, Args) ->
+twig:log(emerg, Fmt, Args).
+
+set_level(Level) ->
+twig:set_level(Level).



twig commit: updated refs/heads/add-couch_log_twig-backend to 72dccc6

2016-05-11 Thread iilyak
Repository: couchdb-twig
Updated Branches:
  refs/heads/add-couch_log_twig-backend [created] 72dccc6f1


Implement couch_log behaviour

couch_log was updated in such a way that the module name of a couch_log
backend has to follow following convention `couch_log_`.


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

Branch: refs/heads/add-couch_log_twig-backend
Commit: 72dccc6f1e982cbe00423fa384305e32a556fd3b
Parents: ec94988
Author: ILYA Khlopotov 
Authored: Wed May 11 08:15:50 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed May 11 08:15:50 2016 -0700

--
 src/couch_log_twig.erl | 54 +
 1 file changed, 54 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/couchdb-twig/blob/72dccc6f/src/couch_log_twig.erl
--
diff --git a/src/couch_log_twig.erl b/src/couch_log_twig.erl
new file mode 100644
index 000..fef3d50
--- /dev/null
+++ b/src/couch_log_twig.erl
@@ -0,0 +1,54 @@
+% 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(couch_log_twig).
+
+-behaviour(couch_log).
+
+-export([
+debug/2,
+info/2,
+notice/2,
+warning/2,
+error/2,
+critical/2,
+alert/2,
+emergency/2,
+set_level/1
+]).
+
+debug(Fmt, Args) ->
+twig:log(debug, Fmt, Args).
+
+info(Fmt, Args) ->
+twig:log(info, Fmt, Args).
+
+notice(Fmt, Args) ->
+twig:log(notice, Fmt, Args).
+
+warning(Fmt, Args) ->
+twig:log(warning, Fmt, Args).
+
+error(Fmt, Args) ->
+twig:log(error, Fmt, Args).
+
+critical(Fmt, Args) ->
+twig:log(crit, Fmt, Args).
+
+alert(Fmt, Args) ->
+twig:log(alert, Fmt, Args).
+
+emergency(Fmt, Args) ->
+twig:log(emerg, Fmt, Args).
+
+set_level(Level) ->
+twig:set_level(Level).



[2/2] twig commit: updated refs/heads/master to 7b58ab2

2016-05-11 Thread iilyak
Merge remote branch 'apache:add-couch_log_twig-backend'

This closes #4

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 7b58ab232f3db5e54d1c81b6965678f87f89ae11
Parents: ec94988 72dccc6
Author: ILYA Khlopotov 
Authored: Wed May 11 08:26:42 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed May 11 08:26:42 2016 -0700

--
 src/couch_log_twig.erl | 54 +
 1 file changed, 54 insertions(+)
--




[couchdb-twig] Git Push Summary

2016-05-11 Thread iilyak
Repository: couchdb-twig
Updated Branches:
  refs/heads/add-couch_log_twig-backend [deleted] 72dccc6f1


[1/2] couch commit: updated refs/heads/master to 514a447

2016-05-18 Thread iilyak
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 23f188096 -> 514a44775


Support create_if_missing option in couch_db:open


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

Branch: refs/heads/master
Commit: 9c349b9b18456bc75486defb87b205c38da4a05d
Parents: 23f1880
Author: ILYA Khlopotov 
Authored: Tue May 17 16:44:13 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 17 16:44:13 2016 -0700

--
 src/couch_server.erl|  4 
 test/couch_db_tests.erl | 19 +++
 2 files changed, 23 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9c349b9b/src/couch_server.erl
--
diff --git a/src/couch_server.erl b/src/couch_server.erl
index b9a5077..2634bbf 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -81,10 +81,14 @@ open(DbName, Options0) ->
 {ok, Db#db{user_ctx=Ctx, fd_monitor=erlang:monitor(process,Fd)}};
 _ ->
 Timeout = couch_util:get_value(timeout, Options, infinity),
+Create = couch_util:get_value(create_if_missing, Options, false),
 case gen_server:call(couch_server, {open, DbName, Options}, Timeout) of
 {ok, #db{fd=Fd} = Db} ->
 update_lru(DbName, Options),
 {ok, Db#db{user_ctx=Ctx, fd_monitor=erlang:monitor(process,Fd)}};
+{not_found, no_db_file} when Create ->
+couch_log:warning("creating missing database: ~s", [DbName]),
+couch_server:create(DbName, Options);
 Error ->
 Error
 end

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9c349b9b/test/couch_db_tests.erl
--
diff --git a/test/couch_db_tests.erl b/test/couch_db_tests.erl
index f614102..c57a0d4 100644
--- a/test/couch_db_tests.erl
+++ b/test/couch_db_tests.erl
@@ -39,6 +39,18 @@ create_delete_db_test_()->
 }
 }.
 
+open_db_test_()->
+{
+"Database open tests",
+{
+setup,
+fun setup/0, fun test_util:stop_couch/1,
+fun(_) ->
+[should_create_db_if_missing()]
+end
+}
+}.
+
 
 should_create_db() ->
 DbName = ?tempdb(),
@@ -98,6 +110,13 @@ should_create_delete_database_continuously() ->
?_assert(loop(DbName, N))}}
  || N <- [10, 100]].
 
+should_create_db_if_missing() ->
+DbName = ?tempdb(),
+{ok, Db} = couch_db:open(DbName, [{create_if_missing, true}]),
+ok = couch_db:close(Db),
+{ok, AllDbs} = couch_server:all_databases(),
+?_assert(lists:member(DbName, AllDbs)).
+
 loop(_, 0) ->
 true;
 loop(DbName, N) ->



[1/2] mem3 commit: updated refs/heads/master to 3865451

2016-05-18 Thread iilyak
Repository: couchdb-mem3
Updated Branches:
  refs/heads/master 861427999 -> 386545186


Make sure mem3_rep autocreates target shards

The change to our fancier history entries introduced a regression that
internal replication wouldn't automatically create the target shards.
This fixes the issue by adding a get_or_create_db/2 in mem3_rep and
switches the use of couch_db:open_int/2 to that function.


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

Branch: refs/heads/master
Commit: 94ebe26b12374552bcd6b4b7b493bf66c8053d22
Parents: 8614279
Author: Paul J. Davis 
Authored: Thu Jan 8 13:08:03 2015 -0600
Committer: ILYA Khlopotov 
Committed: Wed May 18 07:50:46 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/94ebe26b/src/mem3_rpc.erl
--
diff --git a/src/mem3_rpc.erl b/src/mem3_rpc.erl
index c7952b9..93cb99a 100644
--- a/src/mem3_rpc.erl
+++ b/src/mem3_rpc.erl
@@ -60,7 +60,7 @@ find_common_seq(Node, DbName, SourceUUID, SourceEpochs) ->
 
 load_checkpoint_rpc(DbName, SourceNode, SourceUUID) ->
 erlang:put(io_priority, {internal_repl, DbName}),
-case couch_db:open_int(DbName, [?ADMIN_CTX]) of
+case get_or_create_db(DbName, [?ADMIN_CTX]) of
 {ok, Db} ->
 TargetUUID = couch_db:get_uuid(Db),
 NewId = mem3_rep:make_local_id(SourceUUID, TargetUUID),
@@ -83,7 +83,7 @@ load_checkpoint_rpc(DbName, SourceNode, SourceUUID) ->
 
 save_checkpoint_rpc(DbName, Id, SourceSeq, NewEntry0, History0) ->
 erlang:put(io_priority, {internal_repl, DbName}),
-case couch_db:open_int(DbName, [?ADMIN_CTX]) of
+case get_or_create_db(DbName, [?ADMIN_CTX]) of
 {ok, #db{update_seq = TargetSeq} = Db} ->
 NewEntry = {[
 {<<"target_node">>, atom_to_binary(node(), utf8)},
@@ -113,7 +113,7 @@ save_checkpoint_rpc(DbName, Id, SourceSeq, NewEntry0, 
History0) ->
 
 find_common_seq_rpc(DbName, SourceUUID, SourceEpochs) ->
 erlang:put(io_priority, {internal_repl, DbName}),
-case couch_db:open_int(DbName, [?ADMIN_CTX]) of
+case get_or_create_db(DbName, [?ADMIN_CTX]) of
 {ok, Db} ->
 case couch_db:get_uuid(Db) of
 SourceUUID ->
@@ -275,6 +275,10 @@ rexi_call(Node, MFA) ->
 end.
 
 
+get_or_create_db(DbName, Options) ->
+couch_db:open_int(DbName, [{create_if_missing, true} | Options]).
+
+
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").
 



[1/2] fabric commit: updated refs/heads/master to 087a1aa

2016-05-18 Thread iilyak
Repository: couchdb-fabric
Updated Branches:
  refs/heads/master c449ab224 -> 087a1aa9e


Use create_if_missing option of couch_db:open_int


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

Branch: refs/heads/master
Commit: 06578c4b1b6f4bbd6ccd086391bb472001743b2f
Parents: c449ab2
Author: ILYA Khlopotov 
Authored: Tue May 17 16:57:16 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 17 16:57:16 2016 -0700

--
 src/fabric_rpc.erl | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/06578c4b/src/fabric_rpc.erl
--
diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl
index d2578d7..cc242b9 100644
--- a/src/fabric_rpc.erl
+++ b/src/fabric_rpc.erl
@@ -268,13 +268,7 @@ with_db(DbName, Options, {M,F,A}) ->
 end.
 
 get_or_create_db(DbName, Options) ->
-case couch_db:open_int(DbName, Options) of
-{not_found, no_db_file} ->
-couch_log:warning("~p creating ~s", [?MODULE, DbName]),
-couch_server:create(DbName, Options);
-Else ->
-Else
-end.
+couch_db:open_int(DbName, [{create_if_missing, true} | Options]).
 
 
 view_cb({meta, Meta}, Acc) ->



[2/2] fabric commit: updated refs/heads/master to 087a1aa

2016-05-18 Thread iilyak
Merge remote branch 'cloudant:43260-create-target-shard-if-missing'

This closes #50

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 087a1aa9e6972ac6613e2f93177aee56a4bac86c
Parents: c449ab2 06578c4
Author: ILYA Khlopotov 
Authored: Wed May 18 07:48:29 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed May 18 07:48:29 2016 -0700

--
 src/fabric_rpc.erl | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)
--




[2/2] couch commit: updated refs/heads/master to 514a447

2016-05-18 Thread iilyak
Merge remote branch 'cloudant:create_db_if_missing'

This closes #174

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 514a447751440ba230e04ea680f446e72e7f04cd
Parents: 23f1880 9c349b9
Author: ILYA Khlopotov 
Authored: Wed May 18 07:46:46 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed May 18 07:46:46 2016 -0700

--
 src/couch_server.erl|  4 
 test/couch_db_tests.erl | 19 +++
 2 files changed, 23 insertions(+)
--




[2/2] mem3 commit: updated refs/heads/master to 3865451

2016-05-18 Thread iilyak
Merge remote branch 'cloudant:43260-create-target-shard-if-missing'

This closes #21

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: 386545186e5a31a42fc68c82d0e36f8407bf4739
Parents: 8614279 94ebe26
Author: ILYA Khlopotov 
Authored: Wed May 18 07:51:51 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed May 18 07:51:51 2016 -0700

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




[2/2] couch-log commit: updated refs/heads/master to cc55404

2016-05-03 Thread iilyak
Merge remote branch 'cloudant:fix-is_active_level-type-spec'

This closes #12

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: cc5540419e0a4bb7872d18bc5a94f39446d83a88
Parents: e4abbd3 d2e0a9b
Author: ILYA Khlopotov 
Authored: Tue May 3 08:31:51 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 3 08:31:51 2016 -0700

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




[2/2] fabric commit: updated refs/heads/master to c449ab2

2016-05-03 Thread iilyak
Merge remote branch 'cloudant:update-get_doc_count-spec'

This closes #49

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: c449ab22431658173af45a6599d9875883adb911
Parents: f0d6c03 1dcc5b8
Author: ILYA Khlopotov 
Authored: Tue May 3 08:29:50 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 3 08:29:50 2016 -0700

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




[1/2] fabric commit: updated refs/heads/master to c449ab2

2016-05-03 Thread iilyak
Repository: couchdb-fabric
Updated Branches:
  refs/heads/master f0d6c03e4 -> c449ab224


Improve fabric:get_doc_count spec


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

Branch: refs/heads/master
Commit: 1dcc5b88a34f5ccf65c4dec97f0096808e3ae407
Parents: f0d6c03
Author: ILYA Khlopotov 
Authored: Tue May 3 06:57:49 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 3 06:57:49 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/1dcc5b88/src/fabric.erl
--
diff --git a/src/fabric.erl b/src/fabric.erl
index 97f766b..e568179 100644
--- a/src/fabric.erl
+++ b/src/fabric.erl
@@ -84,7 +84,10 @@ get_db_info(DbName) ->
 fabric_db_info:go(dbname(DbName)).
 
 %% @doc the number of docs in a database
--spec get_doc_count(dbname()) -> {ok, non_neg_integer()}.
+-spec get_doc_count(dbname()) ->
+{ok, non_neg_integer()} |
+{error, atom()} |
+{error, atom(), any()}.
 get_doc_count(DbName) ->
 fabric_db_doc_count:go(dbname(DbName)).
 



[1/2] couch-log commit: updated refs/heads/master to cc55404

2016-05-03 Thread iilyak
Repository: couchdb-couch-log
Updated Branches:
  refs/heads/master e4abbd387 -> cc5540419


Fix couch_log:is_active_level/1 type spec


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

Branch: refs/heads/master
Commit: d2e0a9b228f213beff2dbd78f9ed04e208aee4f5
Parents: e4abbd3
Author: ILYA Khlopotov 
Authored: Tue May 3 07:08:24 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 3 07:08:24 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/d2e0a9b2/src/couch_log.erl
--
diff --git a/src/couch_log.erl b/src/couch_log.erl
index 1047c59..678559f 100644
--- a/src/couch_log.erl
+++ b/src/couch_log.erl
@@ -97,7 +97,7 @@ log(Level, Fmt, Args) ->
 apply(Backend, Level, [Fmt, Args])
 end.
 
--spec is_active_level(atom()) -> boolean.
+-spec is_active_level(atom()) -> boolean().
 is_active_level(Level) ->
 CurrentLevel = level_to_atom(config:get("log", "level", "notice")),
 level_integer(Level) >= level_integer(CurrentLevel).



[2/2] fabric commit: updated refs/heads/master to f0d6c03

2016-05-03 Thread iilyak
Merge remote branch 'cloudant:fix-db_update_listener'

This closes #48

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: f0d6c03e425473e784fbb815f48f1cca606f91f1
Parents: ecaacfe b592c39
Author: ILYA Khlopotov 
Authored: Tue May 3 06:18:28 2016 -0700
Committer: ILYA Khlopotov 
Committed: Tue May 3 06:18:28 2016 -0700

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




[1/2] fabric commit: updated refs/heads/master to f0d6c03

2016-05-03 Thread iilyak
Repository: couchdb-fabric
Updated Branches:
  refs/heads/master ecaacfecf -> f0d6c03e4


start_update_notifiers returns list of #worker{}

start_update_notifiers returns list of #workers{}. However we expect
`{Node, Reference}`.


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

Branch: refs/heads/master
Commit: b592c390b99a198d6a051c6ed7b0280800cc2939
Parents: ecaacfe
Author: ILYA Khlopotov 
Authored: Mon May 2 18:01:28 2016 -0700
Committer: ILYA Khlopotov 
Committed: Mon May 2 18:01:28 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/b592c390/src/fabric_db_update_listener.erl
--
diff --git a/src/fabric_db_update_listener.erl 
b/src/fabric_db_update_listener.erl
index 82a70ad..ac4d8a2 100644
--- a/src/fabric_db_update_listener.erl
+++ b/src/fabric_db_update_listener.erl
@@ -37,7 +37,7 @@
 
 go(Parent, ParentRef, DbName, Timeout) ->
 Notifiers = start_update_notifiers(DbName),
-MonRefs = lists:usort([rexi_utils:server_pid(N) || {N, _Ref} <- 
Notifiers]),
+MonRefs = lists:usort([rexi_utils:server_pid(N) || #worker{node = N} <- 
Notifiers]),
 RexiMon = rexi_monitor:start(MonRefs),
 MonPid = start_cleanup_monitor(self(), Notifiers),
 %% This is not a common pattern for rexi but to enable the calling



[1/3] chttpd commit: updated refs/heads/master to be1e959

2016-04-15 Thread iilyak
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master 02202d326 -> be1e95950


Log user name of request initiator

Change the log format from chttpd to include username.
The new format is (space separated):

Nonce, Peer, Host, UserName, Method, RawUri, Code, Status, RequestTime

COUCHDB-2973


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

Branch: refs/heads/master
Commit: d2665cec222ab447e47cdceff950269553fb6c47
Parents: 02202d3
Author: ILYA Khlopotov 
Authored: Mon Mar 21 12:23:31 2016 -0700
Committer: ILYA Khlopotov 
Committed: Fri Apr 15 09:06:37 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d2665cec/src/chttpd.erl
--
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 3d2f3d9..e5c6b65 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -371,10 +371,11 @@ maybe_log(#httpd{} = HttpReq, #httpd_resp{should_log = 
true} = HttpResp) ->
 code = Code,
 status = Status
 } = HttpResp,
+User = get_user(HttpReq),
 Host = MochiReq:get_header_value("Host"),
 RawUri = MochiReq:get(raw_path),
 RequestTime = timer:now_diff(EndTime, BeginTime) / 1000,
-couch_log:notice("~s ~s ~s ~s ~s ~B ~p ~B", [Nonce, Peer, Host,
+couch_log:notice("~s ~s ~s ~s ~s ~s ~B ~p ~B", [Nonce, Peer, Host, User,
 Method, RawUri, Code, Status, round(RequestTime)]);
 maybe_log(_HttpReq, #httpd_resp{should_log = false}) ->
 ok.
@@ -1085,6 +1086,10 @@ respond_(#httpd{mochi_req = MochiReq}, Code, Headers, 
_Args, start_response) ->
 respond_(#httpd{mochi_req = MochiReq}, Code, Headers, Args, Type) ->
 MochiReq:Type({Code, Headers, Args}).
 
+get_user(#httpd{user_ctx = #user_ctx{name = User}}) ->
+couch_util:url_encode(User);
+get_user(#httpd{user_ctx = undefined}) ->
+"undefined".
 
 -ifdef(TEST).
 



[3/3] chttpd commit: updated refs/heads/master to be1e959

2016-04-15 Thread iilyak
Merge remote branch 'github/pr/109'

This closes #109

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: be1e959504ac7b0332110a9918365ff20937bc43
Parents: 02202d3 cd00955
Author: ILYA Khlopotov 
Authored: Fri Apr 15 11:32:30 2016 -0700
Committer: ILYA Khlopotov 
Committed: Fri Apr 15 11:32:30 2016 -0700

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




[2/3] chttpd commit: updated refs/heads/master to be1e959

2016-04-15 Thread iilyak
Add `log_format_test` test case

COUCHDB-2973


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

Branch: refs/heads/master
Commit: cd00955bbe3f6dcbdd11d78781bb4576f7643f9d
Parents: d2665ce
Author: ILYA Khlopotov 
Authored: Mon Mar 21 13:06:28 2016 -0700
Committer: ILYA Khlopotov 
Committed: Fri Apr 15 09:06:46 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/cd00955b/src/chttpd.erl
--
diff --git a/src/chttpd.erl b/src/chttpd.erl
index e5c6b65..ee90e5d 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -1145,4 +1145,46 @@ check_url_encoding_fail_test_() ->
 check_url_encoding("/dbname%g2"))
 ].
 
+log_format_test() ->
+?assertEqual(
+"nonce 127.0.0.1 127.0.0.1:15984 undefined "
+"GET /_cluster_setup 201 ok 1",
+test_log_request("/_cluster_setup", undefined)),
+?assertEqual(
+"nonce 127.0.0.1 127.0.0.1:15984 user_foo "
+"GET /_all_dbs 201 ok 1",
+test_log_request("/_all_dbs", #user_ctx{name = <<"user_foo">>})),
+
+%% Utf8Name = unicode:characters_to_binary(Something),
+Utf8User = <<227,130,136,227,129,134,227,129,147,227,129,157>>,
+?assertEqual(
+"nonce 127.0.0.1 127.0.0.1:15984 %E3%82%88%E3%81%86%E3%81%93%E3%81%9D "
+"GET /_all_dbs 201 ok 1",
+test_log_request("/_all_dbs", #user_ctx{name = Utf8User})),
+ok.
+
+test_log_request(RawPath, UserCtx) ->
+Headers = mochiweb_headers:make([{"HOST", "127.0.0.1:15984"}]),
+MochiReq = mochiweb_request:new(socket, [], 'POST', RawPath, version, 
Headers),
+Req = #httpd{
+mochi_req = MochiReq,
+begin_ts = {1458,588713,124003},
+original_method = 'GET',
+peer = "127.0.0.1",
+nonce = "nonce",
+user_ctx = UserCtx
+},
+Resp = #httpd_resp{
+end_ts = {1458,588723,124303},
+code = 201,
+status = ok
+},
+ok = meck:new(couch_log, [passthrough]),
+ok = meck:expect(couch_log, notice, fun(Format, Args) ->
+lists:flatten(io_lib:format(Format, Args))
+end),
+Message = maybe_log(Req, Resp),
+ok = meck:unload(couch_log),
+Message.
+
 -endif.



[2/2] couchdb commit: updated refs/heads/master to a4d84d8

2016-04-20 Thread iilyak
Merge remote branch 'github/pr/408'

This closes #408

Signed-off-by: ILYA Khlopotov 


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

Branch: refs/heads/master
Commit: a4d84d800b68b98b443cc39db12870e52f37de37
Parents: 9f4103f a9caf3c
Author: ILYA Khlopotov 
Authored: Wed Apr 20 06:45:15 2016 -0700
Committer: ILYA Khlopotov 
Committed: Wed Apr 20 06:45:15 2016 -0700

--
 rebar.config.script | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
--




<    1   2   3   4   5   6   7   >