Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

""

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@99 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit aef9169fd7636487b512b3b26364b5859d55a31b 1 parent a5e3fa4
@klacke authored
View
6 README
@@ -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
View
8 man/yaws.conf.5
@@ -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
View
1  src/yaws.hrl
@@ -48,7 +48,6 @@
access_log = true,
listen = {127,0,0,1},
servername = "localhost",
- default_server_on_this_ip = true,
ets,
ssl,
authdirs = []
View
59 src/yaws_config.erl
@@ -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};
@@ -101,7 +98,7 @@ 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",
@@ -109,23 +106,11 @@ validate_group(List) ->
_ ->
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) ->
@@ -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(),
@@ -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
View
2  src/yaws_ls.erl
@@ -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),
View
75 src/yaws_server.erl
@@ -269,7 +269,7 @@ terminate(_Reason, _State) ->
%% specified as an auth directory
setup_auth(_SC, _E) ->
- ok.
+ ok. %nyi
do_listen(SC) ->
@@ -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)]),
@@ -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) ->
@@ -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
@@ -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 ->
[];
View
2  vsn.mk
@@ -1 +1 @@
-YAWS_VSN=0.50
+YAWS_VSN=0.51
View
13 www/history.yaws
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.