301 when leaving off the trailing slash

10 views
Skip to first unread message

0x6e6562

unread,
Jul 14, 2009, 6:40:27 PM7/14/09
to MochiWeb
Hi,

When doing a GET for a URI without a trailing slash, mochiweb returns
a 200 with the content of the index.html.

Other http implementations seem to return a 301 referring to the same
URI, except with the slash appended.

This appears to have the effect that when client request relative
resources defined in the index.html, they don't set the context root
to the referenced resources and hence receive 404s for these.

Is it just part of the design philosophy of mochiweb that each
application has to decide for itself when to return a 301?

Thx,

Ben

Kunthar

unread,
Jul 14, 2009, 7:08:47 PM7/14/09
to moch...@googlegroups.com
Not answering design part.

Possible solutions;
1. Find related code and change this to handle your case,
2. http://code.google.com/p/webmachine/wiki/WebmachineSetup


Have a nice day
\|/ Kunthar

Bob Ippolito

unread,
Jul 14, 2009, 7:16:56 PM7/14/09
to moch...@googlegroups.com
3. MochiWeb's capability to serve static files is for demonstration
purposes, not really for production use. I'd accept a patch that did
the redirect, but if you're relying on mochiweb to serve lots of
static files from disk every request using that code, you're probably
doing it wrong.

Ben Hood

unread,
Jul 14, 2009, 8:27:44 PM7/14/09
to moch...@googlegroups.com
Bob,

On Wed, Jul 15, 2009 at 12:16 AM, Bob Ippolito<b...@redivi.com> wrote:
>
> 3. MochiWeb's capability to serve static files is for demonstration
> purposes, not really for production use. I'd accept a patch that did
> the redirect, but if you're relying on mochiweb to serve lots of
> static files from disk every request using that code, you're probably
> doing it wrong.

Thanks for the heads up. Looking at the serve_file/3 implementation, I
can see your point about the non-production readiness. My assumption
was that most people would stick either some kind of front-end http
server in front of mochiweb for static content, or some kind of
accelerator.

In my use case, I want to use mochiweb to handle JSON RPCs as opposed
to serving out lots of static content. In fact, the static content is
just their to serve up the web app and JS required for the client to
make the RPCs in the first place.

So I probably will end up patching mochiweb to handle this, so when I
do this, I'll fire off a patch.

Thx,

Ben

Ben

Ben Hood

unread,
Jul 16, 2009, 5:19:59 PM7/16/09
to moch...@googlegroups.com
Bob,

On Wed, Jul 15, 2009 at 12:16 AM, Bob Ippolito<b...@redivi.com> wrote:

> I'd accept a patch that did the redirect

I've attached a patch. Because I couldn't see an integration test
suite for verifying HTTP responses from mochiweb, I wasn't able to add
a unit test for this. It has been tested manually though.

Ben

301.patch
Reply all
Reply to author
Forward
0 new messages