anchor.diff:  set_socket_active_once(#state{sock=S}) ->
       ok = inet:setopts(S, [{active, once}]).
   
  +%%%===================================================================
  +%%% Request init / pre app dispatch
  +%%%===================================================================
  +
   set_request(Method, Path, Ver, State) ->
       State#state{
         env=init_env(Method, Path, Ver),
  
positive.code: init_socket(Sock) ->
      ok = inet:setopts(Sock, [{nodelay, true}]).
  
  handle_msg({http, _, {http_request, Method, Path, Ver}}, _From, State) ->
      set_socket_active_once(State),
      {noreply, set_request(Method, Path, Ver, State)};
  
negative.code: decode_urlencoded_form_data(Data) ->
      psycho_util:parse_query_string(Data).
  
  %%%===================================================================
  %%% multipart form data
  %%%===================================================================
  
  handle_app_recv_multipart(_App, State, _Options) ->
      respond(internal_error("TODO: we'll get there"), State),
      error({"Implement multipart form data"}).
  
  %%%===================================================================
  %%% recv related general/shared functions
  %%%===================================================================
  
  safe_recv_len(Requested, #state{req_content_len=Total, recv_len=Received}) ->
      min(Requested, Total - Received).
  
  recv_remaining(Timeout, State) ->
      recv(remaining_len(State), Timeout, State).
  
  remaining_len(#state{req_content_len=Total, recv_len=Received}) ->
      Total - Received.
  
  recv(Length, Timeout, #state{sock=Sock}) when Length > 0 ->
      gen_tcp:recv(Sock, Length, Timeout);
  recv(_Length, _Timeout, _State) ->
      {ok, <<>>}.
  
  setenv(Env, S) -> S#state{env=Env}.
  
  internal_error() ->
      internal_error("Server error").
  
  internal_error(Msg) ->
      {?status_internal_server_error, [{"Content-Type", "text/plain"}], Msg}.
  
  is_eof(<<>>) -> true;
  is_eof(_) -> false.
  
  error_on_recv_body_after_eof(false, _Result, _App) -> ok;
  error_on_recv_body_after_eof(true, {recv_body, _, _, _}, App) ->
      error({recv_body_after_eof, App});
  error_on_recv_body_after_eof(true, {recv_body, _, _, _, _}, App) ->
      error({recv_body_after_eof, App});
  error_on_recv_body_after_eof(true, _Result, _App) -> ok.
  
  increment_recv_len(I, #state{recv_len=Len}=S) ->
      S#state{recv_len=I + Len}.
  
  %%%===================================================================
  %%% Response
  %%%===================================================================
  
  respond({Status, Headers, Body}, State) ->
      respond(finalize_response(set_response(Status, Headers, Body, State))).
  