couchdb-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=804094&view=rev
Log:
benoitc's attachment PUT patch passes tests for me. Closes 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=804094&r1=804093&r2=804094&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Fri Aug 14 06:58:30 2009
@@ -15,7 +15,7 @@
 
 -export([start_link/0, stop/0, handle_request/5]).
 
--export([header_value/2,header_value/3,qs_value/2,qs_value/3,qs/1,path/1,absolute_uri/2]).
+-export([header_value/2,header_value/3,qs_value/2,qs_value/3,qs/1,path/1,absolute_uri/2,body_length/1]).
 -export([verify_is_server_admin/1,unquote/1,quote/1,recv/2,recv_chunked/4,error_info/1]).
 -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]).
@@ -281,6 +281,17 @@
     % Fun({Length, Binary}, State)
     % called with Length == 0 on the last time.
     MochiReq:stream_body(MaxChunkSize, ChunkFun, InitState).
+    
+body_length(Req) ->
+    case header_value(Req, "Transfer-Encoding") of
+        undefined ->
+            case header_value(Req, "Content-Length") of
+                undefined -> undefined;
+                Length -> list_to_integer(Length)
+            end;
+        "chunked" -> chunked;
+        Unknown -> {unknown_transfer_encoding, Unknown}
+    end.
 
 body(#httpd{mochi_req=MochiReq, req_body=ReqBody}) ->
     case ReqBody of

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=804094&r1=804093&r2=804094&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Aug 14 06:58:30 2009
@@ -858,14 +858,22 @@
                     CType ->
                         list_to_binary(CType)
                     end,
-                data = case couch_httpd:header_value(Req,"Content-Length") of
+                data = case couch_httpd:body_length(Req) of
                     undefined ->
+                        undefined;
+                    {unknown_transfer_encoding, Unknown} ->
+                        exit({unknown_transfer_encoding, Unknown});
+                    chunked ->
                         fun(MaxChunkSize, ChunkFun, InitState) ->
                             couch_httpd:recv_chunked(Req, MaxChunkSize,
                                 ChunkFun, InitState)
                         end;
+                    0 ->
+                        <<>>;
+                    Length when is_integer(Length) ->
+                        fun() -> couch_httpd:recv(Req, 0) end;
                     Length ->
-                        fun() -> couch_httpd:recv(Req, 0) end
+                        exit({length_not_integer, Length})
                     end,
                 len = case couch_httpd:header_value(Req,"Content-Length") of
                     undefined ->



Mime
View raw message