anchor.diff:  make_version(_) ->
       <<"HTTP/1.1 ">>.
   
  -make_headers(Code, Length, RD) ->
  +make_headers(Code, Transfer, Length, RD) ->
       Hdrs0 = case Code of
           304 ->
               mochiweb_headers:make(wrq:resp_headers(RD));
           _ -> 
  -            case Length of
  -                chunked ->
  -                    mochiweb_headers:enter(
  -                      "Transfer-Encoding","chunked",
  -                      mochiweb_headers:make(wrq:resp_headers(RD)));
  -                _ ->
  +            LengthHeaders = case Length of
  +                undefined ->
  +                    mochiweb_headers:make(wrq:resp_headers(RD));
  +                _Length -> 
                       mochiweb_headers:enter(
                         "Content-Length",integer_to_list(Length),
                         mochiweb_headers:make(wrq:resp_headers(RD)))
  +            end,
  +            
  +            case is_chunked_transfer(wrq:version(RD), Transfer) of
  +                true ->
  +                    mochiweb_headers:enter(
  +                      "Transfer-Encoding","chunked",
  +                      LengthHeaders);
  +                false ->
  +                    LengthHeaders
               end
       end,
       ServerHeader = "MochiWeb/1.1 WebMachine/" ++ ?WMVSN ++ " Zotonic/" ++ ?ZOTONIC_VERSION,
  
positive.code: 
  send_response(Code, ReqData) ->
      Body0 = wrq:resp_body(ReqData),
      {Body,Length} = case Body0 of
          {stream, StreamBody} -> {{stream, StreamBody}, chunked};
          {writer, WriteBody} -> {{writer, WriteBody}, chunked};
          _ -> {Body0, iolist_size([Body0])}
      end,
      send(ReqData#wm_reqdata.socket,
          [make_version(wrq:version(ReqData)),
           make_code(Code), <<"\r\n">> | 
           make_headers(Code, Length, ReqData)]),
      FinalLength = case wrq:method(ReqData) of 
  	'HEAD' ->
  	    Length;
  	_ -> 
          case Body of
              {stream, Body2} ->
                  send_stream_body(ReqData#wm_reqdata.socket, Body2);
              {writer, Body2} ->
                  send_writer_body(ReqData#wm_reqdata.socket, Body2);
              _ ->
                  send(ReqData#wm_reqdata.socket, Body),
                  Length
  
negative.code: 	end,
      lists:foldl(F, [<<"\r\n">>], mochiweb_headers:to_list(Hdrs)).
  
  
  is_chunked_transfer(HttpVersion, chunked) when HttpVersion > {1,0} -> true;
  is_chunked_transfer(_, _) -> false.
  
  
  socket(ReqData) -> ReqData#wm_reqdata.socket.
  
  method(ReqData) -> wrq:method(ReqData).
  