mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Remove extraneous newlines in cowboy_static
This commit is contained in:
parent
b29ea644fb
commit
87017e9699
1 changed files with 0 additions and 15 deletions
|
@ -204,12 +204,10 @@
|
||||||
etag_fun :: {fun(([etagarg()], T) ->
|
etag_fun :: {fun(([etagarg()], T) ->
|
||||||
undefined | {strong | weak, binary()}), T}}).
|
undefined | {strong | weak, binary()}), T}}).
|
||||||
|
|
||||||
|
|
||||||
%% @private Upgrade from HTTP handler to REST handler.
|
%% @private Upgrade from HTTP handler to REST handler.
|
||||||
init({_Transport, http}, _Req, _Opts) ->
|
init({_Transport, http}, _Req, _Opts) ->
|
||||||
{upgrade, protocol, cowboy_rest}.
|
{upgrade, protocol, cowboy_rest}.
|
||||||
|
|
||||||
|
|
||||||
%% @private Set up initial state of REST handler.
|
%% @private Set up initial state of REST handler.
|
||||||
-spec rest_init(Req, list()) -> {ok, Req, #state{}} when Req::cowboy_req:req().
|
-spec rest_init(Req, list()) -> {ok, Req, #state{}} when Req::cowboy_req:req().
|
||||||
rest_init(Req, Opts) ->
|
rest_init(Req, Opts) ->
|
||||||
|
@ -245,7 +243,6 @@ rest_init(Req, Opts) ->
|
||||||
end,
|
end,
|
||||||
{ok, Req1, State}.
|
{ok, Req1, State}.
|
||||||
|
|
||||||
|
|
||||||
%% @private Only allow GET and HEAD requests on files.
|
%% @private Only allow GET and HEAD requests on files.
|
||||||
-spec allowed_methods(Req, #state{})
|
-spec allowed_methods(Req, #state{})
|
||||||
-> {[binary()], Req, #state{}} when Req::cowboy_req:req().
|
-> {[binary()], Req, #state{}} when Req::cowboy_req:req().
|
||||||
|
@ -260,7 +257,6 @@ malformed_request(Req, #state{filepath=error}=State) ->
|
||||||
malformed_request(Req, State) ->
|
malformed_request(Req, State) ->
|
||||||
{false, Req, State}.
|
{false, Req, State}.
|
||||||
|
|
||||||
|
|
||||||
%% @private Check if the resource exists under the document root.
|
%% @private Check if the resource exists under the document root.
|
||||||
-spec resource_exists(Req, #state{})
|
-spec resource_exists(Req, #state{})
|
||||||
-> {boolean(), Req, #state{}} when Req::cowboy_req:req().
|
-> {boolean(), Req, #state{}} when Req::cowboy_req:req().
|
||||||
|
@ -269,7 +265,6 @@ resource_exists(Req, #state{fileinfo={error, _}}=State) ->
|
||||||
resource_exists(Req, #state{fileinfo={ok, Fileinfo}}=State) ->
|
resource_exists(Req, #state{fileinfo={ok, Fileinfo}}=State) ->
|
||||||
{Fileinfo#file_info.type =:= regular, Req, State}.
|
{Fileinfo#file_info.type =:= regular, Req, State}.
|
||||||
|
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% Access to a file resource is forbidden if it exists and the local node does
|
%% Access to a file resource is forbidden if it exists and the local node does
|
||||||
%% not have permission to read it. Directory listings are always forbidden.
|
%% not have permission to read it. Directory listings are always forbidden.
|
||||||
|
@ -284,14 +279,12 @@ forbidden(Req, #state{fileinfo={error, _}}=State) ->
|
||||||
forbidden(Req, #state{fileinfo={ok, #file_info{access=Access}}}=State) ->
|
forbidden(Req, #state{fileinfo={ok, #file_info{access=Access}}}=State) ->
|
||||||
{not (Access =:= read orelse Access =:= read_write), Req, State}.
|
{not (Access =:= read orelse Access =:= read_write), Req, State}.
|
||||||
|
|
||||||
|
|
||||||
%% @private Read the time a file system system object was last modified.
|
%% @private Read the time a file system system object was last modified.
|
||||||
-spec last_modified(Req, #state{})
|
-spec last_modified(Req, #state{})
|
||||||
-> {calendar:datetime(), Req, #state{}} when Req::cowboy_req:req().
|
-> {calendar:datetime(), Req, #state{}} when Req::cowboy_req:req().
|
||||||
last_modified(Req, #state{fileinfo={ok, #file_info{mtime=Modified}}}=State) ->
|
last_modified(Req, #state{fileinfo={ok, #file_info{mtime=Modified}}}=State) ->
|
||||||
{erlang:localtime_to_universaltime(Modified), Req, State}.
|
{erlang:localtime_to_universaltime(Modified), Req, State}.
|
||||||
|
|
||||||
|
|
||||||
%% @private Generate the ETag header value for this file.
|
%% @private Generate the ETag header value for this file.
|
||||||
%% The ETag header value is only generated if the resource is a file that
|
%% The ETag header value is only generated if the resource is a file that
|
||||||
%% exists in document root.
|
%% exists in document root.
|
||||||
|
@ -307,7 +300,6 @@ generate_etag(Req, #state{fileinfo={_, #file_info{type=regular, inode=INode,
|
||||||
generate_etag(Req, State) ->
|
generate_etag(Req, State) ->
|
||||||
{undefined, Req, State}.
|
{undefined, Req, State}.
|
||||||
|
|
||||||
|
|
||||||
%% @private Return the content type of a file.
|
%% @private Return the content type of a file.
|
||||||
-spec content_types_provided(cowboy_req:req(), #state{}) -> tuple().
|
-spec content_types_provided(cowboy_req:req(), #state{}) -> tuple().
|
||||||
content_types_provided(Req, #state{filepath=Filepath,
|
content_types_provided(Req, #state{filepath=Filepath,
|
||||||
|
@ -316,7 +308,6 @@ content_types_provided(Req, #state{filepath=Filepath,
|
||||||
|| T <- MimetypesFun(Filepath, MimetypesData)],
|
|| T <- MimetypesFun(Filepath, MimetypesData)],
|
||||||
{Mimetypes, Req, State}.
|
{Mimetypes, Req, State}.
|
||||||
|
|
||||||
|
|
||||||
%% @private Return a function that writes a file directly to the socket.
|
%% @private Return a function that writes a file directly to the socket.
|
||||||
-spec file_contents(cowboy_req:req(), #state{}) -> tuple().
|
-spec file_contents(cowboy_req:req(), #state{}) -> tuple().
|
||||||
file_contents(Req, #state{filepath=Filepath,
|
file_contents(Req, #state{filepath=Filepath,
|
||||||
|
@ -331,7 +322,6 @@ file_contents(Req, #state{filepath=Filepath,
|
||||||
end,
|
end,
|
||||||
{{stream, Filesize, Writefile}, Req, State}.
|
{{stream, Filesize, Writefile}, Req, State}.
|
||||||
|
|
||||||
|
|
||||||
-spec directory_path(dirspec()) -> dirpath().
|
-spec directory_path(dirspec()) -> dirpath().
|
||||||
directory_path({priv_dir, App, []}) ->
|
directory_path({priv_dir, App, []}) ->
|
||||||
priv_dir_path(App);
|
priv_dir_path(App);
|
||||||
|
@ -366,7 +356,6 @@ check_path([H|T]) ->
|
||||||
nomatch -> check_path(T)
|
nomatch -> check_path(T)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
%% @private Join the the directory and request paths.
|
%% @private Join the the directory and request paths.
|
||||||
-spec join_paths(dirpath(), [binary()]) -> binary().
|
-spec join_paths(dirpath(), [binary()]) -> binary().
|
||||||
join_paths([H|_]=Dirpath, Filepath) when is_integer(H) ->
|
join_paths([H|_]=Dirpath, Filepath) when is_integer(H) ->
|
||||||
|
@ -378,7 +367,6 @@ join_paths(Dirpath, Filepath) when is_binary(Dirpath) ->
|
||||||
join_paths([], Filepath) ->
|
join_paths([], Filepath) ->
|
||||||
filename:join(Filepath).
|
filename:join(Filepath).
|
||||||
|
|
||||||
|
|
||||||
%% @private Return the path to the priv/ directory of an application.
|
%% @private Return the path to the priv/ directory of an application.
|
||||||
-spec priv_dir_path(atom()) -> string().
|
-spec priv_dir_path(atom()) -> string().
|
||||||
priv_dir_path(App) ->
|
priv_dir_path(App) ->
|
||||||
|
@ -394,7 +382,6 @@ priv_dir_mod(Mod) ->
|
||||||
File -> filename:join([filename:dirname(File),"../priv"])
|
File -> filename:join([filename:dirname(File),"../priv"])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
%% @private Use application/octet-stream as the default mimetype.
|
%% @private Use application/octet-stream as the default mimetype.
|
||||||
%% If a list of extension - mimetype pairs are provided as the mimetypes
|
%% If a list of extension - mimetype pairs are provided as the mimetypes
|
||||||
%% an attempt to find the mimetype using the file extension. If no match
|
%% an attempt to find the mimetype using the file extension. If no match
|
||||||
|
@ -419,7 +406,6 @@ path_to_mimetypes_(Ext, Extensions) ->
|
||||||
default_mimetype() ->
|
default_mimetype() ->
|
||||||
[{<<"application">>, <<"octet-stream">>, []}].
|
[{<<"application">>, <<"octet-stream">>, []}].
|
||||||
|
|
||||||
|
|
||||||
%% @private Do not send ETag headers in the default configuration.
|
%% @private Do not send ETag headers in the default configuration.
|
||||||
-spec no_etag_function([etagarg()], undefined) -> undefined.
|
-spec no_etag_function([etagarg()], undefined) -> undefined.
|
||||||
no_etag_function(_Args, undefined) ->
|
no_etag_function(_Args, undefined) ->
|
||||||
|
@ -435,7 +421,6 @@ attr_etag_function(Args, Attrs) ->
|
||||||
end || Attr <- Attrs],
|
end || Attr <- Attrs],
|
||||||
{strong, list_to_binary([H|T])}.
|
{strong, list_to_binary([H|T])}.
|
||||||
|
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-define(_eq(E, I), ?_assertEqual(E, I)).
|
-define(_eq(E, I), ?_assertEqual(E, I)).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue