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@568 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information
Claes Wikstrom committed Dec 18, 2003
1 parent d495c60 commit 612490d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 22 deletions.
15 changes: 15 additions & 0 deletions man/yaws.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ application to syncronize the startup with the yaws server
as well as getting hold of user specific configuration data,
see the explanation for the <opaque> context.



.TP
\fBrevproxy = Prefix Url\fR
Make yaws a reverse proxy. The Prefix is a path inside our own docroot
and the Url argument is an rli pointing to a website we want to "mount"
under the path which is Prefix.

Example: revproxy = /tmp/foo http://yaws.hyber.org

Makes the hyber website appear under /tmp/foo

It is possible to have multiple reverse proxies inside the same server.


.TP
\fB <ssl> .... </ssl> \fR
This begins and ends an SSL configuration for this server.
Expand Down
5 changes: 2 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ MODULES=yaws \
mime_types \
yaws_session_server \
yaws_404 \
yaws_revproxy

# yaws_html \
yaws_revproxy \
yaws_html



Expand Down
61 changes: 45 additions & 16 deletions src/yaws_revproxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
url, %% The url we're proxying to
type, %% client | server
r_req, %% if'we're server, what req method are we processing
r_host, %% and value of Host: for the cli request
state}).%% various depending on mode, ......


Expand All @@ -36,13 +37,16 @@ init(CliSock, GC, SC, ARG, DecPath, QueryPart, {Prefix, URL}) ->
Cli = sockmode(Headers0, ARG#arg.req,
#psock{s = CliSock, prefix = Prefix,
url = URL, type = client}),
Headers = rewrite_headers(Cli, Headers0),
Headers = rewrite_headers(SC, Cli, Headers0),
ReqStr = yaws_api:reformat_request(
rewrite_path(ARG#arg.req, Prefix)),
Hstr = headers_to_str(Headers),
yaws:gen_tcp_send(Ssock, [ReqStr, "\r\n", Hstr, "\r\n"], SC,GC),
Srv = #psock{s = Ssock, prefix = Prefix, url = URL,
Srv = #psock{s = Ssock,
prefix = Prefix,
url = URL,
r_req = (ARG#arg.req)#http_request.method,
r_host = (ARG#arg.headers)#headers.host,
mode = expectheaders, type = server},

%% Now we _must_ spawn a process here, casuse we
Expand Down Expand Up @@ -91,9 +95,9 @@ rewrite_path(Req, Pref) ->
New.


strip_prefix(P,[]) -> P;
strip_prefix("/","/") ->
"/";

strip_prefix(P,"/") ->
P;
strip_prefix([H|T1],[H|T2]) ->
strip_prefix(T1,T2).

Expand Down Expand Up @@ -204,8 +208,9 @@ get_chunk(Fd, N, Asz) ->

ploop(From0, To, GC, SC) ->
From = receive
{r_req, Method} ->
From0#psock{r_req = Method}
{cli2srv, Method, Host} ->
From0#psock{r_req = Method,
r_host = Host}
after 0 ->
From0
end,
Expand All @@ -216,17 +221,19 @@ ploop(From0, To, GC, SC) ->
SSL = nossl,
case yaws:http_get_headers(From#psock.s, GC, SSL) of
{R, H0} ->
?Debug("R = ~p~n",[R]),
RStr =
if
%% FIXME handle bad_request here
record(R, http_response) ->
yaws_api:reformat_response(R);
record(R, http_request) ->
To ! {r_req, R#http_request.method},
To ! {cli2srv, R#http_request.method,
H0#headers.host},
yaws_api:reformat_request(
rewrite_path(R, From#psock.prefix))
end,
Hstr = headers_to_str(H = rewrite_headers(From, H0)),
Hstr = headers_to_str(H = rewrite_headers(SC, From, H0)),
yaws:gen_tcp_send(TS, [RStr, "\r\n", Hstr, "\r\n"] ,
SC,GC),
From2 = sockmode(H, R, From),
Expand All @@ -239,6 +246,8 @@ ploop(From0, To, GC, SC) ->
N = get_chunk_num(From#psock.s),
if N == 0 ->
ok=eat_crnl(From#psock.s),
yaws:gen_tcp_send(TS,["\r\n0\r\n\r\n"], SC,GC),
?Debug("SEND final 0 ",[]),
ploop(From#psock{mode = expectheaders,
state = undefined},To, GC, SC);
true ->
Expand Down Expand Up @@ -289,7 +298,7 @@ ploop(From0, To, GC, SC) ->
%% On the way from the client to the server, we need
%% rewrite the Host header

rewrite_headers(PS, H) when PS#psock.type == client ->
rewrite_headers(SC, PS, H) when PS#psock.type == client ->
Host =
if H#headers.host == undefined ->
undefined;
Expand All @@ -313,35 +322,55 @@ rewrite_headers(PS, H) when PS#psock.type == client ->
%% need to rewrite the Location header, and the
%% Set-Cookie header

rewrite_headers(PS, H) when PS#psock.type == server ->
rewrite_headers(SC, PS, H) when PS#psock.type == server ->
?Debug("Location header to rewrite: ~p~n", [H#headers.location]),
Loc = if
H#headers.location == undefined ->
undefined;
true ->
?Debug("parse_url(~p)~n", [H#headers.location]),
LocUrl = yaws_api:parse_url(H#headers.location),
LocUrl = (catch yaws_api:parse_url(H#headers.location)),
ProxyUrl = PS#psock.url,
if
LocUrl#url.host == ProxyUrl#url.host,
LocUrl#url.port == ProxyUrl#url.port,
LocUrl#url.scheme == ProxyUrl#url.scheme ->
P = PS#psock.prefix ++ LocUrl#url.path,
?Debug("New Loc = ~p~n", [P]),
yaws_api:reformat_url(LocUrl#url{path=P});
rewrite_loc_url(SC, LocUrl, PS);

element(1, LocUrl) == 'EXIT' ->
rewrite_loc_rel(SC, PS, H#headers.location);
true ->
?Debug("Not rew ~p~n~p~n",
[LocUrl, ProxyUrl]),
H#headers.location
end
end,
?Debug("New loc=~p~n", [Loc]),

%% WE should try to handle broken relative Location: paths
%% And we also should do cookies here ... FIXME

H#headers{location = Loc}.


%% Rewrite a properly formatted location redir
rewrite_loc_url(SC, LocUrl, PS) ->
Scheme = yaws_server:redirect_scheme(SC),
RedirHost = yaws_server:redirect_host(SC, PS#psock.r_host),
RealPath = LocUrl#url.path,
[Scheme, RedirHost, PS#psock.prefix ++ LocUrl#url.path].


%% This is the case for broken webservers that reply with
%% Location: /path
%% or even worse, Location: path

rewrite_loc_rel(SC, PS, Loc) ->
Scheme = yaws_server:redirect_scheme(SC),
RedirHost = yaws_server:redirect_host(SC, PS#psock.r_host),
[Scheme, RedirHost,Loc].




eat_crnl(Fd) ->
inet:setopts(Fd, [{packet, line}]),
Expand Down
2 changes: 1 addition & 1 deletion src/yaws_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ handle_extension_method(_Method, CliSock, GC, SC, Req, Head) ->
handle_request(CliSock, GC, SC, ARG, N) ->
?TC([{record, GC, gconf}, {record, SC, sconf}]),
Req = ARG#arg.req,
io:format("SrvReq=~p~n",[Req]),
?Debug("SrvReq=~p~n",[Req]),
case Req#http_request.path of
{abs_path, RawPath} ->
case (catch yaws_api:url_decode_q_split(RawPath)) of
Expand Down
4 changes: 3 additions & 1 deletion www/EXHEAD
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<tr border="2">
<td> <A HREF="/index.yaws">Top Page</a> </td>
<td> <A HREF="/simple.yaws">Simple</a></td>
<td> <A HREF="/dynamic.yaws">Dynamic content</a></td>
<td> <A HREF="/query.yaws">Query part of url</a> </td>
<td> <A HREF="/form.yaws">Forms</a> </td>
<td> <A HREF="/redirect.yaws">Redirect</a> </td>
<td> <A HREF="/ssi.yaws">Server side include</a> </td>
<td> <A HREF="/embed.yaws">Embedding Yaws</a> </td>

</tr>
<tr border="2">
Expand All @@ -19,6 +19,8 @@
<td> <A HREF="/pcookie.yaws">Persistant Cookies</a> </td>
<td> <A HREF="/session.yaws">Cookie sessions</a> </td>
<td> <A HREF="/shopingcart/index.yaws">Tiny shoping cart</a> </td>
<td> <A HREF="/embed.yaws">Embedding Yaws</a> </td>

</tr>
</table>
<hr>
Expand Down
2 changes: 1 addition & 1 deletion www/index.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ out(A) ->

{p,[], ["The www page for Yaws is ",
{a ,[{href,"http://yaws.hyber.org"}], "yaws.hyber.org"},
"The documentation, examples as well as releases can be "
" The documentation, examples as well as releases can be "
"found there, and of cource, ",
{a ,[{href,"http://yaws.hyber.org"}],"yaws.hyber.org"},
" is itself powered by Yaws"]},
Expand Down
15 changes: 15 additions & 0 deletions www/news
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
Dec 18, 2003 Version 1.40 released
This is a major feature release.
Experimental reverse proxy implementation <klacke@hyber.org>
New feature, server side includes inside ehtml structure with variable expansion <klacke@hyber.org>
yaws_html an HTML parser which produce ehtml output. The ideal tool for all of us who flunked artclass in highscool. Makes it very easy to rip page design from other sites (designed by those who went to the art classes) <jb@bevemyr.com>)
A HTTP cookie parser <jb@bevemyr.com)
A full blown easy to configure web mail application. It keeps no state, thus only requires the IP of the pop3/smtp servers to run. <jb@bevemyr.com)
Some problems with ehtml expansion fixed <jb@bevemyr.com)
Major overhaul of the docs, written description of embedded mode yaws <klacke@hyber.org)
Don't fail fatal when we can't bind() <klacke@hyber.org)
Time zone fix <magnus@nortelnetworks.com>
Mime type fix <Rob Schmersel>
tilde expansion and dir listings turned off by default, not on <jb@bevemyr.com>
Many small fixes to the wiki by <jb@bevemyr.com> and <mikl>

Oct 4, 2003. Version 1.31 released
This is minor bugfix release
Even more redir bugs fixed by Johan Bevemyr
Expand Down

0 comments on commit 612490d

Please sign in to comment.