Permalink
Browse files

Fixed Yaws response, reading docroot properly, 404 errors back to yaw…

…s, get mime type for static files
  • Loading branch information...
1 parent a407b2a commit 4940ef2c6003963b7f371fa4c87b041d46acf841 @choptastic choptastic committed Oct 24, 2011
Showing with 24 additions and 11 deletions.
  1. +3 −1 .gitignore
  2. +21 −10 src/yaws_bridge_modules/yaws_response_bridge.erl
View
@@ -1,2 +1,4 @@
erl_crash.dump
-.eunit/
+*~
+.*.sw?
+.eunit/
@@ -14,12 +14,13 @@ build_response(_Arg, Res) ->
%% Assemble headers...
Headers = assemble_headers(Res),
- %% Get the content type...
- ContentType = get_content_type(Res),
case Res#response.data of
{data, Body} ->
+ %% Get the content type...
+ ContentType = get_content_type(Res),
+
% Send the yaws response...
lists:flatten([
{status, Code},
@@ -35,15 +36,25 @@ build_response(_Arg, Res) ->
Seconds1 = calendar:gregorian_seconds_to_datetime(Seconds + TenYears),
ExpireDate = httpd_util:rfc1123_date(Seconds1),
- %% Get the file content
- {ok,Bin} = file:read_file(Path),
+ %OutSocket = yaws_api:arg_clisock(_Arg),
+ Docroot = yaws_api:arg_docroot(_Arg),
- %% Send the yaws response...
- lists:flatten([
- {status, Code},
- [{header, {"Expires", ExpireDate}} | Headers],
- {content, ContentType, Bin}
- ])
+ FullPath = [Docroot,Path],
+
+ ContentType = yaws_api:mime_type(Path),
+
+ %% Get the file content
+ FullResponse = case file:read_file(FullPath) of
+ {error,enoent} ->
+ yaws_outmod:out404(_Arg);
+ {ok,Bin} ->
+ [
+ {status, Code},
+ [{header, {"Expires", ExpireDate}} | Headers],
+ {content, ContentType, Bin}
+ ]
+ end,
+ lists:flatten(FullResponse)
end.
assemble_headers(Res) ->

0 comments on commit 4940ef2

Please sign in to comment.