couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r804087 - in /couchdb/trunk/src/couchdb: couch_httpd.erl couch_httpd_db.erl
Date Fri, 14 Aug 2009 06:10:17 GMT
Author: jchris
Date: Fri Aug 14 06:10:16 2009
New Revision: 804087

URL: http://svn.apache.org/viewvc?rev=804087&view=rev
Log:
apply Benoit's patch fixing attachment content-length handling for GET from COUCHDB-461

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

Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=804087&r1=804086&r2=804087&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Fri Aug 14 06:10:16 2009
@@ -20,6 +20,7 @@
 -export([parse_form/1,json_body/1,json_body_obj/1,body/1,doc_etag/1, make_etag/1, etag_respond/3]).
 -export([primary_header_value/2,partition/1,serve_file/3, server_header/0]).
 -export([start_chunked_response/3,send_chunk/2]).
+-export([start_response_length/4, 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/4, send_redirect/2,send_chunked_error/2]).
 -export([send_json/2,send_json/3,send_json/4]).
@@ -334,7 +335,13 @@
     false -> throw({unauthorized, <<"You are not a server admin.">>})
     end.
 
+start_response_length(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Length) ->
+    couch_stats_collector:increment({httpd_status_codes, Code}),
+    {ok, MochiReq:start_response_length({Code, Headers ++ server_header() ++ couch_httpd_auth:cookie_auth_header(Req,
Headers), Length})}.
 
+send(Resp, Data) ->
+    Resp:send(Data),
+    {ok, Resp}.
 
 start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) ->
     couch_stats_collector:increment({httpd_status_codes, Code}),

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=804087&r1=804086&r2=804087&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Aug 14 06:10:16 2009
@@ -21,7 +21,8 @@
 -import(couch_httpd,
     [send_json/2,send_json/3,send_json/4,send_method_not_allowed/2,
     start_json_response/2,send_chunk/2,end_json_response/1,
-    start_chunked_response/3, absolute_uri/2]).
+    start_chunked_response/3, absolute_uri/2, send/2,
+    start_response_length/4]).
 
 -record(doc_query_args, {
     options = [],
@@ -822,24 +823,16 @@
     case [A || A <- Atts, A#att.name == FileName] of
     [] ->
         throw({not_found, "Document is missing attachment"});
-    [#att{type=Type}=Att] ->
+    [#att{type=Type, len=Len}=Att] ->
         Etag = couch_httpd:doc_etag(Doc),
         couch_httpd:etag_respond(Req, Etag, fun() ->
-            {ok, Resp} = start_chunked_response(Req, 200, [
+            {ok, Resp} = start_response_length(Req, 200, [
                 {"ETag", Etag},
                 {"Cache-Control", "must-revalidate"},
-                {"Content-Type", binary_to_list(Type)}%,
-                % My understanding of http://www.faqs.org/rfcs/rfc2616.html
-                % says that we should not use Content-Length with a chunked
-                % encoding. Turning this off makes libcurl happy, but I am
-                % open to discussion. (jchris)
-                %
-                % Can you point to the section that makes you think that? (jan)
-                % {"Content-Length", integer_to_list(couch_doc:bin_size(Bin))}
-                ]),
+                {"Content-Type", binary_to_list(Type)}
+                ], integer_to_list(Len)),
             couch_doc:att_foldl(Att,
-                    fun(BinSegment, _) -> send_chunk(Resp, BinSegment) end,[]),
-            send_chunk(Resp, "")
+                    fun(BinSegment, _) -> send(Resp, BinSegment) end,[])
         end)
     end;
 



Mime
View raw message