Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ma/merge upstream #6

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ language: erlang
sudo: false
install: "true" # don't let travis run get-deps
otp_release:
- 21.0
- 20.0
- 19.1
- 18.3
- 17.5
Expand Down
7 changes: 7 additions & 0 deletions include/wm_compat.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-ifndef(deprecate_stacktrace).
-define(STPATTERN(Pattern), Pattern).
-define(STACKTRACE, erlang:get_stacktrace()).
-else.
-define(STPATTERN(Pattern), Pattern:__STACKTRACE).
-define(STACKTRACE, __STACKTRACE).
-endif.
2 changes: 1 addition & 1 deletion include/wm_resource.hrl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-record(wm_resource, {module, modstate, modexports, trace}).
-record(wm_resource, {module, modstate, trace}).
5 changes: 2 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{xref_checks, [undefined_function_calls]}.

{deps, [{mochiweb, "2.12.2"}]}.
{deps, [{mochiweb, "2.18.0"}]}.

{eunit_opts, [
no_tty,
Expand All @@ -15,8 +15,7 @@
{profiles,
[{test,
[{deps, [meck,
{ibrowse, {git, "git://github.com/cmullaparthi/ibrowse.git", {tag, "v4.0.2"}}},
{eunit_formatters, {git, "git://github.com/seancribbs/eunit_formatters", {branch, "master"}}}
{ibrowse, "4.4.0"}
]},
{erl_opts, [debug_info]}
]}
Expand Down
13 changes: 12 additions & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ Config1 = case hd(OtpVersion) =:= $R andalso OtpVersion < "R15B02" of
CONFIG ++ [{erl_opts, HashDefine}]
end;
false -> CONFIG
end.
end,
if
OtpVersion >= "21" ->
case lists:keysearch(erl_opts, 1, Config1) of
{value, {erl_opts, Opts2}} ->
lists:keyreplace(erl_opts, 1, Config1, {erl_opts, [{d, deprecate_stacktrace}|Opts2]});
false ->
[{erl_opts, [{d, deprecate_stacktrace}]}|Config1]
end;
true ->
Config1
end.
4 changes: 2 additions & 2 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"1.1.0",
[{<<"mochiweb">>,{pkg,<<"mochiweb">>,<<"2.12.2">>},0}]}.
[{<<"mochiweb">>,{pkg,<<"mochiweb">>,<<"2.18.0">>},0}]}.
[
{pkg_hash,[
{<<"mochiweb">>, <<"80804AD342AFA3D7F3524040D4EED66CE74B17A555DE454AC85B07C479928E46">>}]}
{<<"mochiweb">>, <<"EB55F1DB3E6E960FAC4E6DB4E2DB9EC3602CC9F30B86CD1481D56545C3145D2E">>}]}
].
2 changes: 1 addition & 1 deletion src/webmachine.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
%% string() for the "Server" response header
]},

{contributors,["Sean Cribbs", "Joe DeVivo" "Bryan Fink",
{maintainers,["Sean Cribbs", "Joe DeVivo", "Bryan Fink",
"Kelly McLaughlin", "Jared Morrow", "Andy Gross",
"Steve Vinoski"]},
{licenses,["Apache"]},
Expand Down
2 changes: 1 addition & 1 deletion src/webmachine_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

-include("webmachine_logger.hrl").

-define(QUIP, "cafe not found").
-define(QUIP, "greased slide to failure").

%% @spec start(_Type, _StartArgs) -> ServerRet
%% @doc application start callback for webmachine.
Expand Down
11 changes: 9 additions & 2 deletions src/webmachine_decision_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
-author('Bryan Fink <[email protected]>').
-export([handle_request/2]).
-include("webmachine_logger.hrl").
-include("wm_compat.hrl").

%% Suppress Erlang/OTP 21 warnings about the new method to retrieve
%% stacktraces.
-ifdef(OTP_RELEASE).
-compile({nowarn_deprecated_function, [{erlang, get_stacktrace, 0}]}).
-endif.

handle_request(Resource, ReqState) ->
_ = [erase(X) || X <- [decision, code, req_body, bytes_written, tmp_reqstate]],
Expand All @@ -31,8 +38,8 @@ handle_request(Resource, ReqState) ->
try
d(v3b13)
catch
error:_ ->
error_response(erlang:get_stacktrace())
?STPATTERN(error:_Reason) ->
error_response(?STACKTRACE)
end.

wrcall(X) ->
Expand Down
2 changes: 1 addition & 1 deletion src/webmachine_dispatcher.erl
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ make_reqdata(Path) ->
MochiReq = mochiweb_request:new(testing, 'GET', Path, {1, 1},
mochiweb_headers:make([])),
Req = webmachine:new_request(mochiweb, MochiReq),
{RD, _} = Req:get_reqdata(),
{RD, _} = webmachine_request:get_reqdata(Req),
RD.

-endif.
2 changes: 1 addition & 1 deletion src/webmachine_mochiweb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ start(Options) ->
webmachine_router:init_routes(DGroup, DispatchList),
_ = [application_set_unless_env_or_undef(K, V) || {K, V} <- WMOptions],
MochiName = list_to_atom(to_list(PName) ++ "_mochiweb"),
LoopFun = fun(X) -> loop(DGroup, X) end,
LoopFun = fun(X) -> ?MODULE:loop(DGroup, X) end,
mochiweb_http:start([{name, MochiName}, {loop, LoopFun} | OtherOptions]).

stop() ->
Expand Down
37 changes: 23 additions & 14 deletions src/webmachine_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,33 @@
-module(webmachine_resource).
-author('Justin Sheehy <[email protected]>').
-author('Andy Gross <[email protected]>').
-export([new/4, wrap/2]).
-export([new/3, wrap/2]).
-export([do/3,log_d/2,stop/1]).

-include("wm_compat.hrl").
-include("wm_resource.hrl").
-include("wm_reqdata.hrl").
-include("wm_reqstate.hrl").

-type t() :: #wm_resource{}.
-export_type([t/0]).

new(R_Mod, R_ModState, R_ModExports, R_Trace) ->
-define(CALLBACK_ARITY, 2).

%% Suppress Erlang/OTP 21 warnings about the new method to retrieve
%% stacktraces.
-ifdef(OTP_RELEASE).
-compile({nowarn_deprecated_function, [{erlang, get_stacktrace, 0}]}).
-endif.

new(R_Mod, R_ModState, R_Trace) ->
case erlang:module_loaded(R_Mod) of
false -> code:ensure_loaded(R_Mod);
true -> ok
end,
#wm_resource{
module = R_Mod,
modstate = R_ModState,
modexports = R_ModExports,
trace = R_Trace
}.

Expand Down Expand Up @@ -118,15 +130,13 @@ default(_) ->
wrap(Mod, Args) ->
case Mod:init(Args) of
{ok, ModState} ->
{ok, webmachine_resource:new(Mod, ModState,
orddict:from_list(Mod:module_info(exports)), false)};
{ok, webmachine_resource:new(Mod, ModState, false)};
{{trace, Dir}, ModState} ->
{ok, File} = open_log_file(Dir, Mod),
log_decision(File, v3b14),
log_call(File, attempt, Mod, init, Args),
log_call(File, result, Mod, init, {{trace, Dir}, ModState}),
{ok, webmachine_resource:new(Mod, ModState,
orddict:from_list(Mod:module_info(exports)), File)};
{ok, webmachine_resource:new(Mod, ModState, File)};
_ ->
{stop, bad_init_arg}
end.
Expand All @@ -136,7 +146,6 @@ do(#wm_resource{}=Res, Fun, ReqProps) ->
do(Fun, ReqProps,
#wm_resource{
module=R_Mod,
modexports=R_ModExports,
trace=R_Trace
}=Req)
when is_atom(Fun) andalso is_list(ReqProps) ->
Expand All @@ -155,21 +164,20 @@ do(Fun, ReqProps,
%% Do not need the embedded state anymore
TrimData = ReqData#wm_reqdata{wm_state=undefined},
{Reply,
webmachine_resource:new(R_Mod, NewModState, R_ModExports, R_Trace),
webmachine_resource:new(R_Mod, NewModState, R_Trace),
ReqState#wm_reqstate{reqdata=TrimData}}.

handle_wm_call(Fun, ReqData,
#wm_resource{
module=R_Mod,
modstate=R_ModState,
modexports=R_ModExports,
trace=R_Trace
}=Req) ->
case default(Fun) of
no_default ->
resource_call(Fun, ReqData, Req);
Default ->
case orddict:is_key(Fun, R_ModExports) of
case erlang:function_exported(R_Mod, Fun, ?CALLBACK_ARITY) of
true ->
resource_call(Fun, ReqData, Req);
false ->
Expand Down Expand Up @@ -200,12 +208,13 @@ resource_call(F, ReqData,
_ -> log_call(R_Trace, attempt, R_Mod, F, [ReqData, R_ModState])
end,
Result = try
%% Note: the argument list must match the definition of CALLBACK_ARITY
apply(R_Mod, F, [ReqData, R_ModState])
catch C:R ->
Reason = {C, R, trim_trace(erlang:get_stacktrace())},
catch ?STPATTERN(C:R) ->
Reason = {C, R, trim_trace(?STACKTRACE)},
{{error, Reason}, ReqData, R_ModState}
end,
case R_Trace of
case R_Trace of
false -> nop;
_ -> log_call(R_Trace, result, R_Mod, F, Result)
end,
Expand Down
22 changes: 19 additions & 3 deletions test/decision_core_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@

-ifdef(TEST).

-include("wm_compat.hrl").
-include("wm_reqdata.hrl").
-include_lib("eunit/include/eunit.hrl").

-compile(export_all).
-export([size_stream_raises_error/2, process_post_for_created_p11/3, get_streamed_body/2, send_streamed_body/2,
accept_text/2, writer_response/2, known_length_body/2, range_response/2, stream_content_md5/0,
validate_checksum_for_md5stream/3, process_post_for_md5_stream/3, init/1, service_available/2,
validate_content_checksum/2, is_authorized/2, allowed_methods/2, known_methods/2, uri_too_long/2,
known_content_type/2, valid_entity_length/2, malformed_request/2, forbidden/2, valid_content_headers/2,
content_types_provided/2, content_types_accepted/2, language_available/2, charsets_provided/2,
encodings_provided/2, resource_exists/2, generate_etag/2, last_modified/2, moved_permanently/2,
moved_temporarily/2, previously_existed/2, allow_missing_post/2, post_is_create/2, process_post/2,
create_path/2, is_conflict/2, multiple_choices/2, base_uri/2, base_uri_add_slash/1, expires/2,
delete_resource/2, delete_completed/2, to_html/2]).

-define(RESOURCE, atom_to_list(?MODULE)).
-define(RESOURCE_PATH, "/" ++ ?RESOURCE).
Expand All @@ -35,6 +45,12 @@ md5(Bin) ->
crypto:md5(Bin).
-endif.

%% Suppress Erlang/OTP 21 warnings about the new method to retrieve
%% stacktraces.
-ifdef(OTP_RELEASE).
-compile({nowarn_deprecated_function, [{erlang, get_stacktrace, 0}]}).
-endif.

-define(HTTP_1_0_METHODS, ['GET', 'POST', 'HEAD']).
-define(HTTP_1_1_METHODS, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE',
'CONNECT', 'OPTIONS']).
Expand Down Expand Up @@ -320,8 +336,8 @@ setup() ->
meck:new(webmachine_resource, MeckOpts),
Ctx
catch
T:E ->
io:format(user, "~n~p : ~p : ~p", [T, E, erlang:get_stacktrace()]),
?STPATTERN(T:E) ->
io:format(user, "~n~p : ~p : ~p", [T, E, ?STACKTRACE]),
error(setup_failed)
end.

Expand Down
2 changes: 0 additions & 2 deletions test/wm_integration_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
-include_lib("eunit/include/eunit.hrl").
-include("webmachine.hrl").

-compile([export_all]).

integration_test_() ->
{foreach,
%% Setup
Expand Down