Skip to content

Commit

Permalink
added arg_rewrite_mod
Browse files Browse the repository at this point in the history
git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@251 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information
Claes Wikstrom committed Nov 6, 2002
1 parent 8609cb9 commit c3386b0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/yaws.hrl
Expand Up @@ -64,6 +64,7 @@
appmods = [], %% list of modules for this app
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 = true, %% allow public_html user dirs
opaque %% useful in embedded mode
}).
Expand Down
49 changes: 46 additions & 3 deletions man/yaws.conf.5
Expand Up @@ -136,6 +136,45 @@ The Arg argument will have the missing path part supplied in its
appmoddata field.


.TP
\fBerrormod_404 = Module\fR
It is possible to set a special module that handles
404 Not Found messages.

The function \fIModule:out404(Arg, GC, SC)\fR will
be invoked. The arguments are

Arg is a #arg{} record

GC is a #gconf{} record (defined in yaws.hrl)

SC is a #sconf{} record (defined in yaws.hrl)

The function can and must do the same things that
a normal \fIout/1\fR does.


.TP
\fBerrormod_crash = Module\fR
It is possible to set a special module that handles
the HTML generation of server crash messages. The default
is to display the entire formated crash message in the
browser. This is good for debugging but not in production.

The function \fIModule:crashmsg(Arg, SC, Str)\fR will be
called. The \fIStr\fR is the real crash message formated as a string.


.TP
\fBarg_rewrite_mod = Module\fR
It is possible to install a module that rewrites all the
Arg #arg{} records at an early stage in the yaws server.
This can be used to do various things such as checking a cookie,
rewriting paths etc.





.TP
\fB <ssl> .... </ssl> \fR
Expand Down Expand Up @@ -163,7 +202,11 @@ String If the private key is encrypted on disc, this password is the 3des key to
\fB ciphers = String\fR
* This string specifies the ssl cipher string. The syntax of the ssl cipher string is a little horrible sublanguage of its own. It is documented in the ssl man page for "ciphers".

.TP
\fB </ssl> \fR
Ends an SSL definition


.TP
\fB<auth> ... </auth>\fR
Defines an auth structure. The following items are allowed
Expand All @@ -187,7 +230,9 @@ the password Password in the popup dialogue presented by the browser.
We can obviouslu have several of these value inside a single <auth> </auth>
pair.


.TP
\fB</auth>\fR
Ends an auth definition


.SH EXAMPLES
Expand All @@ -211,7 +256,6 @@ And this example shows a similar setup but two webservers on the same ip address
logdir = /var/log/yaws
<server www.mydomain.org>
port = 80
default_server_on_this_ip = true
listen = 192.168.128.31
docroot = /var/yaws/www
</server>
Expand Down Expand Up @@ -264,7 +308,6 @@ max_num_cached_bytes = 6000000

<server www.mydomain.org>
port = 80
default_server_on_this_ip = true
listen = 192.168.128.31
docroot = /var/yaws/www
</server>
Expand Down
3 changes: 3 additions & 0 deletions src/yaws.erl
Expand Up @@ -631,3 +631,6 @@ printversion() ->
io:format("Yaws ~s~n", [yaws_vsn:version()]),
init:stop().

%% our default arg rewriteer does's of cource nothing
arg_rewrite(A) ->
A.
4 changes: 4 additions & 0 deletions src/yaws_config.erl
Expand Up @@ -418,6 +418,10 @@ fload(FD, server, GC, C, Cs, Lno, Chars) ->
C2 = C#sconf{errormod_crash = list_to_atom(Module)},
fload(FD, server, GC, C2, Cs, Lno+1, Next);

["arg_rewrite_mod", '=', Module] ->
C2 = C#sconf{arg_rewrite_mod = list_to_atom(Module)},
fload(FD, server, GC, C2, Cs, Lno+1, Next);

["tilde_expand", '=', Bool] ->
case is_bool(Bool) of
{true, Val} ->
Expand Down
6 changes: 4 additions & 2 deletions src/yaws_server.erl
Expand Up @@ -839,7 +839,8 @@ inet_setopts(_,_,_) ->
ok = inet_setopts(SC, CliSock, [{packet, raw}, binary]),
flush(SC, CliSock, Head#headers.content_length),
ARG = make_arg(CliSock, Head, Req, GC, SC),
handle_request(CliSock, GC, SC, Req, Head, ARG, 0).
ARG2 = apply(SC#sconf.arg_rewrite_mod, arg_rewrite, [ARG]),
handle_request(CliSock, GC, SC, Req, Head, ARG2, 0).


'POST'(CliSock, GC, SC, Req, Head) ->
Expand Down Expand Up @@ -883,7 +884,8 @@ inet_setopts(_,_,_) ->
?Debug("POST data = ~s~n", [binary_to_list(un_partial(Bin))]),
ARG = make_arg(CliSock, Head, Req, GC, SC),
ARG2 = ARG#arg{clidata = Bin},
handle_request(CliSock, GC, SC, Req, Head, ARG2, size(un_partial(Bin))).
ARG3 = apply(SC#sconf.arg_rewrite_mod, arg_rewrite, [ARG2]),
handle_request(CliSock, GC, SC, Req, Head, ARG3, size(un_partial(Bin))).


is_ssl(undefined) ->
Expand Down

0 comments on commit c3386b0

Please sign in to comment.