couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r830353 - in /couchdb/trunk/src/couchdb: couch_httpd.erl couch_httpd_misc_handlers.erl couch_httpd_show.erl
Date Tue, 27 Oct 2009 21:40:26 GMT
Author: damien
Date: Tue Oct 27 21:40:25 2009
New Revision: 830353

URL: http://svn.apache.org/viewvc?rev=830353&view=rev
Log:
Make it harder to accidently terminate chunked resposnes by requiring callers to explicity
call last_chunk(Req) and ignoring send_chunk calls with no data.

Modified:
    couchdb/trunk/src/couchdb/couch_httpd.erl
    couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
    couchdb/trunk/src/couchdb/couch_httpd_show.erl

Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=830353&r1=830352&r2=830353&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Tue Oct 27 21:40:25 2009
@@ -23,7 +23,7 @@
 -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]).
+-export([send_json/2,send_json/3,send_json/4,last_chunk/1]).
 
 start_link() ->
     % read config and register for configuration changes
@@ -422,7 +422,14 @@
     {ok, Resp}.
 
 send_chunk(Resp, Data) ->
-    Resp:write_chunk(Data),
+    case iolist_size(Data) of
+    0 -> ok; % do nothing
+    _ -> Resp:write_chunk(Data)
+    end,
+    {ok, Resp}.
+
+last_chunk(Resp) ->
+    Resp:write_chunk([]),
     {ok, Resp}.
 
 send_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers, Body) ->
@@ -473,8 +480,7 @@
 
 end_json_response(Resp) ->
     send_chunk(Resp, end_jsonp() ++ [$\n]),
-    %send_chunk(Resp, [$\n]),
-    send_chunk(Resp, []).
+    last_chunk(Resp).
 
 start_jsonp(Req) ->
     case get(jsonp) of
@@ -586,7 +592,7 @@
 % give the option for list functions to output html or other raw errors
 send_chunked_error(Resp, {_Error, {[{<<"body">>, Reason}]}}) ->
     send_chunk(Resp, Reason),
-    send_chunk(Resp, []);
+    last_chunk(Resp);
 
 send_chunked_error(Resp, Error) ->
     {Code, ErrorStr, ReasonStr} = error_info(Error),
@@ -594,7 +600,7 @@
         {<<"error">>,  ErrorStr},
         {<<"reason">>, ReasonStr}]},
     send_chunk(Resp, ?l2b([$\n,?JSON_ENCODE(JsonError),$\n])),
-    send_chunk(Resp, []).
+    last_chunk(Resp).
 
 send_redirect(Req, Path) ->
      Headers = [{"Location", couch_httpd:absolute_uri(Req, Path)}],

Modified: couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl?rev=830353&r1=830352&r2=830353&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl Tue Oct 27 21:40:25 2009
@@ -24,7 +24,7 @@
 
 -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_json_response/2,send_chunk/2,last_chunk/1,end_json_response/1,
     start_chunked_response/3, send_error/4]).
 
 % httpd global handlers
@@ -203,7 +203,7 @@
         {"Content-Length", integer_to_list(length(Chunk))}
     ]),
     send_chunk(Resp, Chunk),
-    send_chunk(Resp, "");
+    last_chunk(Resp);
 handle_log_req(Req) ->
     send_method_not_allowed(Req, "GET").
 

Modified: couchdb/trunk/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_show.erl?rev=830353&r1=830352&r2=830353&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_show.erl Tue Oct 27 21:40:25 2009
@@ -19,7 +19,7 @@
 
 -import(couch_httpd,
     [send_json/2,send_json/3,send_json/4,send_method_not_allowed/2,
-    start_json_response/2,send_chunk/2,send_chunked_error/2,
+    start_json_response/2,send_chunk/2,last_chunk/1,send_chunked_error/2,
     start_chunked_response/3, send_error/4]).
 
 handle_doc_show_req(#httpd{
@@ -365,7 +365,7 @@
             [<<"end">>, Chunks] = couch_query_servers:render_list_tail(QueryServer),
             send_non_empty_chunk(Resp, ?b2l(?l2b(Chunks)))
     end,
-    send_chunk(Resp, []).
+    last_chunk(Resp).
 
 
 render_head_for_empty_list(StartListRespFun, Req, Etag, null) ->



Mime
View raw message