You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/10/15 18:35:50 UTC

[16/25] couch commit: updated refs/heads/master to 92598cd

Extract and move multipart specific part of doc:len_doc_to_multi_part_stream into httpd_multipart:length_multipart_stream/3


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

Branch: refs/heads/master
Commit: 042c8785f74cb1a2b64e552efbcb1310651c8419
Parents: b6cccd9
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Dec 2 15:12:47 2014 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed May 6 06:55:59 2015 -0700

----------------------------------------------------------------------
 src/couch_doc.erl             | 38 ++-----------------------------------
 src/couch_httpd_multipart.erl | 39 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/042c8785/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index fd12283..0247532 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -354,42 +354,8 @@ merge_stubs(#doc{id=Id,atts=MemBins}=StubsDoc, #doc{atts=DiskBins}) ->
 len_doc_to_multi_part_stream(Boundary, JsonBytes, Atts, SendEncodedAtts) ->
     AttsToInclude = lists:filter(fun(Att) -> not couch_att:is_stub(Att) end, Atts),
     AttsDecoded = decode_attributes(AttsToInclude, SendEncodedAtts),
-    AttsSize = lists:foldl(fun({_Att, Name, Len, Type, Encoding}, AccAttsSize) ->
-          AccAttsSize +
-          4 + % "\r\n\r\n"
-          length(integer_to_list(Len)) +
-          Len +
-          4 + % "\r\n--"
-          size(Boundary) +
-          % attachment headers
-          % (the length of the Content-Length has already been set)
-          size(Name) +
-          size(Type) +
-          length("\r\nContent-Disposition: attachment; filename=\"\"") +
-          length("\r\nContent-Type: ") +
-          length("\r\nContent-Length: ") +
-          case Encoding of
-          identity ->
-              0;
-           _ ->
-              length(atom_to_list(Encoding)) +
-              length("\r\nContent-Encoding: ")
-          end
-        end, 0, AttsDecoded),
-    if AttsSize == 0 ->
-        {<<"application/json">>, iolist_size(JsonBytes)};
-    true ->
-        {<<"multipart/related; boundary=\"", Boundary/binary, "\"">>,
-            2 + % "--"
-            size(Boundary) +
-            36 + % "\r\ncontent-type: application/json\r\n\r\n"
-            iolist_size(JsonBytes) +
-            4 + % "\r\n--"
-            size(Boundary) +
-            + AttsSize +
-            2 % "--"
-            }
-    end.
+    couch_httpd_multipart:length_multipart_stream(Boundary, JsonBytes, AttsDecoded).
+
 
 doc_to_multi_part_stream(Boundary, JsonBytes, Atts, WriteFun,
     SendEncodedAtts) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/042c8785/src/couch_httpd_multipart.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_multipart.erl b/src/couch_httpd_multipart.erl
index 0477125..fc49c6e 100644
--- a/src/couch_httpd_multipart.erl
+++ b/src/couch_httpd_multipart.erl
@@ -2,6 +2,7 @@
 
 -export([encode_multipart_stream/5]).
 -export([decode_multipart_stream/3]).
+-export([length_multipart_stream/3]).
 -export([abort_multipart_stream/1]).
 
 -include_lib("couch/include/couch_db.hrl").
@@ -192,6 +193,44 @@ atts_to_mp([{Att, Name, Len, Type, Encoding} | RestAtts], Boundary, WriteFun,
     WriteFun(<<"\r\n--", Boundary/binary>>),
     atts_to_mp(RestAtts, Boundary, WriteFun, AttFun).
 
+length_multipart_stream(Boundary, JsonBytes, Atts) ->
+    AttsSize = lists:foldl(fun({_Att, Name, Len, Type, Encoding}, AccAttsSize) ->
+          AccAttsSize +
+          4 + % "\r\n\r\n"
+          length(integer_to_list(Len)) +
+          Len +
+          4 + % "\r\n--"
+          size(Boundary) +
+          % attachment headers
+          % (the length of the Content-Length has already been set)
+          size(Name) +
+          size(Type) +
+          length("\r\nContent-Disposition: attachment; filename=\"\"") +
+          length("\r\nContent-Type: ") +
+          length("\r\nContent-Length: ") +
+          case Encoding of
+          identity ->
+              0;
+           _ ->
+              length(atom_to_list(Encoding)) +
+              length("\r\nContent-Encoding: ")
+          end
+        end, 0, Atts),
+    if AttsSize == 0 ->
+        {<<"application/json">>, iolist_size(JsonBytes)};
+    true ->
+        {<<"multipart/related; boundary=\"", Boundary/binary, "\"">>,
+            2 + % "--"
+            size(Boundary) +
+            36 + % "\r\ncontent-type: application/json\r\n\r\n"
+            iolist_size(JsonBytes) +
+            4 + % "\r\n--"
+            size(Boundary) +
+            + AttsSize +
+            2 % "--"
+            }
+    end.
+
 abort_multipart_stream(Parser) ->
     MonRef = erlang:monitor(process, Parser),
     Parser ! abort_parsing,