Skip to content

Commit

Permalink
""
Browse files Browse the repository at this point in the history
git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@99 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information
Claes Wikstrom committed Jun 18, 2002
1 parent a5e3fa4 commit aef9169
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 57 deletions.
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ To build and install
4. Start as bin/yaws -i
This will create a webserver at http://127.0.0.1:8000

5. make install
6. Start as /usr/local/bin/yaws -i
5. as root make install
6. as root Start as /usr/local/bin/yaws -i
(this starts an interactive system)

7. This will create a webserver at http://127.0.0.1
8. Edit /etc/yaws.conf
8. as root Edit /etc/yaws.conf
9. Create content in /var/yaws

8 changes: 3 additions & 5 deletions man/yaws.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ This makes the server listen on Port
.TP
\fB listen = IpAddress\fR
This makes the server listen on IpAddress
When virthosting several servers on the same ip/port address, if the
browser doesn't sebd a Host: field, yaws will pick the \fIfirst\fR
server specified in the config file
.TP
\fB docroot = Directory\fR
This makes the server serve all its content from Directory
.TP
\fB default_server_on_this_ip = true | false\fR
When virthosting several servers on the same ip address, this option
is mandatory. When client requests arrive at the ip address whithout the
HTTP Host: header present, we must know which server is the default.
.TP
\fB ssl = true \fR
This enables ssl for this server
.TP
Expand Down
1 change: 0 additions & 1 deletion src/yaws.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
access_log = true,
listen = {127,0,0,1},
servername = "localhost",
default_server_on_this_ip = true,
ets,
ssl,
authdirs = []
Expand Down
59 changes: 32 additions & 27 deletions src/yaws_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@ exists(F) ->


validate_cs(GC, Cs) ->
?Debug("Cs ~p~n", [Cs]),
L = lists:map(fun(SC) -> {{SC#sconf.listen, SC#sconf.port}, SC} end,Cs),
L2 = lists:map(fun(X) -> element(2, X) end, lists:sort(L)),
?Debug("L2 ~p~n", [L2]),
L3 = arrange(L2, start, [], []),
?Debug("Arrange: ~p", [L3]),
case validate_groups(L3) of
ok ->
{ok, GC, L3};
Expand All @@ -101,31 +98,19 @@ validate_group(List) ->
io:format("List = ~p~n", [List]),

case lists:filter(fun(C) ->
C#sconf.ssl == on
C#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])});
_ ->
ok
end,

%% if we have multiple servers on the same IP, one must be default
case lists:filter(fun(C) ->
C#sconf.default_server_on_this_ip
end, List) of
L2 when length(List) /= 1, length(L2) > 1 ->
throw({error, ?F("Need exactly ONE server which is "
"default_server_on_this_ip in server group "
"containing ~p", [(hd(List))#sconf.servername])});
_ ->
ok
end,
ok.


arrange([C|Tail], start, [], B) ->
arrange(Tail, {in, C}, [C], B);
arrange(Tail, {in, C}, [set_server(C)], B);
arrange([], _, [], B) ->
B;
arrange([], _, A, B) ->
Expand All @@ -134,12 +119,39 @@ arrange([C1|Tail], {in, C0}, A, B) ->
if
C1#sconf.listen == C0#sconf.listen,
C1#sconf.port == C0#sconf.port ->
arrange(Tail, {in, C0}, [C1|A], B);
arrange(Tail, {in, C0}, [set_server(C1)|A], B);
true ->
arrange(Tail, {in, C1}, [C1], [A|B])
arrange(Tail, {in, C1}, [set_server(C1)], [A|B])
end.


set_server(C) ->
case {C#sconf.ssl, C#sconf.port} of
{undefined, 80} ->
C;
{undefined, Port} ->
add_port(C, Port);
{_SSL, 443} ->
C;
{_SSL, Port} ->
add_port(C, Port)
end.


add_port(C, Port) ->
case string:tokens(C#sconf.servername, ":") of
[Srv, Prt] ->
case (catch list_to_integer(Prt)) of
{'EXIT', _} ->
C#sconf{servername =
Srv ++ [$:|integer_to_list(Port)]};
_Int ->
C
end;
[Srv] ->
C#sconf{servername = Srv ++ [$:|integer_to_list(Port)]}
end.


make_default_gconf() ->
Y = yaws_dir(),
Expand Down Expand Up @@ -323,14 +335,7 @@ fload(FD, server, GC, C, Cs, Lno, Chars) ->
end;

["default_server_on_this_ip", '=', Bool] ->
case is_bool(Bool) of
{true, Val} ->
C2 = C#sconf{default_server_on_this_ip = Val},
fload(FD, server, GC, C2, Cs, Lno, Next);
false ->
{error, ?F("Expect true|false at line ~w", [Lno])}
end;

fload(FD, server, GC, C, Cs, Lno, Next);

%% A bunch of ssl options

Expand Down
2 changes: 1 addition & 1 deletion src/yaws_ls.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ file_entry({ok, FI}, DirName, Name) ->
Entry = ?F("<img SRC=~p ALT=~p> <a HREF=~p>~s</a> ~s~s ~s~n",
["/icons/" ++ Gif,
Alt,
DirName ++ [$/|Name],
Name,
Trim,
lists:duplicate(20 - length(Trim), $\s),
datestr(FI),
Expand Down
75 changes: 57 additions & 18 deletions src/yaws_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ terminate(_Reason, _State) ->
%% specified as an auth directory

setup_auth(_SC, _E) ->
ok.
ok. %nyi


do_listen(SC) ->
Expand Down Expand Up @@ -481,7 +481,7 @@ aloop(CliSock, GS, Num) when GS#gs.ssl == nossl ->
done ->
{ok, Num};
{Req, H} ->
Sconf = pick_sconf(H, GS#gs.group),
Sconf = pick_sconf(GS#gs.gconf, H, GS#gs.group),
?Debug("Sconf: ~p", [?format_record(Sconf, sconf)]),
?TC([{record, Sconf, sconf}]),
?Debug("Headers = ~p~n", [?format_record(H, headers)]),
Expand Down Expand Up @@ -519,29 +519,23 @@ aloop(CliSock, GS, Num) when GS#gs.ssl == ssl ->



pick_sconf(H, Group) ->
pick_sconf(GS, H, Group) ->
case H#headers.host of
undefined ->
pick_default(Group);
hd(Group);
Host ->
pick_host(Host, Group, Group)
pick_host(GS, Host, Group, Group)
end.

pick_default([]) ->
yaws_log:errlog("No default host found in server group ",[]),
exit(normal);
pick_default([H|_T]) when H#sconf.default_server_on_this_ip == true ->
H;
pick_default([_|T]) ->
pick_default(T).


pick_host(Host, [H|_T], _Group) when H#sconf.servername == Host ->
pick_host(_GC, Host, [H|_T], _Group) when H#sconf.servername == Host ->
H;
pick_host(Host, [_|T], Group) ->
pick_host(Host, T, Group);
pick_host(_Host, [], Group) ->
pick_default(Group).
pick_host(GC, Host, [_|T], Group) ->
pick_host(GC, Host, T, Group);
pick_host(GC, Host, [], Group) ->
yaws_debug:derror(GC, "Got Host: header ~p which didn't match any host "
"filed in config, picking the first one ",[Host]),
hd(Group).


inet_peername(Sock, SC) ->
Expand Down Expand Up @@ -1170,6 +1164,43 @@ handle_out_reply(Reply, DCC, LineNo, YawsFile) ->



check_headers(L) ->
Hs = string:tokens(lists:flatten(L), "\r\n"),
io:format("XX ~p~n", [Hs]),
lists:foreach(
fun(H) ->
case lists:reverse(H) of
[_,_,$\r|_] ->
yaws_log:errlog("Bad header ~p, it contains"
" '\\r' or '\\n' at end ",
[lists:flatten(H)]),
exit(normal);
[_,_,$\n|_] ->
yaws_log:errlog("Bad header ~p, it contains"
" '\\r' or '\\n' at end ",
[lists:flatten(H)]),
exit(normal);
_ ->
ok
end
end, Hs).


check_headers([$\r, $\n |Tail], Last) when Tail /= [] ->
case lists:member(hd(Tail), [$\r, $\n]) of
true ->
yaws_log:errlog("Bad header ~p, it contains"
" '\\r' or '\\n' at end ", [lists:reverse(Last)]),
exit(normal);
_ ->
check_headers(Tail, [])
end;

check_headers([H|T], Last) ->
check_headers(T, [H|Last]);
check_headers([], _) ->
ok.


deliver_accumulated(DCC, Sock, GC, SC) ->
Code = case get(status_code) of
Expand All @@ -1179,6 +1210,14 @@ deliver_accumulated(DCC, Sock, GC, SC) ->
StatusLine = ["HTTP/1.1 ", integer_to_list(Code), " ",
yaws_api:code_to_phrase(Code), crnl()],
Headers = erase(acc_headers),

if
GC#gconf.debug == true ->
check_headers(lists:flatten(Headers), []);
true ->
ok
end,

Cont = case erase(acc_content) of
undefined ->
[];
Expand Down
2 changes: 1 addition & 1 deletion vsn.mk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
YAWS_VSN=0.50
YAWS_VSN=0.51
13 changes: 12 additions & 1 deletion www/history.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ out(A) ->
<tr><td> <p>Jun 18, return status 303 when browser asks for a dir URL
without a trailing / in the http request. I've always wondered why apache
does this. Now I know ... otherwise the relative URLs in /dir/index.html
will be wrong when the browser tries to get them. </td></tr>
will be wrong when the browser tries to get them. Utilize this feature
when listing dirs now, generate relative urls instead of absolute.


<p>Removed the default_server_on_this_ip option, the first virthosted server
in the config will be default if no Host: header is present
<p> Made the Host: check to check for Host: host:port instead of just host
when a server is run on a non-standar port. The browsers seem to
set the Host: filed to host:port then Dunno if this is HTTP compliant ...


</td></tr>


<tr><td> <p>Jun 17, fixed yet another chunked encoding bug </td></tr>
Expand Down

0 comments on commit aef9169

Please sign in to comment.