Permalink
Browse files

Improve errors for static files (cowboy/webmachine)

  • Loading branch information...
1 parent 78b8791 commit 6a25d401cfa0b80032ebaa76f291e925fdbb30ba @choptastic choptastic committed Mar 21, 2013
@@ -45,14 +45,14 @@ build_response(ReqKey, Res) ->
%% Note: that this entire {file, Path} section should be avoided
%% as much as possible, since this reads the entire file into
%% memory before sending.
- %%
+ %%
%% You want to make sure that cowboy.config is properly set
%% up with paths so that the requests for static files are
%% properly handled by cowboy directly.
- %%
+ %%
%% See https://github.com/nitrogen/nitrogen/blob/master/rel/overlay/cowboy/etc/cowboy.config
%% and
- %% https://github.com/choptastic/nitrogen/blob/master/rel/overlay/cowboy/site/src/nitrogen_sup.erl
+ %% https://github.com/nitrogen/nitrogen/blob/master/rel/overlay/cowboy/site/src/nitrogen_sup.erl
%% % Cowboy path starts with / so we need to remove it
%% Path = strip_leading_slash(P),
@@ -65,13 +65,21 @@ build_response(ReqKey, Res) ->
%% FullPath = filename:join(DocRoot, Path),
%% {ok, FinReq} =
- %% case file:read_file(FullPath) of
- %% {error,enoent} -> {ok, _R} = send(404, [], [], "Not Found", Req);
- %% {ok,Bin} -> {ok, _R} = send(200, Headers, [], Bin, Req)
- %% end,
+ %% case file:read_file(FullPath) of
+ %% {error,enoent} -> {ok, _R} = send(404, [], [], "Not Found", Req);
+ %% {ok,Bin} -> {ok, _R} = send(200, Headers, [], Bin, Req)
+ %% end,
%% cowboy_request_server:set(ReqKey, RequestCache#request_cache{request = FinReq}),
%% {ok, FinReq}
- throw({error, P, fix_cowboy_routing})
+ throw({unrouted_static_file, [
+ {requested_file, P},
+ {description, "Simple Bridge through Cowboy is not set up to handle static files. Static Files should be handled by Cowboy through the routing table."},
+ {see_also, [
+ "https://github.com/nitrogen/nitrogen/blob/master/rel/overlay/cowboy/site/src/nitrogen_sup.erl",
+ "https://github.com/nitrogen/nitrogen/blob/master/rel/overlay/cowboy/etc/cowboy.config"
+ ]}
+
+ ]})
end.
%% %% Just to strip leading slash, as cowboy tends to do this.
@@ -1,3 +1,4 @@
+%% vim: ts=4 sw=4 et
%% Simple Bridge
%% Copyright (c) 2008-2010 Rusty Klophaus
%% See MIT-LICENSE for licensing information.
@@ -8,9 +9,9 @@
-export ([build_response/2,init/1]).
init(Req) ->
- Req.
+ Req.
-build_response(Req, Res) ->
+build_response(Req, Res) ->
Code = Res#response.statuscode,
case Res#response.data of
{data, Body} ->
@@ -21,7 +22,7 @@ build_response(Req, Res) ->
{content_length, Size},
[{X#header.name, X#header.value} || X <- Res#response.headers],
[create_cookie_header(X) || X <- Res#response.cookies]
- ]),
+ ]),
Req1 = wrq:set_response_code(Code, Req),
Req2 = wrq:set_resp_headers(Headers, Req1),
@@ -31,7 +32,15 @@ build_response(Req, Res) ->
%% works via a dispatch table mapping routes to
%% modules. For this case to happen, it means the dispatch
%% table mapped a route to a static file.
- throw({not_yet_implemented, {file, Path}})
+ throw({unrouted_static_file, [
+ {requested_file, Path},
+ {description, "Simple Bridge for Webmachine is not set up to handle static files. Static files should be handled by Webmachine through the dispatch table."},
+ {see_also, [
+ "https://github.com/nitrogen/nitrogen/blob/master/rel/overlay/webmachine/site/src/nitrogen_sup.erl#L46",
+ "https://github.com/nitrogen/nitrogen/blob/master/rel/overlay/webmachine/etc/webmachine.config"
+ ]}
+ ]})
+
end.
create_cookie_header(Cookie) ->

0 comments on commit 6a25d40

Please sign in to comment.