Author: damien Date: Thu Aug 27 21:19:23 2009 New Revision: 808634 URL: http://svn.apache.org/viewvc?rev=808634&view=rev Log: Fix for problem where HEAD requests that would have a chunked responses would send the chunked respone anyway. Also, we now avoid processing the request, and instead abort it as soon as the header is sent.
Modified: couchdb/branches/0.10.x/ (props changed) couchdb/branches/0.10.x/etc/default/couchdb (props changed) couchdb/branches/0.10.x/src/couchdb/couch_httpd.erl Propchange: couchdb/branches/0.10.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Aug 27 21:19:23 2009 @@ -3,4 +3,4 @@ /couchdb/branches/form:729440-730015 /couchdb/branches/list-iterator:782292-784593 /couchdb/branches/tail_header:775760-778477 -/couchdb/trunk:807208-807478,807771 +/couchdb/trunk:807208-807478,807771,808632 Propchange: couchdb/branches/0.10.x/etc/default/couchdb ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Aug 27 21:19:23 2009 @@ -3,5 +3,5 @@ /couchdb/branches/form/etc/default/couchdb:729440-730015 /couchdb/branches/list-iterator/etc/default/couchdb:782292-784593 /couchdb/branches/tail_header/etc/default/couchdb:775760-778477 -/couchdb/trunk/etc/default/couchdb:807208-807478,807771 +/couchdb/trunk/etc/default/couchdb:807208-807478,807771,808632 /incubator/couchdb/trunk/etc/default/couchdb:642419-694440 Modified: couchdb/branches/0.10.x/src/couchdb/couch_httpd.erl URL: http://svn.apache.org/viewvc/couchdb/branches/0.10.x/src/couchdb/couch_httpd.erl?rev=808634&r1=808633&r2=808634&view=diff ============================================================================== --- couchdb/branches/0.10.x/src/couchdb/couch_httpd.erl (original) +++ couchdb/branches/0.10.x/src/couchdb/couch_httpd.erl Thu Aug 27 21:19:23 2009 @@ -153,7 +153,6 @@ end, increment_method_stats(Method1), - % alias HEAD to GET as mochiweb takes care of stripping the body Method = case Method1 of 'HEAD' -> 'GET'; @@ -180,6 +179,8 @@ Response end catch + throw:{http_head_abort, Resp0} -> + {ok, Resp0}; throw:Error -> ?LOG_DEBUG("Minor error in HTTP request: ~p",[Error]), ?LOG_DEBUG("Stacktrace: ~p",[erlang:get_stacktrace()]), @@ -360,7 +361,12 @@ 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})}. + Resp = MochiReq:start_response_length({Code, Headers ++ server_header() ++ couch_httpd_auth:cookie_auth_header(Req, Headers), Length}), + case MochiReq:get(method) of + 'HEAD' -> throw({http_head_abort, Resp}); + _ -> ok + end, + {ok, Resp}. send(Resp, Data) -> Resp:send(Data), @@ -368,7 +374,12 @@ start_chunked_response(#httpd{mochi_req=MochiReq}=Req, Code, Headers) -> couch_stats_collector:increment({httpd_status_codes, Code}), - {ok, MochiReq:respond({Code, Headers ++ server_header() ++ couch_httpd_auth:cookie_auth_header(Req, Headers), chunked})}. + Resp = MochiReq:respond({Code, Headers ++ server_header() ++ couch_httpd_auth:cookie_auth_header(Req, Headers), chunked}), + case MochiReq:get(method) of + 'HEAD' -> throw({http_head_abort, Resp}); + _ -> ok + end, + {ok, Resp}. send_chunk(Resp, Data) -> Resp:write_chunk(Data),