Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
29952ac
Eliminate use of module_info to check whether a module exports a func…
Nov 28, 2017
21d0c05
Make webmachine_mochiweb loop call use latest version of module
Nov 29, 2017
93797cc
Merge pull request #286 from richcarl/avoid-module-info
seancribbs Dec 7, 2017
9c9bd3a
Merge pull request #287 from richcarl/mochiweb-loop-upgrade
seancribbs Dec 11, 2017
b774aea
Replace -compile(export_all) with -export([...]).
Apr 5, 2018
0dfb031
Upgrade to mochiweb-2.17.0 and ibrowse-v4.4.0.
Apr 5, 2018
c86cc77
Add Erlang 20.0 to the otp_releases to be tested against.
Apr 5, 2018
5546d5a
Revert ibrowse version. Will that fix Travis?
Apr 5, 2018
d042c5c
Reinstate new ibrowse version.
Apr 5, 2018
c6c2f2d
Merge pull request #292 from PhilRunninger/upgrade_mochiweb_dependency
seancribbs Apr 6, 2018
f0807c9
Fix compilation on OTP 21 by suppressing warnings about stacktraces
tazjin Jul 15, 2018
7339f8c
Add Erlang/OTP 21 to the list of releases to build against
tazjin Jul 15, 2018
e75b766
Merge pull request #294 from tazjin/master
seancribbs Jul 16, 2018
4c2009d
Add shim for OTP 21 stacktrace catch patterns.
seancribbs Jul 24, 2018
c426b0e
Call module directly instead of relying on tuple/pmod.
seancribbs Jul 24, 2018
78838cd
Merge pull request #295 from webmachine/sdc/otp21
seancribbs Sep 9, 2018
885f5fb
Version bump
seancribbs Sep 9, 2018
92225b8
Make available on hexpm
seancribbs Sep 9, 2018
d7475f2
[SUSTAIN-663] Update Content-Length in header only if the response is…
PrajaktaPurohit Oct 9, 2017
fa7c802
Merge pull request #285 from chef/praj/SUSTAIN-663/no_content_length
seancribbs Oct 1, 2018
fd19fa0
Fixed type referenc in wm_reqdata.hrl: webmachine_headers:headers() -…
aherranz Feb 4, 2019
f2f48e4
Merge pull request #298 from coowry/1.11.1+fix_webmachine_headers_hea…
seancribbs Feb 4, 2019
63a4a22
Use correct date for L17 test
eproxus Oct 31, 2019
691b208
Update mochiweb dependency to git
samwar Jan 30, 2020
41fc382
Merge pull request #302 from samwar/master
seancribbs Jan 31, 2020
a93d85b
Merge pull request #300 from stritzinger/bugfix/fix-l17-test
seancribbs Jan 31, 2020
7da44ab
webmachine_mochiweb: change LoopFun to an {M,F,As} tuple
mikpe Apr 8, 2020
c208797
webmachine_mochiweb: loop/2: swap parameter order; loop2/2: replace w…
mikpe Apr 9, 2020
518c94d
Merge pull request #306 from mikpe/dont-store-local-fun-in-mochiweb-o…
seancribbs Apr 10, 2020
9e0093d
Update crypto md5 to erlang:md5 to support FIPS
PrajaktaPurohit Mar 19, 2020
d626d7e
Update using erlang md5 instead of crypto md5 to support FIPS. Delete…
PrajaktaPurohit Mar 20, 2020
543b18a
rebar script was used only to define if the version of erlang was old…
PrajaktaPurohit Mar 20, 2020
4741523
updates for erlang 21+
lbakerchef Dec 18, 2019
d7b5a10
fix get_stacktrace deprecations
lbakerchef Jul 30, 2020
fb388a0
Merge branch 'master' into praj/rebase_with_upstream
PrajaktaPurohit Aug 11, 2020
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.
4 changes: 2 additions & 2 deletions include/wm_reqdata.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
| defined_in_create,
req_qs = defined_in_create :: [{string(), string()}]
| defined_in_create,
req_headers :: webmachine_headers:headers(),
req_headers :: webmachine:headers(),
req_body=not_fetched_yet,
resp_redirect = false :: boolean(),
resp_headers = webmachine_headers:empty() :: webmachine_headers:headers(),
resp_headers = webmachine_headers:empty() :: webmachine:headers(),
resp_body = <<>> :: webmachine:response_body(),
%% follow_request : range responce for range request, normal responce for non-range one
%% ignore_request : normal resopnse for either range reuqest or non-range one
Expand Down
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}).
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
7 changes: 7 additions & 0 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 <bryan@basho.com>').
-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 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.
8 changes: 3 additions & 5 deletions 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 = {?MODULE, loop, [DGroup]},
mochiweb_http:start([{name, MochiName}, {loop, LoopFun} | OtherOptions]).

stop() ->
Expand All @@ -74,10 +74,8 @@ stop() ->
stop(Name) ->
mochiweb_http:stop(Name).

-spec loop(any(),
mochiweb_request()) ->
ok.
loop(Name, MochiReq) ->
-spec loop(mochiweb_request(), any()) -> ok.
loop(MochiReq, Name) ->
case new_webmachine_req(MochiReq) of
{{error, NewRequestError}, ErrorReq} ->
handle_error(500, {error, NewRequestError}, ErrorReq);
Expand Down
33 changes: 21 additions & 12 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 <justin@basho.com>').
-author('Andy Gross <andy@basho.com>').
-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:Stacktrace ->
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
21 changes: 18 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 Down Expand Up @@ -883,10 +893,15 @@ not_modified_j18_via_h12() ->

%% 304 result via L17
not_modified_l17() ->
% Because httpd_util:rfc1123_date converts the date to GMT, it is offset by
% the local time zone. To get a Last-Modified date equal to the
% If-Modified-Since date we must convert it back from the RFC 1123 format.
% This avoids the test case failing in any time zone "east" of GMT :-P
RFC1123LastYear = httpd_util:rfc1123_date(?FIRST_DAY_OF_LAST_YEAR),
DateTimeLastYear = httpd_util:convert_request_date(RFC1123LastYear),
put_setting(allowed_methods, ?DEFAULT_ALLOWED_METHODS),
put_setting(last_modified, ?FIRST_DAY_OF_LAST_YEAR),
put_setting(last_modified, DateTimeLastYear),
put_setting(expires, ?FIRST_DAY_OF_NEXT_YEAR),
RFC1123LastYear = httpd_util:rfc1123_date(?FIRST_DAY_OF_LAST_YEAR),
Headers = [{"If-Modified-Since", RFC1123LastYear}],
{ok, Result} = httpc:request(get, {url(), Headers}, [], []),
?assertMatch({{"HTTP/1.1", 304, "Not Modified"}, _, _}, Result),
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