couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r937352 - /couchdb/trunk/src/couchdb/couch_httpd_db.erl
Date Fri, 23 Apr 2010 16:12:37 GMT
Author: kocolosk
Date: Fri Apr 23 16:12:37 2010
New Revision: 937352

URL: http://svn.apache.org/viewvc?rev=937352&view=rev
Log:
identity transfer w/ Content-Length when possible. thx rnewson. COUCHDB-745

Modified:
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=937352&r1=937351&r2=937352&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Apr 23 16:12:37 2010
@@ -853,7 +853,7 @@ db_attachment_req(#httpd{method='GET'}=R
     case [A || A <- Atts, A#att.name == FileName] of
     [] ->
         throw({not_found, "Document is missing attachment"});
-    [#att{type=Type, encoding=Enc}=Att] ->
+    [#att{type=Type, encoding=Enc, disk_len=DiskLen, att_len=AttLen}=Att] ->
         Etag = couch_httpd:doc_etag(Doc),
         ReqAcceptsAttEnc = lists:member(
            atom_to_list(Enc),
@@ -869,6 +869,25 @@ db_attachment_req(#httpd{method='GET'}=R
         _ ->
             []
         end,
+        Len = case {Enc, ReqAcceptsAttEnc} of
+        {identity, _} ->
+            % stored and served in identity form
+            DiskLen;
+        {_, false} when DiskLen =/= AttLen ->
+            % Stored encoded, but client doesn't accept the encoding we used,
+            % so we need to decode on the fly.  DiskLen is the identity length
+            % of the attachment.
+            DiskLen;
+        {_, true} ->
+            % Stored and served encoded.  AttLen is the encoded length.
+            AttLen;
+        _ ->
+            % We received an encoded attachment and stored it as such, so we
+            % don't know the identity length.  The client doesn't accept the
+            % encoding, and since we cannot serve a correct Content-Length
+            % header we'll fall back to a chunked response.
+            undefined
+        end,
         AttFun = case ReqAcceptsAttEnc of
         false ->
             fun couch_doc:att_foldl_decode/3;
@@ -879,9 +898,15 @@ db_attachment_req(#httpd{method='GET'}=R
             Req,
             Etag,
             fun() ->
-                {ok, Resp} = start_chunked_response(Req, 200, Headers),
-                AttFun(Att, fun(Seg, _) -> send_chunk(Resp, Seg) end, ok),
-                last_chunk(Resp)
+                case Len of
+                undefined ->
+                    {ok, Resp} = start_chunked_response(Req, 200, Headers),
+                    AttFun(Att, fun(Seg, _) -> send_chunk(Resp, Seg) end, ok),
+                    last_chunk(Resp);
+                _ ->
+                    {ok, Resp} = start_response_length(Req, 200, Headers, Len),
+                    AttFun(Att, fun(Seg, _) -> send(Resp, Seg) end, ok)
+                end
             end
         )
     end;



Mime
View raw message