anchor.diff:  store({handler_integer, TO} = Conf, _) when is_integer(TO)->
     {ok, Conf}.
   
  -do(ModRec) ->
  -  case defer_response(ModRec) of
  -    false-> {proceed, safe_handle(ModRec)};
  -    true -> {proceed, ModRec#mod.data}
  +do(M) ->
  +  case defer_response(M) of
  +    false-> {proceed, safe_handle(M)};
  +    true -> {proceed, M#mod.data}
     end.
   
   %% we guarantee that handle/1 succeeds (in which case we send a 200) or we
   %% generate a 404.
  -safe_handle(ModRec) ->
  -  try handle(ModRec)
  -  catch _:_ -> fourofour(ModRec)
  +safe_handle(M) ->
  +  try handle(M)
  +  catch _:_ -> fourofour(M)
     end.
   
   %% true if some other mod_* has already handled the request
  
positive.code:   (HTTPV =/= "HTTP/1.1") orelse httpd_response:is_disable_chunked_send(Db).
  
  %% we spawn into the handler fun, monitors it, and waits for data chunks.
  handle(ModRec) ->
    Self = self(),
    {M,F} = mod_get(ModRec,handler_function),
    S = #s{chunked_send_p=chunked_send_p(ModRec),
           timeout=mod_get(ModRec,handler_timeout)},
    Act = fun(defer) -> exit(defer);(L) -> Self ! {self(),L} end,
    Mod = lists:zip(record_info(fields,mod),tl(tuple_to_list(ModRec))),
    Req = fun(all) -> proplists:unfold(Mod);
             (Key) -> proplists:get_value(Key,Mod) end,
    loop(spawn_monitor(fun() -> M:F(Act,Req) end),S,ModRec).
  
  mod_get(ModRec,Key) ->
    httpd_util:lookup(ModRec#mod.config_db,Key,default(Key)).
  
  loop({Pid,Ref},S,ModRec) ->
    Timeout = S#s.timeout,
    receive
      {Pid,Chunk} -> loop({Pid,Ref},chunk(Chunk,S,ModRec),ModRec);
      {'DOWN',Ref,_,Pid,Reason} ->
        case {S#s.state,Reason} of
          {sent_headers,defer} -> twohundred(ModRec,S);
          {_,defer}            -> ModRec#mod.data;
          {init,normal}        -> fourofour(ModRec);
          {_,normal}           -> twohundred(ModRec,S);
          {sent_headers,_}     -> twohundred(ModRec,S);
          {_,_}                -> fourofour(ModRec)
        end
    after
      Timeout ->
        exit(Pid,kill),
        loop({Pid,Ref},S,ModRec)
    end.
  
  %% all went well. response is 200.
  twohundred(ModRec,S) ->
    case S#s.state of
      has_headers -> send_unchunked(200,ModRec,S#s.headers,S#s.chunks);
      sent_headers-> send_final_chunk(ModRec)
    end,
    [{response, {already_sent, 200, S#s.length}} | ModRec#mod.data].
  
  fourofour(ModRec) ->
    Len = send_unchunked(404,ModRec,[{"connection","close"}],"nothing here."),
    [{response,{already_sent,404,Len}} | ModRec#mod.data].
  
  %% got a chunk. it's either headers or a body part.
  %% if we don't get headers first time, use default headers.
  %% if we're not usung chunked encoding, stash everything.
  %% if we are using chunked encoding, send every chunk we get.
  chunk(Chnk,S,ModRec) ->
    Chunk = to_list(Chnk),
    case S#s.state of
      init ->
        {Headers,Body} = check_headers(Chunk),
        case S#s.chunked_send_p of
          true ->
            send_headers(true,ModRec,Headers),
            send_chunk(ModRec,Body),
            Len = S#s.length + length(Body),
            S#s{state=sent_headers,chunks=[],length=Len};
          false->
  
negative.code: 
  %%%% send stuff
  %% not chunking
  send_headers(false,M,Headers) ->
    send_header(M,200,[{"connection","close"} | Headers]);
  %% chunking
  send_headers(true,M,Headers) ->
    send_header(M,200,[{"transfer-encoding","chunked"} | Headers]).
  
  %% wrapper around httpd_response
  send_header(M,Status,HTTPHeaders) ->
    ExtraHeaders = read_header_cache(M),
    httpd_response:send_header(M,Status,ExtraHeaders++HTTPHeaders).
  
  send_chunk(M,Chunk) ->
    httpd_response:send_chunk(M,Chunk,false).
  
  send_final_chunk(M) ->
    httpd_response:send_final_chunk(M,false).
  
  send_unchunked(Status,M,Headers,Body) ->
    Len = integer_to_list(lists:flatlength(Body)),
    send_headers(false,M,[{"content-length",Len} | Headers]),
    httpd_response:send_body(M,Status,Body),
    Len.
  
  read_header_cache(M) ->
    try httpd_response:cache_headers(M)                % -R15
    catch
      _:undef ->
        httpd_response:cache_headers(M,script_nocache) % R16-
    end.
  