Permalink
Browse files

backwards incomp cahnge with flags in gc and sc instead of many bools…

…, chunk bugs in revproxy, possibility to not copy the error_log, workaround buggy error_logger_file_h which doesn't append when you reopen a file, now we have the report files kept over restarts

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@628 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent e2f272a commit 7fd4ad4e58aad2fdf23026ab2d0fdbfa7b0ce585 @klacke committed Mar 11, 2004
Showing with 277 additions and 142 deletions.
  1. +66 −12 include/yaws.hrl
  2. +9 −0 man/yaws.conf.5
  3. +2 −1 src/Makefile
  4. +6 −1 src/yaws.erl
  5. +1 −1 src/yaws_api.erl
  6. +46 −42 src/yaws_config.erl
  7. +12 −35 src/yaws_debug.erl
  8. +27 −14 src/yaws_log.erl
  9. +59 −0 src/yaws_log_file_h.erl
  10. +7 −1 src/yaws_revproxy.erl
  11. +30 −26 src/yaws_server.erl
  12. +12 −9 www/todo.yaws
View
78 include/yaws.hrl
@@ -8,12 +8,40 @@
-author('klacke@hyber.org').
+
+%% flags for gconfs
+-define(GC_TTY_TRACE, 1).
+-define(GC_DEBUG, 2).
+-define(GC_AUTH_LOG, 4).
+-define(GC_COPY_ERRLOG, 8).
+
+
+-define(GC_DEF, ?GC_AUTH_LOG).
+
+-define(gc_has_tty_trace(GC),
+ ((GC#gconf.flags band ?GC_TTY_TRACE) /= 0)).
+-define(gc_has_debug(GC),
+ ((GC#gconf.flags band ?GC_DEBUG) /= 0)).
+-define(gc_has_auth_log(GC),
+ ((GC#gconf.flags band ?GC_AUTH_LOG) /= 0)).
+-define(gc_has_copy_errlog(GC),
+ ((GC#gconf.flags band ?GC_COPY_ERRLOG) /= 0)).
+
+-define(gc_set_tty_trace(GC, Bool),
+ GC#gconf{flags = yaws:flag(GC#gconf.flags,?GC_TTY_TRACE, Bool)}).
+-define(gc_set_debug(GC, Bool),
+ GC#gconf{flags = yaws:flag(GC#gconf.flags, ?GC_DEBUG, Bool)}).
+-define(gc_set_auth_log(GC, Bool),
+ GC#gconf{flags = yaws:flag(GC#gconf.flags, ?GC_AUTH_LOG, Bool)}).
+-define(gc_set_copy_errlog(GC, Bool),
+ GC#gconf{flags = yaws:flag(GC#gconf.flags, ?GC_COPY_ERRLOG, Bool)}).
+
+
+
%% global conf
--record(gconf,{file,
- yaws_dir,
- tty_trace = false,
+-record(gconf,{yaws_dir,
trace,
- debug,
+ flags = ?GC_DEF,
logdir,
ebin_dir = [],
runmods = [],
@@ -24,7 +52,6 @@
large_file_chunk_size = 10240,
cache_refresh_secs = 30, % seconds (auto zero when debug)
default_type = "text/html",
- auth_log = true, %% log 401's and also good auths
timeout = 30000,
include_dir = [],
yaws, %% server string
@@ -47,22 +74,52 @@
cachetimeout}).
+%% flags for sconfs
+-define(SC_ACCESS_LOG, 1).
+-define(SC_ADD_PORT, 2).
+-define(SC_TILDE_EXPAND, 8).
+-define(SC_DIR_LISTINGS, 16).
+-define(SC_DEFLATE, 32).
+
+
+-define(SC_DEF, ?SC_ACCESS_LOG bor ?SC_ADD_PORT).
+
+-define(sc_has_access_log(SC),
+ ((SC#sconf.flags band ?SC_ACCESS_LOG) /= 0)).
+-define(sc_has_add_port(SC),
+ ((SC#sconf.flags band ?SC_ADD_PORT) /= 0)).
+-define(sc_has_tilde_expand(SC),
+ ((SC#sconf.flags band ?SC_TILDE_EXPAND) /= 0)).
+-define(sc_has_dir_listings(SC),
+ ((SC#sconf.flags band ?SC_DIR_LISTINGS) /= 0)).
+-define(sc_has_deflate(SC),
+ ((SC#sconf.flags band ?SC_DEFLATE) /= 0)).
+
+-define(sc_set_access_log(SC, Bool),
+ SC#sconf{flags = yaws:flag(SC#sconf.flags, ?SC_ACCESS_LOG, Bool)}).
+-define(sc_set_add_port(SC, Bool),
+ SC#sconf{flags = yaws:flag(SC#sconf.flags, ?SC_ADD_PORT, Bool)}).
+-define(sc_set_ssl(SC, Bool),
+ SC#sconf{flags = yaws:flag(SC#sconf.flags , ?SC_SSL, Bool)}).
+-define(sc_set_tilde_expand(SC, Bool),
+ SC#sconf{flags = yaws:flag(SC#sconf.flags, ?SC_TILDE_EXPAND, Bool)}).
+-define(sc_set_dir_listings(SC, Bool),
+ SC#sconf{flags = yaws:flag(SC#sconf.flags, ?SC_DIR_LISTINGS, Bool)}).
+-define(sc_set_deflate(SC, Bool),
+ SC#sconf{flags = yaws:flag(SC#sconf.flags, ?SC_DEFLATE, Bool)}).
-%% a list of lists of #sconfs
-%% one list of #sconf's per listen ip
%% server conf
-record(sconf,
{port = 8000, %% which port is this server listening to
+ flags = ?SC_DEF,
rhost, %% forced redirect host (+ optional port)
rmethod, %% forced redirect method
docroot, %% path to the docs
- access_log = true, %% log access
listen = {127,0,0,1}, %% bind to this IP, {0,0,0,0} is possible
servername = "localhost", %% servername is what Host: header is
- add_port = true, %% add port after reading config
ets, %% local store for this server
ssl,
authdirs = [],
@@ -71,9 +128,6 @@
errormod_404 = yaws_404, %% the default 404 error module
errormod_crash = yaws_404, %% use the same module for crashes
arg_rewrite_mod = yaws,
- tilde_expand = false, %% allow public_html user dirs
- dir_listings = false, %% allow dir listings
- deflate = false, %% support deflate encoding (needs zlib)
opaque = [], %% useful in embedded mode
start_mod, %% user provided module to be started
allowed_scripts = [yaws],
View
9 man/yaws.conf.5
@@ -97,6 +97,15 @@ Enable or disable the auth log. Default is true.
.TP
+\fB copy_error_log = true | false\fR
+Enable or disable copying of the error log. When we run in
+embedded mode, that may very well be some other systems process
+that is responsible for writing the errorlog to a file whereas
+when we run in normal standalone mode, we typicall ywant the
+erlang errorlog written to a report.log file.
+Default value is true.
+
+.TP
\fB username = Username \fR
When running a Yaws server in production, it may feel safe
to run yaws as a different user than root. Set this value to a
View
3 src/Makefile
@@ -29,7 +29,8 @@ MODULES=yaws \
yaws_session_server \
yaws_404 \
yaws_revproxy \
- yaws_html
+ yaws_html \
+ yaws_log_file_h
View
7 src/yaws.erl
@@ -1592,7 +1592,7 @@ gen_tcp_send(S, Data, SC, GC) ->
_SSL ->
ssl:send(S, Data)
end,
- case GC#gconf.debug of
+ case ?gc_has_debug(GC) of
false ->
case Res of
ok ->
@@ -1853,6 +1853,11 @@ uid_change_files(GC, Dir, Files) ->
+flag(CurFlag, Bit, true) ->
+ CurFlag bor Bit;
+flag(CurFlag, Bit, false) ->
+ CurFlag band (bnot Bit).
+
%% misc debug funcs .... use from cli only
View
2 src/yaws_api.erl
@@ -909,7 +909,7 @@ set_trace(Val) ->
set_access_log(Bool) ->
{ok, GC, Groups} = getconf(),
Groups2 = lmap(fun(SC) ->
- SC#sconf{access_log = Bool}
+ ?sc_set_access_log(SC, Bool)
end, Groups),
setconf(GC, Groups2).
View
88 src/yaws_config.erl
@@ -53,23 +53,19 @@ load({file, File}, Trace, TraceOutput, Debug) ->
case file:open(File, [read]) of
{ok, FD} ->
GC = make_default_gconf(Debug),
- R = (catch fload(FD, globals, GC#gconf{file = File,
- trace = Trace,
- tty_trace =
- if
- TraceOutput==undefined->
- false;
- true ->
- true
- end,
- debug = Debug
- },
- undefined,
+ GC2 = if TraceOutput == undefined ->
+ GC;
+ true ->
+ ?gc_set_tty_trace(GC,true)
+ end,
+ GC3 = ?gc_set_debug(GC2, Debug),
+ GC4 = GC3#gconf{trace = Trace},
+ R = (catch fload(FD, globals, GC4, undefined,
[], 1, io:get_line(FD, ''))),
?Debug("FLOAD: ~p", [R]),
case R of
- {ok, GC2, Cs} ->
- validate_cs(GC2, Cs);
+ {ok, GC5, Cs} ->
+ validate_cs(GC5, Cs);
Err ->
Err
end;
@@ -102,16 +98,13 @@ validate_groups([H|T]) ->
end.
validate_group(List) ->
-
%% first, max one ssl per group
- ?Debug("List = ~p~n", [List]),
-
- case lists:filter(fun(C) ->
- C#sconf.ssl /= undefined
+ case lists:filter(fun(SC) ->
+ SC#sconf.ssl /= undefined
end, List) of
L when length(L) > 1 ->
throw({error, ?F("Max one ssl server per IP: ~p",
- [(hd(L))#sconf.servername])});
+ [(hd(L))#sconf.servername])});
_ ->
ok
end,
@@ -134,33 +127,33 @@ arrange([C1|Tail], {in, C0}, A, B) ->
end.
-set_server(C) ->
- case {C#sconf.ssl, C#sconf.port, C#sconf.add_port} of
+set_server(SC) ->
+ case {SC#sconf.ssl, SC#sconf.port, ?sc_has_add_port(SC)} of
{undefined, 80, _} ->
- C;
+ SC;
{undefined, Port, true} ->
- add_port(C, Port);
+ add_port(SC, Port);
{_SSL, 443, _} ->
- C;
+ SC;
{_SSL, Port, true} ->
- add_port(C, Port);
+ add_port(SC, Port);
{_,_,_} ->
- C
+ SC
end.
-add_port(C, Port) ->
- case string:tokens(C#sconf.servername, ":") of
+add_port(SC, Port) ->
+ case string:tokens(SC#sconf.servername, ":") of
[Srv, Prt] ->
case (catch list_to_integer(Prt)) of
{'EXIT', _} ->
- C#sconf{servername =
- Srv ++ [$:|integer_to_list(Port)]};
+ SC#sconf{servername =
+ Srv ++ [$:|integer_to_list(Port)]};
_Int ->
- C
+ SC
end;
[Srv] ->
- C#sconf{servername = Srv ++ [$:|integer_to_list(Port)]}
+ SC#sconf{servername = Srv ++ [$:|integer_to_list(Port)]}
end.
@@ -176,8 +169,11 @@ make_default_gconf(Debug) ->
true ->
30
end,
- debug = Debug,
- trace = false,
+ flags = if Debug ->
+ ?GC_DEBUG bor ?GC_AUTH_LOG bor ?GC_COPY_ERRLOG;
+ true ->
+ ?GC_AUTH_LOG bor ?GC_COPY_ERRLOG
+ end,
uid = element(2, yaws:getuid()),
yaws = "Yaws " ++ yaws_vsn:version()}.
@@ -266,7 +262,6 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) ->
{error, ?F("Expect directory at line ~w", [Lno])}
end;
-
%% keep this bugger for backward compat for a while
["keepalive_timeout", '=', Val] ->
case (catch list_to_integer(Val)) of
@@ -333,10 +328,19 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) ->
C, Cs, Lno+1, Next)
end;
+ ["copy_error_log", '=', Bool] ->
+ case is_bool(Bool) of
+ {true, Val} ->
+ fload(FD, globals, ?gc_set_copy_errlog(GC, Val),
+ C, Cs, Lno+1, Next);
+ false ->
+ {error, ?F("Expect true|false at line ~w", [Lno])}
+ end;
+
["auth_log", '=', Bool] ->
case is_bool(Bool) of
{true, Val} ->
- fload(FD, globals, GC#gconf{auth_log = Bool},
+ fload(FD, globals, ?gc_set_auth_log(GC, Val),
C, Cs, Lno+1, Next);
false ->
{error, ?F("Expect true|false at line ~w", [Lno])}
@@ -361,23 +365,23 @@ fload(FD, server, GC, C, Cs, Lno, Chars) ->
["access_log", '=', Bool] ->
case is_bool(Bool) of
{true, Val} ->
- C2 = C#sconf{access_log = Val},
+ C2 = ?sc_set_access_log(C, Val),
fload(FD, server, GC, C2, Cs, Lno+1, Next);
false ->
{error, ?F("Expect true|false at line ~w", [Lno])}
end;
["dir_listings", '=', Bool] ->
case is_bool(Bool) of
{true, Val} ->
- C2 = C#sconf{dir_listings = Val},
+ C2 = ?sc_set_dir_listings(C, Val),
fload(FD, server, GC, C2, Cs, Lno+1, Next);
false ->
{error, ?F("Expect true|false at line ~w", [Lno])}
end;
["deflate", '=', Bool] ->
case is_bool(Bool) of
{true, Val} ->
- C2 = C#sconf{deflate = Val},
+ C2 = ?sc_set_deflate(C, Val),
fload(FD, server, GC, C2, Cs, Lno+1, Next);
false ->
{error, ?F("Expect true|false at line ~w", [Lno])}
@@ -413,7 +417,7 @@ fload(FD, server, GC, C, Cs, Lno, Chars) ->
fload(FD, server, GC, C2, Cs, Lno+1, Next)
end;
["servername", '=', Name] ->
- C2 = C#sconf{servername = Name, add_port=false},
+ C2 = ?sc_set_add_port((C#sconf{servername = Name}),false),
fload(FD, server, GC, C2, Cs, Lno+1, Next);
["docroot", '=', Rootdir] ->
Root = filename:absname(Rootdir),
@@ -467,7 +471,7 @@ fload(FD, server, GC, C, Cs, Lno, Chars) ->
["tilde_expand", '=', Bool] ->
case is_bool(Bool) of
{true, Val} ->
- C2 = C#sconf{tilde_expand = Val},
+ C2 = ?sc_set_tilde_expand(C,Val),
fload(FD, server, GC, C2, Cs, Lno+1, Next);
false ->
{error, ?F("Expect true|false at line ~w", [Lno])}
View
47 src/yaws_debug.erl
@@ -28,10 +28,6 @@ typecheck([], _,_) ->
ok.
-
-
-
-
%% returns {record, RecName, [Field1, Val1} .....]
format_record(Record, Name, Fields) ->
case tuple_to_list(Record) of
@@ -50,9 +46,6 @@ format_record([Val|Vals], [F|Fs]) ->
-
-
-
assert(equal,X,Y,_) when X==Y ->
ok;
assert(neq,X,Y,_) when X/=Y ->
@@ -123,35 +116,20 @@ fail({format, File,Line,Fmt,Args}) ->
end.
+format(GC, F, A) when ?gc_has_debug(GC) ->
+ io:format(F, A);
+format(_,_,_) ->
+ ok.
+derror(GC, F, A) when ?gc_has_debug(GC) ->
+ error_logger:error_msg(F, A);
+derror(_,_,_) ->
+ ok.
-format(GC, F, A) ->
- if
- GC#gconf.debug == true ->
- io:format(F, A);
- true ->
- ok
- end.
-
-
-derror(GC, F, A) ->
- if
- GC#gconf.debug == true ->
- error_logger:error_msg(F, A);
- true ->
- ok
- end.
-
-
-dinfo(GC, F, A) ->
- if
- GC#gconf.debug == true ->
- error_logger:info_msg(F, A);
- true ->
- ok
- end.
-
-
+dinfo(GC, F, A) when ?gc_has_debug(GC) ->
+ error_logger:info_msg(F, A);
+dinfo(_,_,_) ->
+ ok.
mktags() ->
@@ -197,7 +175,6 @@ eprof() ->
eprof:profile(pids()),
io:format("Ok run some traffic \n", []).
-
%% not used
View
41 src/yaws_log.erl
@@ -32,6 +32,7 @@
now,
tracefd,
tty_trace = false,
+ copy_errlog,
auth_log,
alogs = []}).
@@ -111,13 +112,13 @@ handle_call({setdir, GC, Sconfs}, _From, State)
Dir = GC#gconf.logdir,
?Debug("setdir ~s~n", [Dir]),
ElogFile = filename:join([Dir, "report.log"]),
- case error_logger:logfile({open,ElogFile}) of
- ok ->
- ok;
- {error, Reason} ->
- error_logger:format("Failed to open ~s~n", [ElogFile])
- end,
-
+ Copy = if ?gc_has_copy_errlog(GC) ->
+ gen_event:add_handler(error_logger, yaws_log_file_h,
+ ElogFile),
+ true;
+ true ->
+ false
+ end,
SCs = lists:flatten(Sconfs),
L = lists:zf(
fun(SC) ->
@@ -144,7 +145,7 @@ handle_call({setdir, GC, Sconfs}, _From, State)
AuthLogFileName = filename:join([Dir, "auth.log"]),
AuthLog =
- if GC#gconf.auth_log == true ->
+ if ?gc_has_auth_log(GC) ->
case file:open(AuthLogFileName, [write, raw, append]) of
{ok, AFd} ->
#alog{fd = AFd,
@@ -161,6 +162,7 @@ handle_call({setdir, GC, Sconfs}, _From, State)
S2 = State#state{running = true,
dir = Dir,
now = fmtnow(),
+ copy_errlog = Copy,
auth_log = AuthLog,
alogs = L},
@@ -178,6 +180,20 @@ handle_call({setdir, GC, Sconfs}, _From, State)
when State#state.running == true ->
Dir = State#state.dir,
+ ElogFile = filename:join([Dir, "report.log"]),
+ Copy = if ?gc_has_copy_errlog(GC), State#state.copy_errlog == false->
+ gen_event:add_handler(error_logger, yaws_log_file_h,
+ ElogFile),
+ true;
+ ?gc_has_copy_errlog(GC) ->
+ true;
+ State#state.copy_errlog == true ->
+ gen_event:delete_handler(error_logger, yaws_log_file_h,
+ normal),
+ false;
+ true ->
+ false
+ end,
%% close all files
lists:map(
@@ -203,6 +219,7 @@ handle_call({setdir, GC, Sconfs}, _From, State)
S2 = State#state{running = true,
dir = Dir,
now = fmtnow(),
+ copy_errlog = Copy,
alogs = L},
{reply, ok, S2};
@@ -327,12 +344,8 @@ handle_info(minute10, State) ->
E = filename:join([Dir, "report.log"]),
{ok, FI} = file:read_file_info(E),
if
- FI#file_info.size > ?WRAP_LOG_SIZE ->
- error_logger:logfile(close),
- Old = [E, ".old"],
- file:delete(Old),
- file:rename(E, Old),
- error_logger:logfile({open, E});
+ FI#file_info.size > ?WRAP_LOG_SIZE, State#state.copy_errlog == true ->
+ gen_event:call(error_logger, yaws_log_file_h, wrap);
true ->
ok
end,
View
59 src/yaws_log_file_h.erl
@@ -0,0 +1,59 @@
+%%%-------------------------------------------------------------------
+%%% File : yaws_log_file_h.erl
+%%% Author : <klacke@hyber.org>
+%%% Description :
+%%%
+%%% Created : 11 Mar 2004 by <klacke@hyber.org>
+%%%-------------------------------------------------------------------
+
+
+%% Just extending the error_logger_file_h abit,
+%% If they change the internals of that module, this module
+%% breaks, but then again, the otp crew doesn't ever appear to
+%% change anything that might break anything .....
+
+-module(yaws_log_file_h).
+-behaviour(gen_event).
+
+-export([init/1,
+ handle_event/2, handle_call/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+
+
+%% This one is used when we are started directly.
+init(File) ->
+ init(File, []).
+
+init(File, PrevHandler) ->
+ process_flag(trap_exit, true),
+ case file:open(File, [write, append]) of
+ {ok,Fd} ->
+ {ok, {Fd, File, PrevHandler}};
+ Error ->
+ Error
+ end.
+
+handle_call(wrap, {Fd, File, Prev}) ->
+ Old = File ++ ".old",
+ file:delete(Old),
+ file:close(Fd),
+ file:rename(File, Old),
+ {ok, Fd2} = file:open(File, [write,append]),
+ {ok, ok, {Fd2, File, Prev}};
+
+handle_call(X, S) ->
+ error_logger_file_h:handle_call(X,S).
+
+
+handle_event(X, S) ->
+ error_logger_file_h:handle_event(X, S).
+handle_info(X, S) ->
+ error_logger_file_h:handle_info(X, S).
+
+
+terminate(Reason, State) ->
+ error_logger_file_h:terminate(Reason, State).
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
View
8 src/yaws_revproxy.erl
@@ -240,9 +240,15 @@ ploop(From0, To, GC, SC) ->
rewrite_path(R, From#psock.prefix))
end,
Hstr = headers_to_str(H = rewrite_headers(SC, From, H0)),
- yaws:gen_tcp_send(TS, [RStr, "\r\n", Hstr, "\r\n"] ,
+ yaws:gen_tcp_send(TS, [RStr, "\r\n", Hstr] ,
SC,GC),
From2 = sockmode(H, R, From),
+ if
+ From2#psock.mode == expectchunked ->
+ true;
+ true ->
+ yaws:gen_tcp_send(TS,"\r\n",SC,GC)
+ end,
ploop(From2, To, GC,SC);
closed ->
done
View
56 src/yaws_server.erl
@@ -159,12 +159,13 @@ init([]) ->
case yaws_config:load(Conf, Trace, TraceOut, Debug) of
{ok, Gconf, Sconfs} ->
erase(logdir),
- ?Debug("Conf = ~p~n", [?format_record(Gconf, gconf)]),
+ %?Debug("GC = ~p~n", [?format_record(Gconf, gconf)]),
+ %?Debug("SCS: ~p~n", [Sconfs]),
yaws_log:setdir(Gconf, Sconfs),
case Gconf#gconf.trace of
{true, What} ->
yaws_log:open_trace(What),
- yaws_api:set_tty_trace(Gconf#gconf.tty_trace);
+ yaws_api:set_tty_trace(?gc_has_tty_trace(Gconf));
_ ->
ok
end,
@@ -336,10 +337,10 @@ terminate(_Reason, _State) ->
%% specified as an auth directory. These are merged with server conf.
setup_auth(SC) ->
- ?Debug("setup_auth(~p)", [yaws_debug:nobin(SC)]),
+ %?Debug("setup_auth(~p)", [yaws_debug:nobin(SC)]),
?f(lists:map(fun(Auth) ->
add_yaws_auth(Auth#auth.dir, Auth)
-end, SC#sconf.authdirs)).
+ end, SC#sconf.authdirs)).
add_yaws_auth(Dirs, A) ->
lists:map(
@@ -423,7 +424,7 @@ gserv(GC, Group0) ->
ssl = SSLBOOL,
l = Listen},
acceptor(GS),
- gserv(GS, [], 0);
+ gserv_loop(GS, [], 0);
{_,Err} ->
error_logger:format("Yaws: Failed to listen ~s:~w : ~p~n",
[yaws:fmt_ip(SC#sconf.listen),
@@ -458,30 +459,30 @@ setup_dirs(GC) ->
-gserv(GS, Ready, Rnum) ->
+gserv_loop(GS, Ready, Rnum) ->
receive
{From , status} ->
From ! {self(), GS},
- gserv(GS, Ready, Rnum);
+ gserv_loop(GS, Ready, Rnum);
{_From, next} when Ready == [] ->
acceptor(GS),
- gserv(GS, Ready, Rnum);
+ gserv_loop(GS, Ready, Rnum);
{_From, next} ->
[R|RS] = Ready,
R ! {self(), accept},
- gserv(GS, RS, Rnum-1);
+ gserv_loop(GS, RS, Rnum-1);
{From, done_client, Int} ->
GS2 = GS#gs{sessions = GS#gs.sessions + 1,
reqs = GS#gs.reqs + Int},
if
Rnum == 8 ->
From ! {self(), stop},
- gserv(GS2, Ready, Rnum);
+ gserv_loop(GS2, Ready, Rnum);
Rnum < 8 ->
- gserv(GS2, [From | Ready], Rnum+1)
+ gserv_loop(GS2, [From | Ready], Rnum+1)
end;
{'EXIT', _Pid, _} ->
- gserv(GS, Ready, Rnum);
+ gserv_loop(GS, Ready, Rnum);
{From, stop} ->
unlink(From),
{links, Ls} = process_info(self(), links),
@@ -525,7 +526,6 @@ ssl_opts(SC, SSL) ->
{ip, SC#sconf.listen},
{packet, 0},
{active, false} | ssl_opts(SSL)],
- ?Debug("SSL opts ~p~n", [Opts]),
Opts.
@@ -587,7 +587,6 @@ acceptor(GS) ->
acceptor0(GS, Top) ->
?TC([{record, GS, gs}]),
X = do_accept(GS),
- ?Debug("do_accept ret: ~p~n", [X]),
Top ! {self(), next},
case X of
{ok, Client} ->
@@ -607,7 +606,6 @@ acceptor0(GS, Top) ->
end,
Res = (catch aloop(Client, GS, 0)),
- ?Debug("RES = ~p~n", [Res]),
if
GS#gs.ssl == nossl ->
gen_tcp:close(Client);
@@ -652,7 +650,7 @@ aloop(CliSock, GS, Num) ->
?TC([{record, SC, sconf}]),
?Debug("Headers = ~p~n", [?format_record(H, headers)]),
?Debug("Request = ~p~n", [?format_record(Req, http_request)]),
- IP = case SC#sconf.access_log of
+ IP = case ?sc_has_access_log(SC) of
true ->
{ok, {Ip, _Port}} = peername(CliSock, SSL),
Ip;
@@ -668,7 +666,7 @@ aloop(CliSock, GS, Num) ->
end.
-handle_method_result(Res, CliSock, IP, GS, SC, Req, H, Num) ->
+erase_transients() ->
erase(post_parse),
erase(query_parse),
erase(outh),
@@ -679,15 +677,22 @@ handle_method_result(Res, CliSock, IP, GS, SC, Req, H, Num) ->
_ ->
ok
end
- end, get()),
+ end, get()).
+
+
+handle_method_result(Res, CliSock, IP, GS, SC, Req, H, Num) ->
case Res of
continue ->
maybe_access_log(IP, SC, Req, H),
+ erase_transients(),
aloop(CliSock, GS, Num+1);
done ->
maybe_access_log(IP, SC, Req, H),
+ erase_transients(),
{ok, Num+1};
{page, P} ->
+ erase(post_parse),
+ erase(query_parse),
put(outh, #outh{}),
case P of
{Options, Page} ->
@@ -764,7 +769,7 @@ inet_peername(Sock, SC) ->
maybe_auth_log(GC, SC, Item, ARG) ->
- case GC#gconf.auth_log of
+ case ?gc_has_auth_log(GC) of
false ->
ok;
true ->
@@ -794,7 +799,7 @@ maybe_auth_log(GC, SC, Item, ARG) ->
maybe_access_log(Ip, SC, Req, H) ->
?TC([{record, SC, sconf}]),
- case SC#sconf.access_log of
+ case ?sc_has_access_log(SC) of
true ->
Status = case yaws:outh_get_status_code() of
undefined -> "-";
@@ -886,7 +891,6 @@ bad_request(CliSock, GC, SC, Req, Head) ->
%% ret: continue | done
'GET'(CliSock, GC, SC, Req, Head) ->
?TC([{record, GC, gconf}, {record, SC, sconf}]),
- ?Debug("GET ~p", [?format_record(Req, http_request)]),
ok = inet_setopts(SC, CliSock, [{packet, raw}, binary]),
flush(SC, CliSock, Head#headers.content_length),
ARG = make_arg(CliSock, Head, Req, GC, SC, undefined),
@@ -1108,7 +1112,7 @@ handle_ut(CliSock, GC, SC, ARG, UT, N) ->
fun(A)->finish_up_dyn_file(CliSock, GC, SC)
end
);
- directory when SC#sconf.dir_listings == true ->
+ directory when ?sc_has_dir_listings(SC) ->
P = UT#urltype.dir,
yaws:outh_set_dyn_headers(Req, H),
yaws_ls:list_directory(CliSock, UT#urltype.data, P, Req, GC, SC);
@@ -2438,7 +2442,7 @@ cache_file(GC, SC, Path, UT) when
{ok, Bin} = prim_file:read_file(
UT#urltype.fullpath),
Deflated =
- case SC#sconf.deflate
+ case ?sc_has_deflate(SC)
and (UT#urltype.type==regular) of
true ->
case zlib:gzip(Bin) of
@@ -2579,7 +2583,7 @@ ret_app_mod(_SC, Path, Mod, PrePath) ->
%% http://a.b.c/~user URLs
-ret_user_dir(SC, [], "/", Upath) when SC#sconf.tilde_expand == true ->
+ret_user_dir(SC, [], "/", Upath) when ?sc_has_tilde_expand(SC) ->
?Debug("UserPart = ~p~n", [Upath]),
case parse_user_path(SC#sconf.docroot, Upath, []) of
{ok, User, Path} ->
@@ -2643,7 +2647,7 @@ ret_reg_split(SC, Comps, RevFile) ->
{X, Mime} ->
#urltype{type=X,
finfo=FI,
- deflate=deflate_q(SC#sconf.deflate, X, Mime),
+ deflate=deflate_q(?sc_has_deflate(SC), X, Mime),
path = {noflat, [DR, Dir]},
dir = FlatDir,
fullpath = lists:flatten(L),
@@ -2768,7 +2772,7 @@ runmod(_, GC) ->
runmod2(GC, Mods) ->
lists:foreach(fun(M) ->
proc_lib:spawn(?MODULE, load_and_run,
- [M, GC#gconf.debug])
+ [M, ?gc_has_debug(GC)])
end, Mods).
View
21 www/todo.yaws
@@ -12,18 +12,21 @@ out(A) ->
<ul>
<li> respect client side Cache-Control: no-cache
-<li> clusters
-<li> handle the If-..... headers
-<li> handle Range header
+<li> clusters, it would be fairly straightforward
+to build support for webfarms into yaws. Now it works
+ofcource with a normal loadbalancer and mnesia across a set
+of nodes, but we could migrate IPs and stuff as well.
<li> TRACE, PUT, OPTIONS ......
<li> more documentation in the www directory
-<li> more functions in yaws_api push() ....
-<li> lots of examples
+<li> redo the docs completely, docbook ??
+<li> more functions in yaws_api
+<li> lots of examples, mnesia examples.
<li> do something cool, maybe a streaming audio app
-<li> shell access into the daemon .... no bad idea
-<li> HTTP trailer support
-<li> substitution in ssi pages as well as regular pages
-<li> a CGI interface
+<li> shell access into the daemon .... no bad idea .. ?? Maybe using
+distributed erlang to do that.
+<li> HTTP trailer support (why ??)
+<li> webdav, lots of work.
+<li> content negotiation / language support
</ul>

0 comments on commit 7fd4ad4

Please sign in to comment.