Permalink
Browse files

Making Cowboy path start with "/"

  • Loading branch information...
1 parent fd38393 commit 3f6a5e4b5fe65432c8ca92c58bf77c33a85a9470 @rambocoder rambocoder committed Apr 11, 2012
@@ -42,7 +42,7 @@ path(ReqKey) ->
{Path, Req} = cowboy_http_req:path(Req),
case Path of
[] -> "/";
- _ -> b2l(filename:join(Path))
+ _ -> "/" ++ b2l(filename:join(Path)) %Mochweb returns path as /path and Cowboy does not
end.
uri(ReqKey) ->
@@ -48,7 +48,9 @@ build_response(ReqKey, Res) ->
cowboy_request_server:set(ReqKey,NewRequestCache),
{ok,FinReq};
- {file, Path} ->
+ {file, P} ->
+ % Cowboy path starts with / so we need to remove it
+ Path = lists:nthtail(length("/"), P),
%% Calculate expire date far into future...
Seconds = calendar:datetime_to_gregorian_seconds(calendar:local_time()),
TenYears = 10 * 365 * 24 * 60 * 60,
@@ -64,9 +66,9 @@ build_response(ReqKey, Res) ->
{"Content-Type",Mimetype}
],
- io:format("Serving static file ~p~n",[Path]),
+ io:format("Serving static file ~p from docroot of ~p ~n",[Path, DocRoot]),
- FullPath = filename:join(DocRoot,Path),
+ FullPath = filename:join(DocRoot, Path),
{ok, FinReq} = case file:read_file(FullPath) of
{error,enoent} ->
{ok, _R} = send(404,[],[],"Not Found",Req);

0 comments on commit 3f6a5e4

Please sign in to comment.