-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP OS Env Var to choose cowboy version
- default is cowboy 2.x - to use 1.x $COWBOY_VERSION needs to be set to a value starting with "1" (same method as Elixir Plug) - no runtime detection of available cowboy version
- Loading branch information
1 parent
2d68421
commit aa6f487
Showing
8 changed files
with
98 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{deps, | ||
[{cowboy, "1.1.2"}, | ||
[{cowboy, "~> 2.0.0"}, | ||
{lager, "3.2.4"}, | ||
{jsone, "1.3.1"} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
case os:getenv("COWBOY_VERSION") of | ||
"1" ++ _ -> | ||
ErlOpts = proplists:get_value(erl_opts, CONFIG, []), | ||
NewErlOpts = {erl_opts, [{d, 'COWBOY_VERSION_1'}|ErlOpts]}, | ||
Config2 = lists:keystore(erl_opts, 1, CONFIG, NewErlOpts), | ||
|
||
Deps = proplists:get_value(deps, CONFIG, []), | ||
NewDeps = {deps, lists:keystore(cowboy, 1, Deps, {cowboy, "1.1.2"})}, | ||
lists:keystore(deps, 1, Config2, NewDeps); | ||
_ -> | ||
CONFIG | ||
end. | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
%%% @doc Cowboy 2.x compatible HTTP handler | ||
-module(xprof_gui_cowboy2_handler). | ||
|
||
-ifndef(COWBOY_VERSION_1). | ||
|
||
-behavior(cowboy_handler). | ||
|
||
%% xprof_gui_app callback | ||
-export([start_listener/3]). | ||
|
||
%% Cowboy 2.x callback | ||
-export([init/2]). | ||
|
||
-define(HDR_JSON, #{<<"content-type">> => <<"application/json">>}). | ||
|
||
%% In case an XHR receives no content with no content-type Firefox will emit | ||
%% the following error: "XML Parsing Error: no root element found..." | ||
%% As a workaround always return a content-type of octet-stream with | ||
%% 204 No Content responses | ||
-define(HDR_NO_CONTENT, #{<<"content-type">> => <<"application/octet-stream">>}). | ||
|
||
%% xprof_gui_app callback | ||
|
||
start_listener(Name, Port, Dispatch) -> | ||
cowboy:start_clear(Name, [{port, Port}], | ||
#{env => #{dispatch => Dispatch}}). | ||
|
||
%% Cowboy 2.x callback | ||
|
||
init(Req0, State) -> | ||
What = cowboy_req:binding(what, Req0), | ||
Params = cowboy_req:parse_qs(Req0), | ||
Req = | ||
case xprof_gui_rest:handle_req(What, Params) of | ||
{StatusCode, Json} when is_integer(StatusCode), is_binary(Json) -> | ||
cowboy_req:reply(StatusCode, ?HDR_JSON, Json, Req0); | ||
StatusCode when is_integer(StatusCode) -> | ||
cowboy_req:reply(StatusCode, ?HDR_NO_CONTENT, Req0) | ||
end, | ||
{ok, Req, State}. | ||
|
||
-endif. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
case os:getenv("TRAVIS") of | ||
"true" -> | ||
JobId = os:getenv("TRAVIS_JOB_ID"), | ||
JobId = os:getenv("TRAVIS_JOB_ID"), | ||
lists:keystore(coveralls_service_job_id, 1, CONFIG, {coveralls_service_job_id, JobId}); | ||
|
||
_ -> | ||
CONFIG | ||
end. | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
{"1.1.0", | ||
[{<<"cowboy">>,{pkg,<<"cowboy">>,<<"1.1.2">>},0}, | ||
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"1.0.2">>},1}, | ||
[{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.0.0">>},0}, | ||
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.0.1">>},1}, | ||
{<<"customized_hdr_histogram">>, | ||
{pkg,<<"customized_hdr_histogram">>,<<"0.3.2">>}, | ||
0}, | ||
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1}, | ||
{<<"jsone">>,{pkg,<<"jsone">>,<<"1.3.1">>},0}, | ||
{<<"lager">>,{pkg,<<"lager">>,<<"3.2.4">>},0}, | ||
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.3.2">>},1}]}. | ||
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.4.0">>},1}]}. | ||
[ | ||
{pkg_hash,[ | ||
{<<"cowboy">>, <<"61AC29EA970389A88ECA5A65601460162D370A70018AFE6F949A29DCA91F3BB0">>}, | ||
{<<"cowlib">>, <<"9D769A1D062C9C3AC753096F868CA121E2730B9A377DE23DEC0F7E08B1DF84EE">>}, | ||
{<<"cowboy">>, <<"A3B680BCC1156C6FBCB398CC56ADC35177037012D7DC28D8F7E7926D6C243561">>}, | ||
{<<"cowlib">>, <<"4DFFFB1DB296EAB9F2E8B95EE3017007F674BC920CE30AEB5A53BBDA82FC38C0">>}, | ||
{<<"customized_hdr_histogram">>, <<"14DDAE316FB694455FCC20CBD1AD5F057E421132E562AFB93BD81EDA44BD937D">>}, | ||
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>}, | ||
{<<"jsone">>, <<"133BE761810EC0E94E05D4156944FFC35D02D6A88FA8FDFC2AF29BA53EADB377">>}, | ||
{<<"lager">>, <<"A6DEB74DAE7927F46BD13255268308EF03EB206EC784A94EAF7C1C0F3B811615">>}, | ||
{<<"ranch">>, <<"E4965A144DC9FBE70E5C077C65E73C57165416A901BD02EA899CFD95AA890986">>}]} | ||
{<<"ranch">>, <<"10272F95DA79340FA7E8774BA7930B901713D272905D0012B06CA6D994F8826B">>}]} | ||
]. |