Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…s, get mime type for static files
  • Loading branch information...
commit 4940ef2c6003963b7f371fa4c87b041d46acf841 1 parent a407b2a
@choptastic choptastic authored
Showing with 24 additions and 11 deletions.
  1. +3 −1 .gitignore
  2. +21 −10 src/yaws_bridge_modules/yaws_response_bridge.erl
View
4 .gitignore
@@ -1,2 +1,4 @@
erl_crash.dump
-.eunit/
+*~
+.*.sw?
+.eunit/
View
31 src/yaws_bridge_modules/yaws_response_bridge.erl
@@ -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) ->
Please sign in to comment.
Something went wrong with that request. Please try again.