Permalink
Browse files

""

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@98 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent 4de3563 commit a5e3fa4a0c2194d75bc75c5fb3e60680ca04eba2 @klacke committed Jun 18, 2002
Showing with 169 additions and 67 deletions.
  1. +43 −5 src/yaws_server.erl
  2. +5 −3 www/api.yaws
  3. +9 −2 www/configuration.yaws
  4. +23 −7 www/dynamic.yaws
  5. +31 −24 www/history.yaws
  6. +18 −6 www/index.yaws
  7. +1 −0 www/motivation.yaws
  8. +17 −10 www/setcookie.yaws
  9. +9 −6 www/setpcookie.yaws
  10. +1 −1 www/shopingcart/cart.yaws
  11. +11 −2 www/simple.yaws
  12. +1 −1 www/testdir/index.html
View
@@ -822,7 +822,9 @@ handle_ut(CliSock, GC, SC, Req, H, ARG, UT) ->
do_yaws(CliSock, GC, SC, Req, H,
ARG#arg{querydata = UT#urltype.q}, UT);
dotdot ->
- deliver_403(CliSock, Req, GC, SC)
+ deliver_403(CliSock, Req, GC, SC);
+ redir_dir ->
+ deliver_303(CliSock, Req, GC, SC)
end.
@@ -870,6 +872,36 @@ is_authenticated(_SC, UT, _Req, H) ->
end.
+% we must deliver a 303 if the browser asks for a dir
+% without a trailing / in the HTTP req
+% otherwise the relative urls in /dir/index.html will be broken.
+
+deliver_303(CliSock, Req, GC, SC) ->
+ Scheme = case SC#sconf.ssl of
+ undefined ->
+ "http://";
+ _SSl ->
+ "https://"
+ end,
+ PortPart = case {SC#sconf.ssl, SC#sconf.port} of
+ {undefined, 80} ->
+ "";
+ {undefined, Port} ->
+ io_lib:format(":~w",[Port]);
+ {_SSL, 443} ->
+ "";
+ {_SSL, Port} ->
+ io_lib:format(":~w",[Port])
+ end,
+
+ set_status_code(303),
+ make_connection_close(true),
+ make_content_length(0),
+ accumulate_header(["Location: ", Scheme, SC#sconf.servername,
+ PortPart, get_path(Req#http_request.path), "/"]),
+
+ deliver_accumulated(#dcc{}, CliSock, GC, SC),
+ done.
deliver_401(CliSock, _Req, GC, Realm, SC) ->
set_status_code(401),
@@ -1160,7 +1192,6 @@ deliver_accumulated(DCC, Sock, GC, SC) ->
crnl()
end,
All = [StatusLine, Headers, CRNL, Cont],
- io:format("ALL: ~p~n", [All]),
gen_tcp_send(Sock, All, SC, GC),
if
GC#gconf.trace == false ->
@@ -1440,8 +1471,10 @@ update_total(E, Path) ->
end.
-cache_file(GC, SC, Path, UT) when UT#urltype.type == regular ;
- UT#urltype.type == yaws ->
+cache_file(GC, SC, Path, UT) when
+ UT#urltype.type == regular ;
+ UT#urltype.type == yaws ->
+
E = SC#sconf.ets,
[{num_files, N}] = ets:lookup(E, num_files),
[{num_bytes, B}] = ets:lookup(E, num_bytes),
@@ -1490,6 +1523,9 @@ do_url_type(Droot, Path) ->
maybe_return_dir(Droot, lists:flatten(Path));
dotdot -> %% generate 403 forbidden
#urltype{type=dotdot};
+ redir_dir ->
+ #urltype{type = redir_dir,
+ dir = [Path, $/]};
OK ->
OK
end.
@@ -1593,8 +1629,10 @@ ret_reg_split(DR, Comps, RevFile, Query) ->
dir = FlatDir,
fullpath = lists:flatten(L),
mime=Mime, q=Query};
- {ok, FI} when FI#file_info.type == directory ->
+ {ok, FI} when FI#file_info.type == directory, hd(RevFile) == $/ ->
maybe_return_dir(DR, lists:flatten(Dir) ++ File);
+ {ok, FI} when FI#file_info.type == directory, hd(RevFile) /= $/ ->
+ redir_dir;
{error, enoent} ->
%% kind of hackish, defer url decode
Dir2 = lists:flatmap(fun(X) -> yaws_api:url_decode(X) end, Dir),
View
@@ -8,6 +8,7 @@ out(A) ->
<H1>Yaws API</H1>
+<p>
Here we describe the API avalable to Yaws applications.
First and foremost, the entire regular erlang API is available, this
include mnesia ans all other erlang applications that are part of the
@@ -59,15 +60,16 @@ document.
<hr>
-<h3> <tt> parse_post_data(Bin, Spec) </tt> </h2>
+<h3> <tt> parse_post_data(Bin) </tt> </h2>
<p>
-When data is POSTed to a yaws page,
+When data is POST ed to a yaws page,
this function can be used to parse the
data in a convenient way. Data which is posted from a form is naturally
arranged as a list of {key,value} pairs.
<p> Similarly, when data is fed to a yaws page in the URL as a query part,
-the query can be parsed by this function.
+the query can be parsed by this function. More info on this at
+<a href="query.yaws">query.yaws</a>
<p>We can see examples of the usage of this function in the files
<a href="form.yaws">form.yaws</a> which feeds the POST data to the file
View
@@ -10,6 +10,7 @@ out(A) ->
<h2>Build and install</h2>
+<p>
Yaws is hosted by the excellent source code site SourceForge <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=45637&type=1" width="88" height="31" border="0" alt="SourceForge.net Logo"></a>.
The Yaws SourceForge www page is <a href="http://sourceforge.net/projects/erlyaws/">http://sourceforge.net/projects/erlyaws</a>
@@ -29,10 +30,13 @@ out(A) -> yaws_api:pre_ssi_string("
</erl>
+<p>
The above commands will
checkout the bleeding edge source, build it and install it at
127.0.0.1:80 with the docroot set to the local documentation.
+<p>Give return as password.
+
<p>Just <tt>make</tt> (without install)
will build the yaws system and do a local
install at http://127.0.0.1:8000. This is the typical mode of operation
@@ -58,32 +62,35 @@ include.mk file in the the toplevel directory.
<p>The yaws executable is a shell script which invokes the
erlang system and instructs it to start yaws.
The command line flags for yaws are documented in
-<a href="man.yaws?page=yaws.conf"> man page for <tt>yaws (1)</tt> </a>
+<a href="man.yaws?page=yaws"> man page for <tt>yaws (1)</tt> </a>
<p>When developing yaws code, the interactive mode is ideal. Typically
yaws is then started as:
<br>
<pre>
-# yaws -i -d
+# yaws -i
</pre>
<H2>Configuring Yaws</h2>
+<p>
Web server configuration can be supplied to yaws
in either of two ways depending
on wheter we run yaws as a standalone daemon or if we run yaws as an
embedded application inside another Erlang program.
<h3>Daemon mode</h3>
+<p>
The yaws configuration is described in
<a href="man.yaws?page=yaws.conf"> man page for <tt>yaws.conf (5)</tt> </a>
<h3>Embedded mode</h3>
+<p>
Not documented.
View
@@ -9,6 +9,7 @@ out(A) ->
<h1>Generating Dynamic Content</h1>
+<p>
Yaws have verry nice support for generating dynamic content on the fly.
We use embedded erlang code to generate the content. The Erlang code
is separated from the HTML code by <tt> &lt;erl> </tt> and <tt> &lt;/erl> </tt>
@@ -38,37 +39,50 @@ yaws_api:pre_ssi_string(L).
-
+<p>
Is a very small example where we have a HTML document with embedded
erlang code. A file which contains embedded erlang code must have the file
suffix <tt>.yaws</tt>
<br>
+<p>
The embedded erlang code can return the following values:
<ul>
-<li><tt>{html, DeepCharOrBinaryList}</tt> which will make the value of
+<li>
+<p>
+<tt>{html, DeepCharOrBinaryList}</tt> which will make the value of
<tt>DeepCharOrBinaryList</tt> be substituted into the HTML document.
-<li><tt>{header, Header}</tt> If a <tt>header</tt> structure is returned,
+<li>
+<p>
+<tt>{header, Header}</tt> If a <tt>header</tt> structure is returned,
an additional header is inserted among the HTTP headers generated by yaws.
This is used to insert for example Cookie headers.
The <tt>Header</tt> variable must not
be newline terminated.
-<li><tt>{allheaders, Header}</tt> If an <tt>allheaders</tt> structure
+<li>
+<p>
+<tt>{allheaders, Header}</tt> If an <tt>allheaders</tt> structure
is returned, all previously headers that have been generated, including those
default hedaers generated by yaws itself are erased, and replaced by
the headers in <tt>Headers</tt>. The variable <tt>Headers</tt> must be
a list of <tt>{header, Str}</tt> tuples. The <tt>Str</tt> must not
be newline terminated.
-<li><tt>{status, StatusCodeInt} </tt>
+<li>
+<p>
+<tt>{status, StatusCodeInt} </tt>
Is used to force yaws to return a different status code than the
default 200 code.
-<li><tt>ok</tt> Do nothing.
+<li>
+<p>
+<tt>ok</tt> Do nothing.
-<li><tt>{'EXIT', normal}</tt> which will make terminate the
+<li>
+<p>
+<tt>{'EXIT', normal}</tt> which will make terminate the
client connection in an uncontrolled way.
@@ -95,6 +109,8 @@ at the same time.
<h2>The argument</h2>
+
+<p>
The <tt>out/1</tt> function is supplied with a record argument. The
definition of that record is automatically included in the embedded erlang code
and the record definition is:
View
@@ -13,66 +13,73 @@ out(A) ->
-<tr><td> </td></tr>
+<tr><td> <p> </td></tr>
+<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>
-<tr><td> Hun 17, fixed yet another chunked encoding bug </td></tr>
-<tr><td> Jun 16, wrote a proper /etc/init.d start/stop/reload/status script, new flag cmdline -S which query the daemon status </td></tr>
+<tr><td> <p>Jun 17, fixed yet another chunked encoding bug </td></tr>
-<tr><td> Jun 15, fixed abug in the cache load machanism, pages were cached indefinitely. A bug in the new code in 0.48 didn't ship any content on 401 's </td></tr>
+<tr><td> <p>Jun 16, wrote a proper /etc/init.d start/stop/reload/status script, new flag cmdline -S which query the daemon status </td></tr>
-<tr><td>Jun 12 Redid the out/1 structure completely removed some/all headers and made
+
+<tr><td> <p>Jun 15, fixed abug in the cache load machanism, pages were cached indefinitely. A bug in the new code in 0.48 didn't ship any content on 401 's </td></tr>
+
+
+<tr><td><p>Jun 12 Redid the out/1 structure completely removed some/all headers and made
it possible to return headers as well as new status code inside any out/1 function. This makes it much easier to write apps in yaws. Also accumulated output into larger write chunks. Performnce enhancer.</td></tr>
-<tr><td> Jun 11, fixed Etag: and Last-Modified: headers for static content.
+<tr><td> <p>Jun 11, fixed Etag: and Last-Modified: headers for static content.
Fixed the Cache-Contol: headers for generated content.
The <erl> tag must
no longer be first on each line </td></tr>
-<tr><td> Jun 10, use prim_file: instead of file: calls, fix a bug
+<tr><td> <p>Jun 10, use prim_file: instead of file: calls, fix a bug
with iso 8859 chars in urls, virthost bug with multiple IP addresses </td></tr>
-<tr><td> May 26, added SSL support 0.40 </td> </tr>
+<tr><td> <p>May 26, added SSL support 0.40 </td> </tr>
- <tr><td> Mar 29, fixed a bug in the log wrapping which restarted the server</td></tr>
-<tr><td> Mar 26, released 0.32 </tr>
-<tr> <td> Mar 26, 2002. Fixed a bug where chunked encodings were
+ <tr><td> <p>Mar 29, fixed a bug in the log wrapping which restarted the server</td></tr>
+<tr><td> <p>Mar 26, released 0.32 </tr>
+<tr> <td> <p>Mar 26, 2002. Fixed a bug where chunked encodings were
missing a CRNL which made all yaws pages not render in IE </td> </tr>
-<tr> <td> Mar 25 2002 Fixed a bug with empty initial lines in yaws files.
+<tr> <td> <p>Mar 25 2002 Fixed a bug with empty initial lines in yaws files.
<br>Made access log files per virt host.
<br>Made the access log as well as the info/err log a wrap log, wraps at 50k.
-<tr><td> Mar 17 2002, buxfix in cache + added -T flag to yaws, which is
+<tr><td> <p>Mar 17 2002, buxfix in cache + added -T flag to yaws, which is
http protocol trace in log file
-<tr><td> Mar4 4 2002 made release 0.30 <td><tr>
+<tr><td> <p>Mar4 4 2002 made release 0.30 <td><tr>
-<tr><td> Feb 28, 2002 Added traffic trace -t flag and ~/public_html support.
+<tr><td> <p>Feb 28, 2002 Added traffic trace -t flag and ~/public_html support.
-<tr><td> Feb 26, 2002 Cought I/O from the erlang compiler when compiling.
+<tr><td> <p>Feb 26, 2002 Cought I/O from the erlang compiler when compiling.
The compiler will (wrongly) produce some errors plainly to the tty.
The RightThing would be to fix that, but .....
-<tr><td> Feb 22, 2002 yaws_api:set_cookie + examples </td></tr>
+<tr><td> <p>Feb 22, 2002 yaws_api:set_cookie + examples </td></tr>
-<tr><td> Feb 14, 2002 redid HTML tables for top docs </td></tr>
+<tr><td> <p>Feb 14, 2002 redid HTML tables for top docs </td></tr>
-<tr><td> Feb 13, 2002 released first version to the net 0.20 </td></tr>
+<tr><td> <p>Feb 13, 2002 released first version to the net 0.20 </td></tr>
-<tr><td> Feb 12, 2002 cached pages in RAM (ets tables) </td></tr>
+<tr><td> <p>Feb 12, 2002 cached pages in RAM (ets tables) </td></tr>
-<tr><td> Feb 7, 2002 added virtual hosting capabilities </td></tr>
+<tr><td> <p>Feb 7, 2002 added virtual hosting capabilities </td></tr>
-<tr><td> Feb 6, added query strings in URLs passed in #arg{} </td></tr>
+<tr><td> <p>Feb 6, added query strings in URLs passed in #arg{} </td></tr>
-<tr><td> Feb 5, 2002 added directory listings </td></tr>
+<tr><td> <p>Feb 5, 2002 added directory listings </td></tr>
-<tr><td> Jan 15, 2002. Started to hack the thing </td></tr>
+<tr><td> <p>Jan 15, 2002. Started to hack the thing </td></tr>
</table>
<erl>
Oops, something went wrong.

0 comments on commit a5e3fa4

Please sign in to comment.