anchor.diff:    req_body :: binary(),
   
     res_status :: integer(),
  -  res_headers = [] :: [{iolist(), iolist()}]
  +  res_headers = [] :: [{iolist(), iolist()}],
  +
  +  content_length = 0,
  +  sent_length = 0
   }).
   
   -define(DEFAULT_TIMEOUT, 5000).
  
positive.code:   {ok, Req2} = cowboy_req:reply(StatusCode, Req),
    terminate(Req2, State).
  
  terminate(Req, State=#state{env=Env}) ->
    proxy_terminate(Req, State),
    {ok, Req, [{result, ok}|Env]}.
  
  -spec error_terminate(cowboy_req:req(), #state{}) -> no_return().
  
negative.code:   % after Timeout
    end.
  
  get_res_body(Req, State = #state{conn = Conn, content_length = Length, sent_length = Sent}) ->
    inet:setopts(Conn, [{active, once}, {packet, raw}]),
    receive
      {tcp, Conn, Data} ->
        ok = cowboy_req:chunk(Data, Req),
        ChunkLength = byte_size(Data),
        NewSent = ChunkLength + Sent,
        case NewSent >= Length of
          true ->
            terminate(Req, State);
          _ ->
            get_res_body(Req, State#state{sent_length = NewSent})
        end;
      {tcp_closed, Conn} ->
        terminate(Req, State);
      {cowboy_req, resp_sent} ->
        get_res_body(Req, State);
      Other ->
        io:format("Unhandled message: ~p~n", [Other]),
        get_res_body(Req, State)
    %% TODO add a response timeout
    % after Timeout
    end.
  
  % internal
  
  