You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Paul Davis <pa...@gmail.com> on 2009/08/27 23:20:00 UTC

Re: svn commit: r808632 - /couchdb/trunk/src/couchdb/couch_httpd.erl

Does this mean that HEAD requests for views don't return a
Content-Length header? And is that important?

Paul Davis

On Thu, Aug 27, 2009 at 5:16 PM, <da...@apache.org> wrote:
> Author: damien
> Date: Thu Aug 27 21:16:08 2009
> New Revision: 808632
>
> URL: http://svn.apache.org/viewvc?rev=808632&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/trunk/src/couchdb/couch_httpd.erl
>
> Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
> URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=808632&r1=808631&r2=808632&view=diff
> ==============================================================================
> --- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
> +++ couchdb/trunk/src/couchdb/couch_httpd.erl Thu Aug 27 21:16:08 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),
>
>
>

Re: svn commit: r808632 - /couchdb/trunk/src/couchdb/couch_httpd.erl

Posted by Paul Davis <pa...@gmail.com>.
> I believe it is important - kindof.  RFC2616 says, in summary, that the
> response to a HEAD request should be the same as for a GET, but without the
> body.  So I *think* this means couch is free to not supply a content-length
> (as it doesn't for a GET), but should still include the transfer-encoding:
> chunked header the GET returns.

Doh! I managed to get all confused and think we returned a
Content-Length for views. /ignore me.

Re: svn commit: r808632 - /couchdb/trunk/src/couchdb/couch_httpd.erl

Posted by Mark Hammond <sk...@gmail.com>.
On 28/08/2009 7:20 AM, Paul Davis wrote:
> Does this mean that HEAD requests for views don't return a
> Content-Length header? And is that important?

I believe it is important - kindof.  RFC2616 says, in summary, that the 
response to a HEAD request should be the same as for a GET, but without 
the body.  So I *think* this means couch is free to not supply a 
content-length (as it doesn't for a GET), but should still include the 
transfer-encoding: chunked header the GET returns.

I'm also fairly confident another content-length issue exists; if a 
conditional request is made for an attachment and the entity hasn't 
changed, couch correctly returns a 304 response, but incorrectly 
includes a "content-length: 0" header.  The RFC isn't quite as explicit 
about this case, but section 10.3.5 implies no content-length header 
should be returned at all in this case, even in the case where a 
content-length header would be supplied in a 200 response.

Cheers,

Mark