anchor.diff:  	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).
  
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: 	_ -> exit(normal)
      end.
  
  send_stream_body(Socket, IsChunked, X) -> 
      send_stream_body(Socket, IsChunked, X, 0).
  
  send_stream_body(Socket, IsChunked, {<<>>, done}, SoFar) ->
      send_chunk(Socket, IsChunked, <<>>),
      SoFar;
  send_stream_body(Socket, IsChunked, {Data, done}, SoFar) ->
      Size = send_chunk(Socket, IsChunked, Data),
      send_chunk(Socket, IsChunked, <<>>),
      Size + SoFar;
  send_stream_body(Socket, IsChunked, {<<>>, Next}, SoFar) ->
      send_stream_body(Socket, IsChunked, Next(), SoFar);
  send_stream_body(Socket, IsChunked, {[], Next}, SoFar) ->
      send_stream_body(Socket, IsChunked, Next(), SoFar);
  send_stream_body(Socket, IsChunked, {Data, Next}, SoFar) ->
      Size = send_chunk(Socket, IsChunked, Data),
      send_stream_body(Socket, IsChunked, Next(), Size + SoFar).
  
  
  %% @todo Remove usage of the put/get to get the number of bytes written
  %%       Use a separate process to accumulate these counts
  send_writer_body(Socket, IsChunked, {Encoder, Charsetter, BodyFun}) ->
      put(bytes_written, 0),
      Writer = fun(Data) ->
          Size = send_chunk(Socket, IsChunked, Encoder(Charsetter(Data))),
          put(bytes_written, get(bytes_written) + Size),
          Size
      end,
      BodyFun(Writer),
      send_chunk(Socket, IsChunked, <<>>),
      get(bytes_written).
  
  
  %% @todo Distinguish between HTTP/1.0 and 1.1
  %%       HTTP/1.0 should not add the size (and transfer-encoding: chunked)
  send_chunk(Socket, true, Data) ->
      Size = iolist_size(Data),
      send(Socket, mochihex:to_hex(Size)),
      send(Socket, <<"\r\n">>),
      send(Socket, Data),
      send(Socket, <<"\r\n">>),
      Size;
  send_chunk(_Socket, false, <<>>) ->
      0;
  send_chunk(Socket, false, Data) ->
      Size = iolist_size(Data),
      send(Socket, Data),
      Size.
  
  
  