Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge changes from remote master.

  • Loading branch information...
commit 13ed2af1f742d0cafe363a8d7de3edc0a2f274a1 2 parents 9a19a25 + c462679
@choptastic choptastic authored
View
10 src/cowboy_bridge_modules/cowboy_request_bridge.erl
@@ -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) ->
@@ -52,12 +52,16 @@ uri(ReqKey) ->
peer_ip(ReqKey) ->
?GET,
- {{IP, _Port, Req}} = cowboy_http_req:peer(Req),
+ {{IP, _Port}, NewReq} = cowboy_http_req:peer(Req),
+ NewRequestCache = _RequestCache#request_cache{request=NewReq},
+ ?PUT,
IP.
peer_port(ReqKey) ->
?GET,
- {{_IP, Port, Req}} = cowboy_http_req:peer(Req),
+ {{_IP, Port}, NewReq} = cowboy_http_req:peer(Req),
+ NewRequestCache = _RequestCache#request_cache{request=NewReq},
+ ?PUT,
Port.
headers(ReqKey) ->
View
23 src/cowboy_bridge_modules/cowboy_response_bridge.erl
@@ -47,8 +47,9 @@ build_response(ReqKey, Res) ->
},
cowboy_request_server:set(ReqKey,NewRequestCache),
{ok,FinReq};
-
- {file, Path} ->
+
+
+ {file, P} ->
%% Note: that this entire {file, Path} section should be avoided
%% as much as possible, since this reads the entire file into
%% memory before sending.
@@ -60,6 +61,11 @@ build_response(ReqKey, Res) ->
%% See https://github.com/nitrogen/nitrogen/blob/master/rel/overlay/cowboy/etc/cowboy.config
%% and
%% https://github.com/choptastic/nitrogen/blob/master/rel/overlay/cowboy/site/src/nitrogen_sup.erl
+
+
+ % Cowboy path starts with / so we need to remove it
+ Path = strip_leading_slash(P),
+
ExpireDate = simple_bridge_util:expires(years, 10),
[$. | Ext] = filename:extension(Path),
@@ -70,7 +76,9 @@ build_response(ReqKey, Res) ->
{"Content-Type",Mimetype}
],
- FullPath = filename:join(DocRoot,Path),
+ io:format("Serving static file ~p from docroot of ~p ~n",[Path, DocRoot]),
+
+ FullPath = filename:join(DocRoot, Path),
{ok, FinReq} = case file:read_file(FullPath) of
{error,enoent} ->
{ok, _R} = send(404,[],[],"Not Found",Req);
@@ -85,6 +93,15 @@ build_response(ReqKey, Res) ->
{ok, FinReq}
end.
+
+%% Just to strip leading slash, as cowboy tends to do this.
+%% If no leading slash, just return the path.
+strip_leading_slash([$/ | Path]) ->
+ Path;
+strip_leading_slash(Path) ->
+ Path.
+
+
send(Code,Headers,Cookies,Body,Req) ->
Req1 = prepare_cookies(Req,Cookies),
Req2 = prepare_headers(Req1,Headers),

0 comments on commit 13ed2af

Please sign in to comment.
Something went wrong with that request. Please try again.