You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2016/04/22 08:02:18 UTC

[2/5] chttpd commit: updated refs/heads/2992-limit-doc-size to 1ac365d

Use doc body after parsing

We use the #doc.body because we only care about the json body. Inline
attachments are already stripped away

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/b0e54930
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/b0e54930
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/b0e54930

Branch: refs/heads/2992-limit-doc-size
Commit: b0e54930ad341b7385f48d8f06a9455372115e98
Parents: 03fdcde
Author: Tony Sun <to...@cloudant.com>
Authored: Wed Apr 20 15:38:49 2016 -0700
Committer: Tony Sun <to...@cloudant.com>
Committed: Wed Apr 20 15:38:49 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/b0e54930/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index fdfd03d..d30a89b 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -309,10 +309,8 @@ 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}],
 
-    Body = chttpd:json_body(Req),
-    ok = maybe_verify_body_size(Body),
-
-    Doc = couch_doc:from_json_obj(Body),
+    Doc = couch_doc:from_json_obj(chttpd:json_body(Req)),
+    ok = maybe_verify_body_size(Doc#doc.body),
     Doc2 = case Doc#doc.id of
         <<"">> ->
             Doc#doc{id=couch_uuids:new(), revs={0, []}};
@@ -769,10 +767,8 @@ db_doc_req(#httpd{method='PUT', user_ctx=Ctx}=Req, Db, DocId) ->
         case chttpd:qs_value(Req, "batch") of
         "ok" ->
             % batch
-            Body = chttpd:json_body(Req),
-            ok = maybe_verify_body_size(Body),
-            Doc = couch_doc_from_req(Req, DocId, Body),
-
+            Doc = couch_doc_from_req(Req, DocId, chttpd:json_body(Req)),
+            ok = maybe_verify_body_size(Doc#doc.body),
             spawn(fun() ->
                     case catch(fabric:update_doc(Db, Doc, Options)) of
                     {ok, _} -> ok;
@@ -788,8 +784,8 @@ db_doc_req(#httpd{method='PUT', user_ctx=Ctx}=Req, Db, DocId) ->
         _Normal ->
             % normal
             Body = chttpd:json_body(Req),
-            ok = maybe_verify_body_size(Body),
             Doc = couch_doc_from_req(Req, DocId, Body),
+            ok = maybe_verify_body_size(Doc#doc.body),
             send_updated_doc(Req, Db, DocId, Doc, RespHeaders, UpdateType)
         end
     end;