You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/04/04 21:03:53 UTC
[1/5] chttpd commit: updated
refs/heads/COUCHDB-3288-remove-public-db-record to 04d26cc [Forced Update!]
Repository: couchdb-chttpd
Updated Branches:
refs/heads/COUCHDB-3288-remove-public-db-record 27cadc58d -> 04d26cc72 (forced update)
Rename max_document_size to max_http_request_size
`max_document_size` is implemented as `max_http_request_size`. There was no
real check for document size. In some cases the implementation was close enough
of a proxy (PUT-ing and GET-ing single docs), but in some edge cases, like
_bulk_docs requests the discrepancy between request size and document size
could be rather large.
The section was changed accordingly from `couchdb` to `httpd`. `httpd` was
chosen as it applies to both clustered as well as local interface.
There is a parallel effort to implement an actual max_document_size check. The
set of commit should be merged close enough together to allow for a backwards
compatible transition.
COUCHDB-2992
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/a1470e3b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/a1470e3b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/a1470e3b
Branch: refs/heads/COUCHDB-3288-remove-public-db-record
Commit: a1470e3bdbcb4b98d9cc7f5dc3641a2b008df16b
Parents: 90bd048
Author: Nick Vatamaniuc <va...@apache.org>
Authored: Tue Mar 7 18:01:33 2017 -0500
Committer: Nick Vatamaniuc <va...@apache.org>
Committed: Tue Mar 7 18:01:33 2017 -0500
----------------------------------------------------------------------
src/chttpd.erl | 4 ++--
src/chttpd_external.erl | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/a1470e3b/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index cdf6e8d..89498c0 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -629,8 +629,8 @@ body(#httpd{mochi_req=MochiReq, req_body=ReqBody}) ->
case ReqBody of
undefined ->
% Maximum size of document PUT request body (4GB)
- MaxSize = list_to_integer(
- config:get("couchdb", "max_document_size", "4294967296")),
+ MaxSize = config:get_integer("httpd", "max_http_request_size",
+ 4294967296),
Begin = os:timestamp(),
try
MochiReq:recv_body(MaxSize)
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/a1470e3b/src/chttpd_external.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_external.erl b/src/chttpd_external.erl
index 1dccf2a..4abeecb 100644
--- a/src/chttpd_external.erl
+++ b/src/chttpd_external.erl
@@ -93,7 +93,7 @@ json_req_obj_field(<<"headers">>, #httpd{mochi_req=Req}, _Db, _DocId) ->
Hlist = mochiweb_headers:to_list(Headers),
to_json_terms(Hlist);
json_req_obj_field(<<"body">>, #httpd{req_body=undefined, mochi_req=Req}, _Db, _DocId) ->
- MaxSize = config:get_integer("couchdb", "max_document_size", 4294967296),
+ MaxSize = config:get_integer("httpd", "max_http_request_size", 4294967296),
try
Req:recv_body(MaxSize)
catch exit:normal ->
[3/5] chttpd commit: updated
refs/heads/COUCHDB-3288-remove-public-db-record to 04d26cc
Posted by da...@apache.org.
Allow limiting maximum document body size
This is the HTTP layer and some tests. The actual checking is done in couch
application's from_json_obj/1 function.
If a document is too large it will return a 413 response code. The error reason
will be the document ID. The intent is to help users identify the document if
they used _bulk_docs endpoint. It will also help replicator skip over documents
which are too large.
COUCHDB-2992
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/d1848e6f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/d1848e6f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/d1848e6f
Branch: refs/heads/COUCHDB-3288-remove-public-db-record
Commit: d1848e6f2288ea9b3758c22f10f75706a87be3b5
Parents: 60f6f6a
Author: Nick Vatamaniuc <va...@apache.org>
Authored: Mon Mar 13 02:22:19 2017 -0400
Committer: Nick Vatamaniuc <va...@apache.org>
Committed: Tue Mar 14 02:57:25 2017 -0400
----------------------------------------------------------------------
src/chttpd.erl | 2 +
src/chttpd_db.erl | 8 +-
src/chttpd_show.erl | 2 +-
test/chttpd_db_doc_size_tests.erl | 173 +++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d1848e6f/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 89498c0..76eb7c3 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -891,6 +891,8 @@ error_info({missing_stub, Reason}) ->
{412, <<"missing_stub">>, Reason};
error_info(request_entity_too_large) ->
{413, <<"too_large">>, <<"the request entity is too large">>};
+error_info({request_entity_too_large, DocID}) ->
+ {413, <<"document_too_large">>, DocID};
error_info({error, security_migration_updates_disabled}) ->
{503, <<"security_migration">>, <<"Updates to security docs are disabled during "
"security migration.">>};
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d1848e6f/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index bb08db6..37e4669 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -325,7 +325,7 @@ db_req(#httpd{method='POST', path_parts=[DbName], user_ctx=Ctx}=Req, Db) ->
W = chttpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db))),
Options = [{user_ctx,Ctx}, {w,W}],
- Doc = couch_doc:from_json_obj(chttpd:json_body(Req)),
+ Doc = couch_doc:from_json_obj_validate(chttpd:json_body(Req)),
Doc2 = case Doc#doc.id of
<<"">> ->
Doc#doc{id=couch_uuids:new(), revs={0, []}};
@@ -410,7 +410,7 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
true ->
Docs = lists:map(
fun(JsonObj) ->
- Doc = couch_doc:from_json_obj(JsonObj),
+ Doc = couch_doc:from_json_obj_validate(JsonObj),
validate_attachment_names(Doc),
Id = case Doc#doc.id of
<<>> -> couch_uuids:new();
@@ -441,7 +441,7 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req,
send_json(Req, 417, ErrorsJson)
end;
false ->
- Docs = [couch_doc:from_json_obj(JsonObj) || JsonObj <- DocsArray],
+ Docs = [couch_doc:from_json_obj_validate(JsonObj) || JsonObj <- DocsArray],
[validate_attachment_names(D) || D <- Docs],
case fabric:update_docs(Db, Docs, [replicated_changes|Options]) of
{ok, Errors} ->
@@ -1050,7 +1050,7 @@ couch_doc_from_req(Req, DocId, #doc{revs=Revs} = Doc) ->
end,
Doc#doc{id=DocId, revs=Revs2};
couch_doc_from_req(Req, DocId, Json) ->
- couch_doc_from_req(Req, DocId, couch_doc:from_json_obj(Json)).
+ couch_doc_from_req(Req, DocId, couch_doc:from_json_obj_validate(Json)).
% Useful for debugging
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d1848e6f/src/chttpd_show.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_show.erl b/src/chttpd_show.erl
index bbe51b2..49fed7b 100644
--- a/src/chttpd_show.erl
+++ b/src/chttpd_show.erl
@@ -129,7 +129,7 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
_ ->
Options = [{user_ctx, Req#httpd.user_ctx}, {w, W}]
end,
- NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
+ NewDoc = couch_doc:from_json_obj_validate({NewJsonDoc}),
couch_doc:validate_docid(NewDoc#doc.id),
{UpdateResult, NewRev} = fabric:update_doc(Db, NewDoc, Options),
NewRevStr = couch_doc:rev_to_str(NewRev),
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/d1848e6f/test/chttpd_db_doc_size_tests.erl
----------------------------------------------------------------------
diff --git a/test/chttpd_db_doc_size_tests.erl b/test/chttpd_db_doc_size_tests.erl
new file mode 100644
index 0000000..d2a993e
--- /dev/null
+++ b/test/chttpd_db_doc_size_tests.erl
@@ -0,0 +1,173 @@
+% 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_db_doc_size_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+-define(USER, "chttpd_db_test_admin").
+-define(PASS, "pass").
+-define(AUTH, {basic_auth, {?USER, ?PASS}}).
+-define(CONTENT_JSON, {"Content-Type", "application/json"}).
+-define(CONTENT_MULTI_RELATED, {"Content-Type",
+ "multipart/related;boundary=\"bound\""}).
+-define(CONTENT_MULTI_FORM, {"Content-Type",
+ "multipart/form-data;boundary=\"bound\""}).
+
+
+setup() ->
+ ok = config:set("admins", ?USER, ?PASS, _Persist=false),
+ ok = config:set("couchdb", "max_document_size", "50"),
+ TmpDb = ?tempdb(),
+ Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
+ Port = mochiweb_socket_server:get(chttpd, port),
+ Url = lists:concat(["http://", Addr, ":", Port, "/", ?b2l(TmpDb)]),
+ create_db(Url),
+ Url.
+
+teardown(Url) ->
+ delete_db(Url),
+ ok = config:delete("admins", ?USER, _Persist=false),
+ ok = config:delete("couchdb", "max_document_size").
+
+create_db(Url) ->
+ {ok, Status, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"),
+ ?assert(Status =:= 201 orelse Status =:= 202).
+
+delete_db(Url) ->
+ {ok, 200, _, _} = test_request:delete(Url, [?AUTH]).
+
+all_test_() ->
+ {
+ "chttpd db max_document_size tests",
+ {
+ setup,
+ fun chttpd_test_util:start_couch/0, fun chttpd_test_util:stop_couch/1,
+ {
+ foreach,
+ fun setup/0, fun teardown/1,
+ [
+ fun post_single_doc/1,
+ fun put_single_doc/1,
+ fun bulk_doc/1,
+ fun put_post_doc_attach_inline/1,
+ fun put_multi_part_related/1,
+ fun post_multi_part_form/1
+ ]
+ }
+ }
+ }.
+
+post_single_doc(Url) ->
+ ?_assertEqual({<<"error">>, <<"document_too_large">>},
+ begin
+ NewDoc = "{\"post_single_doc\": \"some_doc\",
+ \"_id\": \"testdoc\", \"should_be\" : \"too_large\"}",
+ {ok, _, _, ResultBody} = test_request:post(Url,
+ [?CONTENT_JSON, ?AUTH], NewDoc),
+ {ErrorMsg} = ?JSON_DECODE(ResultBody),
+ lists:nth(1, ErrorMsg)
+ end).
+
+put_single_doc(Url) ->
+ ?_assertEqual({<<"error">>, <<"document_too_large">>},
+ begin
+ NewDoc = "{\"post_single_doc\": \"some_doc\",
+ \"_id\": \"testdoc\", \"should_be\" : \"too_large\"}",
+ {ok, _, _, ResultBody} = test_request:put(Url ++ "/" ++ "testid",
+ [?CONTENT_JSON, ?AUTH], NewDoc),
+ {ErrorMsg} = ?JSON_DECODE(ResultBody),
+ lists:nth(1, ErrorMsg)
+ end).
+
+bulk_doc(Url) ->
+ NewDoc = "{\"docs\": [{\"doc1\": 1}, {\"errordoc\":
+ \"this_should_be_the_error_document\"}]}",
+ {ok, _, _, ResultBody} = test_request:post(Url ++ "/_bulk_docs/",
+ [?CONTENT_JSON, ?AUTH], NewDoc),
+ ResultJson = ?JSON_DECODE(ResultBody),
+ Expect = {[{<<"error">>,<<"document_too_large">>},{<<"reason">>,<<>>}]},
+ ?_assertEqual(Expect, ResultJson).
+
+put_post_doc_attach_inline(Url) ->
+ Body1 = "{\"body\":\"This is a body.\",",
+ Body2 = lists:concat(["{\"body\":\"This is a body it should fail",
+ "because there are too many characters.\","]),
+ DocRest = lists:concat(["\"_attachments\":{\"foo.txt\":{",
+ "\"content_type\":\"text/plain\",",
+ "\"data\": \"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=\"}}}"]),
+ Doc1 = lists:concat([Body1, DocRest]),
+ Doc2 = lists:concat([Body2, DocRest]),
+
+ {ok, _, _, ResultBody} = test_request:post(Url,
+ [?CONTENT_JSON, ?AUTH], Doc1),
+ {Msg} = ?JSON_DECODE(ResultBody),
+ ?_assertEqual({<<"ok">>, true}, lists:nth(1, Msg)),
+ {ok, _, _, ResultBody1} = test_request:post(Url,
+ [?CONTENT_JSON, ?AUTH], Doc2),
+ {Msg1} = ?JSON_DECODE(ResultBody1),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, lists:nth(1, Msg1)),
+
+ {ok, _, _, ResultBody2} = test_request:put(Url ++ "/" ++ "accept",
+ [?CONTENT_JSON, ?AUTH], Doc1),
+ {Msg2} = ?JSON_DECODE(ResultBody2),
+ ?_assertEqual({<<"ok">>, true}, lists:nth(1, Msg2)),
+ {ok, _, _, ResultBody3} = test_request:put(Url ++ "/" ++ "fail",
+ [?CONTENT_JSON, ?AUTH], Doc2),
+ {Msg3} = ?JSON_DECODE(ResultBody3),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, lists:nth(1, Msg3)).
+
+put_multi_part_related(Url) ->
+ Body1 = "{\"body\":\"This is a body.\",",
+ Body2 = lists:concat(["{\"body\":\"This is a body it should fail",
+ "because there are too many characters.\","]),
+ DocBeg = "--bound\r\nContent-Type: application/json\r\n\r\n",
+ DocRest = lists:concat(["\"_attachments\":{\"foo.txt\":{\"follows\":true,",
+ "\"content_type\":\"text/plain\",\"length\":21},\"bar.txt\":",
+ "{\"follows\":true,\"content_type\":\"text/plain\",",
+ "\"length\":20}}}\r\n--bound\r\n\r\nthis is 21 chars long",
+ "\r\n--bound\r\n\r\nthis is 20 chars lon\r\n--bound--epilogue"]),
+ Doc1 = lists:concat([DocBeg, Body1, DocRest]),
+ Doc2 = lists:concat([DocBeg, Body2, DocRest]),
+ {ok, _, _, ResultBody} = test_request:put(Url ++ "/" ++ "accept",
+ [?CONTENT_MULTI_RELATED, ?AUTH], Doc1),
+ {Msg} = ?JSON_DECODE(ResultBody),
+ ?_assertEqual({<<"ok">>, true}, lists:nth(1, Msg)),
+ {ok, _, _, ResultBody1} = test_request:put(Url ++ "/" ++ "faildoc",
+ [?CONTENT_MULTI_RELATED, ?AUTH], Doc2),
+ {Msg1} = ?JSON_DECODE(ResultBody1),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, lists:nth(1, Msg1)).
+
+post_multi_part_form(Url) ->
+ Port = mochiweb_socket_server:get(chttpd, port),
+ Host = lists:concat([ "http://127.0.0.1:", Port]),
+ Referer = {"Referer", Host},
+ Body1 = "{\"body\":\"This is a body.\"}",
+ Body2 = lists:concat(["{\"body\":\"This is a body it should fail",
+ "because there are too many characters.\"}"]),
+ DocBeg = "--bound\r\nContent-Disposition: form-data; name=\"_doc\"\r\n\r\n",
+ DocRest = lists:concat(["\r\n--bound\r\nContent-Disposition:",
+ "form-data; name=\"_attachments\"; filename=\"file.txt\"\r\n",
+ "Content-Type: text/plain\r\n\r\ncontents of file.txt\r\n\r\n",
+ "--bound--"]),
+ Doc1 = lists:concat([DocBeg, Body1, DocRest]),
+ Doc2 = lists:concat([DocBeg, Body2, DocRest]),
+ {ok, _, _, ResultBody} = test_request:post(Url ++ "/" ++ "accept",
+ [?CONTENT_MULTI_FORM, ?AUTH, Referer], Doc1),
+ {Msg} = ?JSON_DECODE(ResultBody),
+ ?_assertEqual({<<"ok">>, true}, lists:nth(1, Msg)),
+ {ok, _, _, ResultBody1} = test_request:post(Url ++ "/" ++ "fail",
+ [?CONTENT_MULTI_FORM, ?AUTH, Referer], Doc2),
+ {Msg1} = ?JSON_DECODE(ResultBody1),
+ ?_assertEqual({<<"error">>, <<"document_too_large">>}, lists:nth(1, Msg1)).
+
[4/5] chttpd commit: updated
refs/heads/COUCHDB-3288-remove-public-db-record to 04d26cc
Posted by da...@apache.org.
Merge branch 'couchdb-2992'
Closes #157
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/74002101
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/74002101
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/74002101
Branch: refs/heads/COUCHDB-3288-remove-public-db-record
Commit: 74002101513c03df74a4c25f3c892f5d003fa5da
Parents: 60f6f6a d1848e6
Author: Nick Vatamaniuc <va...@apache.org>
Authored: Wed Mar 15 22:36:56 2017 -0400
Committer: Nick Vatamaniuc <va...@apache.org>
Committed: Wed Mar 15 22:36:56 2017 -0400
----------------------------------------------------------------------
src/chttpd.erl | 2 +
src/chttpd_db.erl | 8 +-
src/chttpd_show.erl | 2 +-
test/chttpd_db_doc_size_tests.erl | 173 +++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
[5/5] chttpd commit: updated
refs/heads/COUCHDB-3288-remove-public-db-record to 04d26cc
Posted by da...@apache.org.
Remove public db record
COUCHDB-3288
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/04d26cc7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/04d26cc7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/04d26cc7
Branch: refs/heads/COUCHDB-3288-remove-public-db-record
Commit: 04d26cc72cf2b3334e1796e48955e8cd79488484
Parents: 7400210
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Feb 1 12:32:15 2017 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Apr 4 16:03:12 2017 -0500
----------------------------------------------------------------------
src/chttpd_db.erl | 21 ++++++++++++---------
src/chttpd_external.erl | 22 ++++++++++++++--------
src/chttpd_show.erl | 3 ++-
3 files changed, 28 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/04d26cc7/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 37e4669..aed649d 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -84,7 +84,7 @@ handle_changes_req1(#httpd{}=Req, Db) ->
#changes_args{filter=Raw, style=Style} = Args0 = parse_changes_query(Req),
ChangesArgs = Args0#changes_args{
filter_fun = couch_changes:configure_filter(Raw, Style, Req, Db),
- db_open_options = [{user_ctx, Db#db.user_ctx}]
+ db_open_options = [{user_ctx, couch_db:get_user_ctx(Db)}]
},
Max = chttpd:chunked_response_buffer_size(),
case ChangesArgs#changes_args.feed of
@@ -253,7 +253,7 @@ handle_view_cleanup_req(Req, Db) ->
handle_design_req(#httpd{
path_parts=[_DbName, _Design, Name, <<"_",_/binary>> = Action | _Rest]
}=Req, Db) ->
- DbName = mem3:dbname(Db#db.name),
+ DbName = mem3:dbname(couch_db:name(Db)),
case ddoc_cache:open(DbName, <<"_design/", Name/binary>>) of
{ok, DDoc} ->
Handler = chttpd_handlers:design_handler(Action, fun bad_action_req/3),
@@ -309,7 +309,8 @@ delete_db_req(#httpd{}=Req, DbName) ->
do_db_req(#httpd{path_parts=[DbName|_], user_ctx=Ctx}=Req, Fun) ->
fabric:get_security(DbName, [{user_ctx,Ctx}]), % calls check_is_reader
- Fun(Req, #db{name=DbName, user_ctx=Ctx}).
+ {ok, Db} = couch_db:clustered_db(DbName, Ctx),
+ Fun(Req, Db).
db_req(#httpd{method='GET',path_parts=[DbName]}=Req, _Db) ->
% measure the time required to generate the etag, see if it's worth it
@@ -767,16 +768,17 @@ db_doc_req(#httpd{method='PUT', user_ctx=Ctx}=Req, Db, DocId) ->
} = parse_doc_query(Req),
couch_doc:validate_docid(DocId),
+ DbName = couch_db:name(Db),
W = chttpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db))),
Options = [{user_ctx,Ctx}, {w,W}],
- Loc = absolute_uri(Req, [$/, couch_util:url_encode(Db#db.name),
+ Loc = absolute_uri(Req, [$/, couch_util:url_encode(DbName),
$/, couch_util:url_encode(DocId)]),
RespHeaders = [{"Location", Loc}],
case couch_util:to_list(couch_httpd:header_value(Req, "Content-Type")) of
("multipart/related;" ++ _) = ContentType ->
couch_httpd:check_max_request_length(Req),
- couch_httpd_multipart:num_mp_writers(mem3:n(mem3:dbname(Db#db.name), DocId)),
+ couch_httpd_multipart:num_mp_writers(mem3:n(mem3:dbname(DbName), DocId)),
{ok, Doc0, WaitFun, Parser} = couch_doc:doc_from_multi_part_stream(ContentType,
fun() -> receive_request_data(Req) end),
Doc = couch_doc_from_req(Req, DocId, Doc0),
@@ -833,8 +835,9 @@ db_doc_req(#httpd{method='COPY', user_ctx=Ctx}=Req, Db, SourceDocId) ->
HttpCode = 202
end,
% respond
+ DbName = couch_db:name(Db),
{PartRes} = update_doc_result_to_json(TargetDocId, {ok, NewTargetRev}),
- Loc = absolute_uri(Req, "/" ++ couch_util:url_encode(Db#db.name) ++ "/" ++ couch_util:url_encode(TargetDocId)),
+ Loc = absolute_uri(Req, "/" ++ couch_util:url_encode(DbName) ++ "/" ++ couch_util:url_encode(TargetDocId)),
send_json(Req, HttpCode,
[{"Location", Loc},
{"ETag", "\"" ++ ?b2l(couch_doc:rev_to_str(NewTargetRev)) ++ "\""}],
@@ -1057,8 +1060,8 @@ couch_doc_from_req(Req, DocId, Json) ->
% couch_doc_open(Db, DocId) ->
% couch_doc_open(Db, DocId, nil, []).
-couch_doc_open(#db{} = Db, DocId, Rev, Options0) ->
- Options = [{user_ctx, Db#db.user_ctx} | Options0],
+couch_doc_open(Db, DocId, Rev, Options0) ->
+ Options = [{user_ctx, couch_db:get_user_ctx(Db)} | Options0],
case Rev of
nil -> % open most recent rev
case fabric:open_doc(Db, DocId, Options) of
@@ -1258,7 +1261,7 @@ db_attachment_req(#httpd{method=Method, user_ctx=Ctx}=Req, Db, DocId, FileNamePa
HttpCode = 202
end,
erlang:put(mochiweb_request_recv, true),
- #db{name=DbName} = Db,
+ DbName = couch_db:name(Db),
{Status, Headers} = case Method of
'DELETE' ->
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/04d26cc7/src/chttpd_external.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_external.erl b/src/chttpd_external.erl
index 4abeecb..64664b9 100644
--- a/src/chttpd_external.erl
+++ b/src/chttpd_external.erl
@@ -120,16 +120,22 @@ json_req_obj_field(<<"secObj">>, #httpd{user_ctx=UserCtx}, Db, _DocId) ->
get_db_security(Db, UserCtx).
-get_db_info(#db{main_pid = nil} = Db) ->
- fabric:get_db_info(Db);
-get_db_info(#db{} = Db) ->
- couch_db:get_db_info(Db).
+get_db_info(Db) ->
+ case couch_db:is_clustered(Db) of
+ true ->
+ fabric:get_db_info(Db);
+ false ->
+ couch_db:get_db_info(Db)
+ end.
-get_db_security(#db{main_pid = nil}=Db, #user_ctx{}) ->
- fabric:get_security(Db);
-get_db_security(#db{}=Db, #user_ctx{}) ->
- couch_db:get_security(Db).
+get_db_security(Db, #user_ctx{}) ->
+ case couch_db:is_clustered(Db) of
+ true ->
+ fabric:get_security(Db);
+ false ->
+ couch_db:get_security(Db)
+ end.
to_json_terms(Data) ->
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/04d26cc7/src/chttpd_show.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_show.erl b/src/chttpd_show.erl
index 49fed7b..0b45495 100644
--- a/src/chttpd_show.erl
+++ b/src/chttpd_show.erl
@@ -196,7 +196,8 @@ handle_view_list_req(Req, _Db, _DDoc) ->
handle_view_list(Req, Db, DDoc, LName, {ViewDesignName, ViewName}, Keys) ->
%% Will throw an exception if the _list handler is missing
couch_util:get_nested_json_value(DDoc#doc.body, [<<"lists">>, LName]),
- {ok, VDoc} = ddoc_cache:open(Db#db.name, <<"_design/", ViewDesignName/binary>>),
+ DbName = couch_db:name(Db),
+ {ok, VDoc} = ddoc_cache:open(DbName, <<"_design/", ViewDesignName/binary>>),
CB = fun couch_mrview_show:list_cb/2,
QueryArgs = couch_mrview_http:parse_params(Req, Keys),
Options = [{user_ctx, Req#httpd.user_ctx}],
[2/5] chttpd commit: updated
refs/heads/COUCHDB-3288-remove-public-db-record to 04d26cc
Posted by da...@apache.org.
Merge remote-tracking branch 'cloudant/64299-add-new-request-parameter'
Close #156
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/60f6f6a8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/60f6f6a8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/60f6f6a8
Branch: refs/heads/COUCHDB-3288-remove-public-db-record
Commit: 60f6f6a8be1d8334241f40a34516e5c9ba30a9f4
Parents: 90bd048 a1470e3
Author: Nick Vatamaniuc <va...@apache.org>
Authored: Tue Mar 7 19:13:53 2017 -0500
Committer: Nick Vatamaniuc <va...@apache.org>
Committed: Tue Mar 7 19:13:53 2017 -0500
----------------------------------------------------------------------
src/chttpd.erl | 4 ++--
src/chttpd_external.erl | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------