diff options
-rw-r--r-- | Makefile | 34 | ||||
-rw-r--r-- | src/cowboy_req.erl | 5 | ||||
-rw-r--r-- | src/cowboy_router.erl | 15 |
3 files changed, 35 insertions, 19 deletions
@@ -20,27 +20,21 @@ erlc_verbose = $(erlc_verbose_$(V)) gen_verbose_0 = @echo " GEN " $@; gen_verbose = $(gen_verbose_$(V)) -.PHONY: all clean-all app clean docs clean-docs tests autobahn build-plt dialyze +.PHONY: all clean-all app clean deps clean-deps docs clean-docs tests autobahn build-plt dialyze # Application. -all: app +all: deps app -clean-all: clean clean-docs +clean-all: clean clean-deps clean-docs $(gen_verbose) rm -rf .$(PROJECT).plt $(DEPS_DIR) logs -deps/ranch: - @mkdir -p $(DEPS_DIR) - git clone -n -- https://github.com/extend/ranch.git $(DEPS_DIR)/ranch - cd $(DEPS_DIR)/ranch ; git checkout -q $(RANCH_VSN) - MODULES = $(shell ls src/*.erl | sed 's/src\///;s/\.erl/,/' | sed '$$s/.$$//') -app: deps/ranch ebin/$(PROJECT).app +app: ebin/$(PROJECT).app $(appsrc_verbose) cat src/$(PROJECT).app.src \ | sed 's/{modules, \[\]}/{modules, \[$(MODULES)\]}/' \ > ebin/$(PROJECT).app - @$(MAKE) -C $(DEPS_DIR)/ranch ebin/$(PROJECT).app: src/*.erl @mkdir -p ebin/ @@ -48,9 +42,21 @@ ebin/$(PROJECT).app: src/*.erl src/$(PROJECT)_middleware.erl $? clean: - -@$(MAKE) -C $(DEPS_DIR)/ranch clean $(gen_verbose) rm -rf ebin/ test/*.beam erl_crash.dump +# Dependencies. + +$(DEPS_DIR)/ranch: + @mkdir -p $(DEPS_DIR) + git clone -n -- https://github.com/extend/ranch.git $(DEPS_DIR)/ranch + cd $(DEPS_DIR)/ranch ; git checkout -q $(RANCH_VSN) + +deps: $(DEPS_DIR)/ranch + @$(MAKE) -C $(DEPS_DIR)/ranch + +clean-deps: + -@$(MAKE) -C $(DEPS_DIR)/ranch clean + # Documentation. docs: clean-docs @@ -69,17 +75,17 @@ CT_RUN = ct_run \ -cover test/cover.spec tests: ERLC_OPTS += -DTEST=1 -tests: clean app +tests: clean clean-deps deps app @mkdir -p logs/ @$(CT_RUN) -suite eunit_SUITE http_SUITE ws_SUITE -autobahn: clean app +autobahn: clean clean-deps deps app @mkdir -p logs/ @$(CT_RUN) -suite autobahn_SUITE # Dialyzer. -build-plt: app +build-plt: deps app @dialyzer --build_plt --output_plt .$(PROJECT).plt \ --apps erts kernel stdlib crypto public_key ssl $(DEPS_DIR)/ranch diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl index 0745192..eb3a939 100644 --- a/src/cowboy_req.erl +++ b/src/cowboy_req.erl @@ -847,7 +847,7 @@ set_resp_body(Body, Req) -> %% Cowboy will add a "Transfer-Encoding: identity" header to the %% response. -spec set_resp_body_fun(resp_body_fun(), Req) -> Req when Req::req(). -set_resp_body_fun(StreamFun, Req) -> +set_resp_body_fun(StreamFun, Req) when is_function(StreamFun) -> Req#http_req{resp_body=StreamFun}. %% @doc Add a body function to the response. @@ -863,7 +863,8 @@ set_resp_body_fun(StreamFun, Req) -> %% fewer bytes than declared the behaviour is undefined. -spec set_resp_body_fun(non_neg_integer(), resp_body_fun(), Req) -> Req when Req::req(). -set_resp_body_fun(StreamLen, StreamFun, Req) -> +set_resp_body_fun(StreamLen, StreamFun, Req) + when is_integer(StreamLen), is_function(StreamFun) -> Req#http_req{resp_body={StreamLen, StreamFun}}. %% @doc Return whether the given header has been set for the response. diff --git a/src/cowboy_router.erl b/src/cowboy_router.erl index a4597ed..10db3f7 100644 --- a/src/cowboy_router.erl +++ b/src/cowboy_router.erl @@ -78,7 +78,7 @@ compile([{HostMatch, Constraints, Paths}|Tail], Acc) -> compile(Tail, Hosts ++ Acc). compile_host(HostMatch) when is_list(HostMatch) -> - compile_host(unicode:characters_to_binary(HostMatch)); + compile_host(list_to_binary(HostMatch)); compile_host(HostMatch) when is_binary(HostMatch) -> compile_rules(HostMatch, $., [], [], <<>>). @@ -88,7 +88,7 @@ compile_paths([{PathMatch, Handler, Opts}|Tail], Acc) -> compile_paths([{PathMatch, [], Handler, Opts}|Tail], Acc); compile_paths([{PathMatch, Constraints, Handler, Opts}|Tail], Acc) when is_list(PathMatch) -> - compile_paths([{unicode:characters_to_binary(PathMatch), + compile_paths([{list_to_binary(PathMatch), Constraints, Handler, Opts}|Tail], Acc); compile_paths([{'_', Constraints, Handler, Opts}|Tail], Acc) -> compile_paths(Tail, [{'_', Constraints, Handler, Opts}] ++ Acc); @@ -391,10 +391,14 @@ compile_test_() -> {[<<"path">>, <<"to">>, <<"resource">>], [], hb, ob}]}]}, {[{'_', [{"/path/to/resource/", h, o}]}], [{'_', [], [{[<<"path">>, <<"to">>, <<"resource">>], [], h, o}]}]}, + {[{'_', [{"/путь/к/ресурсу/", h, o}]}], + [{'_', [], [{[<<"путь">>, <<"к">>, <<"ресурсу">>], [], h, o}]}]}, {[{"cowboy.example.org.", [{'_', h, o}]}], [{[<<"org">>, <<"example">>, <<"cowboy">>], [], [{'_', [], h, o}]}]}, {[{".cowboy.example.org", [{'_', h, o}]}], [{[<<"org">>, <<"example">>, <<"cowboy">>], [], [{'_', [], h, o}]}]}, + {[{"некий.сайт.рф.", [{'_', h, o}]}], + [{[<<"рф">>, <<"сайт">>, <<"некий">>], [], [{'_', [], h, o}]}]}, {[{":subdomain.example.org", [{"/hats/:name/prices", h, o}]}], [{[<<"org">>, <<"example">>, subdomain], [], [ {[<<"hats">>, name, <<"prices">>], [], h, o}]}]}, @@ -502,6 +506,9 @@ match_info_test_() -> ]}, {[<<"eu">>, <<"ninenines">>, '...'], [], [ {'_', [], match_any, []} + ]}, + {[<<"рф">>, <<"сайт">>], [], [ + {[<<"путь">>, '...'], [], match_path, []} ]} ], Tests = [ @@ -516,7 +523,9 @@ match_info_test_() -> {<<"www.ninenines.eu">>, <<"/pathinfo/is/next/path_info">>, {ok, match_path, [], [], undefined, [<<"path_info">>]}}, {<<"www.ninenines.eu">>, <<"/pathinfo/is/next/foo/bar">>, - {ok, match_path, [], [], undefined, [<<"foo">>, <<"bar">>]}} + {ok, match_path, [], [], undefined, [<<"foo">>, <<"bar">>]}}, + {<<"сайт.рф">>, <<"/путь/домой">>, + {ok, match_path, [], [], undefined, [<<"домой">>]}} ], [{lists:flatten(io_lib:format("~p, ~p", [H, P])), fun() -> R = match(Dispatch, H, P) |