diff options
author | Damien F. Katz <damien@apache.org> | 2009-08-27 21:16:08 +0000 |
---|---|---|
committer | Damien F. Katz <damien@apache.org> | 2009-08-27 21:16:08 +0000 |
commit | 37ef1fac195bcdc71374e6549295c069b5207e1a (patch) | |
tree | 27968c1b70dfece12a4dffc41d3fa7a2a729cd8f /src/couchdb/couch_httpd.erl | |
parent | 17f526b45e79efd877b21ded5d4c1c31cf2d5f7a (diff) |
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.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@808632 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd.erl')
-rw-r--r-- | src/couchdb/couch_httpd.erl | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 8da157b3..77a07511 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -153,7 +153,6 @@ handle_request(MochiReq, DefaultFun, 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 @@ handle_request(MochiReq, DefaultFun, 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 @@ verify_is_server_admin(#httpd{user_ctx=#user_ctx{roles=Roles}}) -> 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 @@ send(Resp, Data) -> 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), |