Skip to content

Commit

Permalink
Fixed Yaws response, reading docroot properly, 404 errors back to yaw…
Browse files Browse the repository at this point in the history
…s, get mime type for static files
  • Loading branch information
choptastic committed Oct 24, 2011
1 parent a407b2a commit 4940ef2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
erl_crash.dump
.eunit/
*~
.*.sw?
.eunit/
31 changes: 21 additions & 10 deletions src/yaws_bridge_modules/yaws_response_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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) ->
Expand Down

0 comments on commit 4940ef2

Please sign in to comment.