Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix header handling: Expires should be set elsewhere, and header

values for files should not be discarded.
  • Loading branch information...
commit 4e1d981a7c8a83cb951118b4398fe4135259335a 1 parent e8f42d8
David N. Welton davidw authored choptastic committed
Showing with 19 additions and 19 deletions.
  1. +19 −19 src/mochiweb_bridge_modules/mochiweb_response_bridge.erl
38 src/mochiweb_bridge_modules/mochiweb_response_bridge.erl
View
@@ -11,33 +11,33 @@
init({Req,DocRoot}) ->
{Req,DocRoot}.
-build_response({Req, DocRoot}, Res) ->
+build_response({Req, DocRoot}, Res) ->
% Some values...
- Code = Res#response.statuscode,
- case Res#response.data of
- {data, Body} ->
+ Code = Res#response.statuscode,
- % Assemble headers...
- Headers = lists:flatten([
- [{X#header.name, X#header.value} || X <- Res#response.headers],
- [create_cookie_header(X) || X <- Res#response.cookies]
- ]),
+ %% Assemble headers...
+ Headers = lists:flatten([
+ [{X#header.name, X#header.value} || X <- Res#response.headers],
+ [create_cookie_header(X) || X <- Res#response.cookies]
+ ]),
- % Ensure content type...
- F = fun(Key) -> lists:keymember(Key, 1, Headers) end,
- HasContentType = lists:any(F, ["content-type", "Content-Type", "CONTENT-TYPE"]),
- Headers2 = case HasContentType of
- true -> Headers;
- false -> [{"Content-Type", "text/html"}|Headers]
- end,
+ %% Ensure content type...
+ F = fun(Key) ->
+ lists:keymember(Key, 1, Headers)
+ end,
+ HasContentType = lists:any(F, ["content-type", "Content-Type", "CONTENT-TYPE"]),
+ Headers2 = case HasContentType of
+ true -> Headers;
+ false -> [{"Content-Type", "text/html"}|Headers]
+ end,
+ case Res#response.data of
+ {data, Body} ->
% Send the mochiweb response...
Req:respond({Code, Headers2, Body});
{file, Path} ->
- ExpireDate = simple_bridge_util:expires(years, 10),
%% Create the response telling Mochiweb to serve the file...
- Headers = [{"Expires", ExpireDate}],
- Req:serve_file(tl(Path), DocRoot, Headers)
+ Req:serve_file(tl(Path), DocRoot, Headers2)
end.
create_cookie_header(Cookie) ->
Please sign in to comment.
Something went wrong with that request. Please try again.