Erlang Mailing Lists

Author Message

<  Yaws mailing list  ~  Send a 404 on file not found from appmod

Guest
Posted: Wed Sep 06, 2006 6:50 pm Reply with quote
Guest
Hi,

Is it possible to send a 404 page from an appmod using a built in yaws
facility? I don't want a custom one, just want to tell the client
there is no page. Using {status, 404} doesn't seem to work, unless
the appmod is overriding it somehow. All that is returned is the
empty page.

The appmod is included below, it tries to locate a match for a file if
the extension is omitted and doesn't exist. The 404 path is executed
if the file isn't found.

Regards,
Chris


-module(yappm_rewrite).
-export([out/1]).

-include("$YAWS_INCLUDE/yaws_api.hrl").
-include("yappm_rewrite.hrl").

%% Get extensions from opaque section of yaws.conf.
%%
file_extenions(A) ->
case lists:keysearch (?SEXT_TAG, 1, A#arg.opaque) of
{value, {?SEXT_TAG, StrExts}} ->
string:tokens(StrExts, " ");
_ ->
[]
end.

url_to_file(A, Url) ->
A#arg.docroot ++ Url.

file_type(F) ->
case {filelib:is_dir(F), filelib:is_file(F)} of
{true, _} ->
directory;
{false, true} ->
file;
{_, _} ->
none
end.

test_file(F, [X|Xs]) ->
error_logger:info_msg("testing file:~p", [F ++ X]),
case file_type(F ++ X) of
file ->
{value, X};
directory ->
undefined;
none ->
test_file(F, Xs)
end;
test_file(_F, []) ->
undefined.

is_known(A, F) ->
Exts = file_extenions(A),
case test_file(F, Exts) of
{value, X} ->
{ok, X};
_ ->
undefined
end.

find_url(A) ->
F = url_to_file(A, A#arg.appmoddata),
error_logger:info_msg("finding ~p", [F]),
case file_type(F) of
file ->
{url, A#arg.appmoddata};
directory ->
undefined;
none ->
case is_known(A, F) of
{ok, Ext} ->
{url, A#arg.appmoddata ++ Ext};
_X ->
undefined
end
end.

out(A) ->
case find_url(A) of
{url, Url} ->
{page, Url};
_ ->
error_logger:info_msg("sending 404"),
{status, 404}
end.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
Guest
Posted: Wed Sep 06, 2006 7:42 pm Reply with quote
Guest
> Hi,
>
> Is it possible to send a 404 page from an appmod using a built in yaws
> facility? I don't want a custom one, just want to tell the client
> there is no page. Using {status, 404} doesn't seem to work, unless
> the appmod is overriding it somehow. All that is returned is the
> empty page.


You should check the retuned header. Use curl, the www developers
tool number one.

Yaws returns a perfect 404, as in:

[klacke@guld]~ > curl -I http://localhost:8000/a/jaja
HTTP/1.1 404 Not Found
Server: Yaws/1.64 Yet Another Web Server
Date: Wed, 06 Sep 2006 19:31:28 GMT
Content-Type: text/html



No content at all though, If you want some text a'la "page not found"
you have to send that text to the browser as in:

out(A) ->
[{html, "Foobar is not valid html"},
{status, 404}].



/klacke





-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
Guest
Posted: Wed Sep 06, 2006 8:48 pm Reply with quote
Guest
On 06/09/06, klacke@tail-f.com <klacke@tail-f.com> wrote:

> You should check the retuned header. Use curl, the www developers
> tool number one.

Thanks for the tip.

I take then, if you use appmods you have to generate your own response
pages when there's a problem. i.e. you can't tell yaws here's a 400+
HTTP code, send whatever you'd usually send for that. I don't really
care about this anyway, I was just curious.

Chris

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
Guest
Posted: Wed Sep 06, 2006 9:03 pm Reply with quote
Guest
> On 06/09/06, klacke@tail-f.com <klacke@tail-f.com> wrote:
>
>> You should check the retuned header. Use curl, the www developers
>> tool number one.
>
> Thanks for the tip.
>
> I take then, if you use appmods you have to generate your own response
> pages when there's a problem. i.e. you can't tell yaws here's a 400+
> HTTP code, send whatever you'd usually send for that. I don't really
> care about this anyway, I was just curious.
>



Well, you do have to generate all output that should be returned
to the client.

However, Yaws has configurable bahaviour for delivering 404
messages (see yaws.conf(5)) (errormod_404) and the default
is a module called - yaws_404.erl

Thus, you could just do:

out(A) ->
yaws_404:out404(A).

To get precicely the same behaviour as the default.


/klacke

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum