mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Make cowlib a proper dependency
Start moving a few functions from Cowboy into cowlib.
This commit is contained in:
parent
bd0de074c3
commit
4a30198f90
27 changed files with 38 additions and 45 deletions
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ PLT_APPS = crypto public_key ssl
|
||||||
# Dependencies.
|
# Dependencies.
|
||||||
|
|
||||||
DEPS = cowlib ranch
|
DEPS = cowlib ranch
|
||||||
dep_cowlib = pkg://cowlib master
|
dep_cowlib = pkg://cowlib 0.1.0
|
||||||
dep_ranch = pkg://ranch 0.8.5
|
dep_ranch = pkg://ranch 0.8.5
|
||||||
|
|
||||||
TEST_DEPS = ct_helper gun
|
TEST_DEPS = ct_helper gun
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(basic_auth).
|
ok = application:start(basic_auth).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(chunked_hello_world).
|
ok = application:start(chunked_hello_world).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(compress_response).
|
ok = application:start(compress_response).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(cookie).
|
ok = application:start(cookie).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(echo_get).
|
ok = application:start(echo_get).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(echo_post).
|
ok = application:start(echo_post).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(error_hook).
|
ok = application:start(error_hook).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(eventsource).
|
ok = application:start(eventsource).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(hello_world).
|
ok = application:start(hello_world).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(markdown_middleware).
|
ok = application:start(markdown_middleware).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(rest_hello_world).
|
ok = application:start(rest_hello_world).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(rest_pastebin).
|
ok = application:start(rest_pastebin).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(rest_stream_response).
|
ok = application:start(rest_stream_response).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(ssl_hello_world).
|
ok = application:start(ssl_hello_world).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(static_world).
|
ok = application:start(static_world).
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(web_server).
|
ok = application:start(web_server).
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
ok = application:start(crypto),
|
ok = application:start(crypto),
|
||||||
|
ok = application:start(cowlib),
|
||||||
ok = application:start(ranch),
|
ok = application:start(ranch),
|
||||||
ok = application:start(cowboy),
|
ok = application:start(cowboy),
|
||||||
ok = application:start(websocket).
|
ok = application:start(websocket).
|
||||||
|
|
|
@ -3,10 +3,12 @@ Getting started
|
||||||
|
|
||||||
Cowboy does nothing by default.
|
Cowboy does nothing by default.
|
||||||
|
|
||||||
Cowboy requires the `crypto` and `ranch` applications to be started.
|
Cowboy requires the `crypto`, `cowlib` and `ranch` applications to be
|
||||||
|
started.
|
||||||
|
|
||||||
``` erlang
|
``` erlang
|
||||||
ok = application:start(crypto).
|
ok = application:start(crypto).
|
||||||
|
ok = application:start(cowlib).
|
||||||
ok = application:start(ranch).
|
ok = application:start(ranch).
|
||||||
ok = application:start(cowboy).
|
ok = application:start(cowboy).
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
{deps, [
|
{deps, [
|
||||||
|
{cowlib, ".*", {git, "git://github.com/extend/cowlib.git", "0.1.0"}},
|
||||||
{ranch, ".*", {git, "git://github.com/extend/ranch.git", "0.8.5"}}
|
{ranch, ".*", {git, "git://github.com/extend/ranch.git", "0.8.5"}}
|
||||||
]}.
|
]}.
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
kernel,
|
kernel,
|
||||||
stdlib,
|
stdlib,
|
||||||
ranch,
|
ranch,
|
||||||
|
cowlib,
|
||||||
crypto
|
crypto
|
||||||
]},
|
]},
|
||||||
{mod, {cowboy_app, []}},
|
{mod, {cowboy_app, []}},
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
%% Internal.
|
%% Internal.
|
||||||
-export([init/4]).
|
-export([init/4]).
|
||||||
-export([parse_request/3]).
|
-export([parse_request/3]).
|
||||||
-export([parse_host/3]).
|
|
||||||
-export([resume/6]).
|
-export([resume/6]).
|
||||||
|
|
||||||
-type opts() :: [{compress, boolean()}
|
-type opts() :: [{compress, boolean()}
|
||||||
|
@ -443,6 +442,9 @@ default_port(ssl) -> 443;
|
||||||
default_port(_) -> 80.
|
default_port(_) -> 80.
|
||||||
|
|
||||||
%% Another hurtful block of code. :)
|
%% Another hurtful block of code. :)
|
||||||
|
%%
|
||||||
|
%% Same code as cow_http:parse_fullhost/1, but inline because we
|
||||||
|
%% really want this to go fast.
|
||||||
parse_host(<< $[, Rest/bits >>, false, <<>>) ->
|
parse_host(<< $[, Rest/bits >>, false, <<>>) ->
|
||||||
parse_host(Rest, true, << $[ >>);
|
parse_host(Rest, true, << $[ >>);
|
||||||
parse_host(<<>>, false, Acc) ->
|
parse_host(<<>>, false, Acc) ->
|
||||||
|
@ -593,24 +595,3 @@ error_terminate(Status, Req, State) ->
|
||||||
terminate(#state{socket=Socket, transport=Transport}) ->
|
terminate(#state{socket=Socket, transport=Transport}) ->
|
||||||
Transport:close(Socket),
|
Transport:close(Socket),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% Tests.
|
|
||||||
|
|
||||||
-ifdef(TEST).
|
|
||||||
|
|
||||||
parse_host(RawHost) ->
|
|
||||||
parse_host(RawHost, false, <<>>).
|
|
||||||
|
|
||||||
parse_host_test() ->
|
|
||||||
{<<"example.org">>, 8080} = parse_host(<<"example.org:8080">>),
|
|
||||||
{<<"example.org">>, undefined} = parse_host(<<"example.org">>),
|
|
||||||
{<<"192.0.2.1">>, 8080} = parse_host(<<"192.0.2.1:8080">>),
|
|
||||||
{<<"192.0.2.1">>, undefined} = parse_host(<<"192.0.2.1">>),
|
|
||||||
{<<"[2001:db8::1]">>, 8080} = parse_host(<<"[2001:db8::1]:8080">>),
|
|
||||||
{<<"[2001:db8::1]">>, undefined} = parse_host(<<"[2001:db8::1]">>),
|
|
||||||
{<<"[::ffff:192.0.2.1]">>, 8080} =
|
|
||||||
parse_host(<<"[::ffff:192.0.2.1]:8080">>),
|
|
||||||
{<<"[::ffff:192.0.2.1]">>, undefined} =
|
|
||||||
parse_host(<<"[::ffff:192.0.2.1]">>).
|
|
||||||
|
|
||||||
-endif.
|
|
||||||
|
|
|
@ -340,11 +340,11 @@ delete_child(Pid, State=#state{children=Children}) ->
|
||||||
|
|
||||||
request_init(FakeSocket, Peer, OnRequest, OnResponse,
|
request_init(FakeSocket, Peer, OnRequest, OnResponse,
|
||||||
Env, Middlewares, Method, Host, Path, Version, Headers) ->
|
Env, Middlewares, Method, Host, Path, Version, Headers) ->
|
||||||
Version2 = parse_version(Version),
|
{Host2, Port} = cow_http:parse_fullhost(Host),
|
||||||
{Host2, Port} = cowboy_protocol:parse_host(Host, false, <<>>),
|
{Path2, Qs} = cow_http:parse_fullpath(Path),
|
||||||
{Path2, Query} = parse_path(Path, <<>>),
|
Version2 = cow_http:parse_version(Version),
|
||||||
Req = cowboy_req:new(FakeSocket, ?MODULE, Peer,
|
Req = cowboy_req:new(FakeSocket, ?MODULE, Peer,
|
||||||
Method, Path2, Query, Version2, Headers,
|
Method, Path2, Qs, Version2, Headers,
|
||||||
Host2, Port, <<>>, true, false, OnResponse),
|
Host2, Port, <<>>, true, false, OnResponse),
|
||||||
case OnRequest of
|
case OnRequest of
|
||||||
undefined ->
|
undefined ->
|
||||||
|
@ -357,23 +357,6 @@ request_init(FakeSocket, Peer, OnRequest, OnResponse,
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
parse_version(<<"HTTP/1.1">>) ->
|
|
||||||
'HTTP/1.1';
|
|
||||||
parse_version(<<"HTTP/1.0">>) ->
|
|
||||||
'HTTP/1.0'.
|
|
||||||
|
|
||||||
parse_path(<<>>, Path) ->
|
|
||||||
{Path, <<>>};
|
|
||||||
parse_path(<< $?, Rest/binary >>, Path) ->
|
|
||||||
parse_query(Rest, Path, <<>>);
|
|
||||||
parse_path(<< C, Rest/binary >>, SoFar) ->
|
|
||||||
parse_path(Rest, << SoFar/binary, C >>).
|
|
||||||
|
|
||||||
parse_query(<<>>, Path, Query) ->
|
|
||||||
{Path, Query};
|
|
||||||
parse_query(<< C, Rest/binary >>, Path, SoFar) ->
|
|
||||||
parse_query(Rest, Path, << SoFar/binary, C >>).
|
|
||||||
|
|
||||||
-spec execute(cowboy_req:req(), cowboy_middleware:env(), [module()])
|
-spec execute(cowboy_req:req(), cowboy_middleware:env(), [module()])
|
||||||
-> ok.
|
-> ok.
|
||||||
execute(Req, _, []) ->
|
execute(Req, _, []) ->
|
||||||
|
|
|
@ -37,6 +37,7 @@ groups() ->
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:start(crypto),
|
application:start(crypto),
|
||||||
|
application:start(cowlib),
|
||||||
application:start(ranch),
|
application:start(ranch),
|
||||||
application:start(cowboy),
|
application:start(cowboy),
|
||||||
%% /tmp must be used as the parent directory for the virtualenv because
|
%% /tmp must be used as the parent directory for the virtualenv because
|
||||||
|
@ -58,6 +59,7 @@ end_per_suite(_Config) ->
|
||||||
os:cmd("deactivate"),
|
os:cmd("deactivate"),
|
||||||
application:stop(cowboy),
|
application:stop(cowboy),
|
||||||
application:stop(ranch),
|
application:stop(ranch),
|
||||||
|
application:stop(cowlib),
|
||||||
application:stop(crypto),
|
application:stop(crypto),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -196,6 +196,7 @@ groups() ->
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:start(crypto),
|
application:start(crypto),
|
||||||
|
application:start(cowlib),
|
||||||
application:start(ranch),
|
application:start(ranch),
|
||||||
application:start(cowboy),
|
application:start(cowboy),
|
||||||
Dir = ?config(priv_dir, Config) ++ "/static",
|
Dir = ?config(priv_dir, Config) ++ "/static",
|
||||||
|
@ -207,6 +208,7 @@ end_per_suite(Config) ->
|
||||||
ct_helper:delete_static_dir(Dir),
|
ct_helper:delete_static_dir(Dir),
|
||||||
application:stop(cowboy),
|
application:stop(cowboy),
|
||||||
application:stop(ranch),
|
application:stop(ranch),
|
||||||
|
application:stop(cowlib),
|
||||||
application:stop(crypto),
|
application:stop(crypto),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ groups() ->
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:start(crypto),
|
application:start(crypto),
|
||||||
|
application:start(cowlib),
|
||||||
application:start(ranch),
|
application:start(ranch),
|
||||||
application:start(cowboy),
|
application:start(cowboy),
|
||||||
application:start(asn1),
|
application:start(asn1),
|
||||||
|
@ -62,6 +63,7 @@ end_per_suite(Config) ->
|
||||||
application:stop(asn1),
|
application:stop(asn1),
|
||||||
application:stop(cowboy),
|
application:stop(cowboy),
|
||||||
application:stop(ranch),
|
application:stop(ranch),
|
||||||
|
application:stop(cowlib),
|
||||||
application:stop(crypto),
|
application:stop(crypto),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ groups() ->
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:start(crypto),
|
application:start(crypto),
|
||||||
|
application:start(cowlib),
|
||||||
application:start(ranch),
|
application:start(ranch),
|
||||||
application:start(cowboy),
|
application:start(cowboy),
|
||||||
Config.
|
Config.
|
||||||
|
@ -77,6 +78,7 @@ init_per_suite(Config) ->
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
application:stop(cowboy),
|
application:stop(cowboy),
|
||||||
application:stop(ranch),
|
application:stop(ranch),
|
||||||
|
application:stop(cowlib),
|
||||||
application:stop(crypto),
|
application:stop(crypto),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue