hongruiqi / happs

Automatically exported from code.google.com/p/happs
0 stars 0 forks source link

fileServe directory handling breaks relative references #48

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When using fileServe, a request for a URL such as "http://localhost/foo"
will return a default file such as "foo/index.html", assuming that "foo" is
a directory and "index.html" exists.

This is wrong.  :)

The problem is that the web browser sees that the URL doesn't have a
trailing slash, and so treats the base for links as "/" instead of "/foo/".
 This means that any relative links in the served page will be relative to
the parent directory rather than to the directory from which the page was
served.

The usual solution to this (i.e. what Apache and other web servers do) is
that a request to a directory without a trailing slash produces an HTTP 301
redirect response to the same URL with a trailing slash added.

The problem can be reproduced with a minimal server, e.g.:

  import Happstack.Server
  simpleHTTP nullConf (fileServe [] "/path/to/docroot")

Create a subdirectory "/path/to/docroot/foo", and in that directory create
a file "index.html" which contains: <a href="bar.html">bar</a>.  Create
another file "bar.html" in the same directory, with arbitrary content.

Run the server, use a browser to navigate to "http://localhost/foo", and
click on the "bar" link.  You should get a "file not found" error. 
However, navigating to "http://localhost/foo/" (with a trailing slash) and
clicking the "bar" link should work, and return the contents of "bar.html"

This was tested with a Happstack dev version pulled on 2009-04-11, running
on Debian.

Original issue reported on code.google.com by anton...@gmail.com on 10 May 2009 at 6:12

GoogleCodeExporter commented 8 years ago
I entered this on the HAppS issues list by mistake.  Reentered on Happstack 
list as
issue 93.

Original comment by anton...@gmail.com on 10 May 2009 at 11:35