Skip to content

Commit

Permalink
merge develop to master
Browse files Browse the repository at this point in the history
Webmachine users are starting to use Erlang/OTP 17.0, which requires
changes to webmachine and its meck dependency. Merge the develop branch to
master to ensure all changes necessary for 17.0 are available there.
  • Loading branch information
vinoski committed May 28, 2014
2 parents f88b4de + 50c790d commit 26d04d8
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ deps/*
.eunit/*
ebin/*.app
doc/*
.local_dialyzer_plt
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -19,6 +19,10 @@ notifications:
webhooks: http://basho-engbot.herokuapp.com/travis?key=66724b424957d598311ba00bb2d137fcae4eae21
email: eng@basho.com
otp_release:
- R16B02
- R16B01
- R15B03
- R15B02
- R15B01
- R15B
- R14B04
Expand Down
28 changes: 2 additions & 26 deletions Makefile
Expand Up @@ -22,35 +22,11 @@ distclean: clean

edoc:
@$(ERL) -noshell -run edoc_run application '$(APP)' '"."' '[{preprocess, true},{includes, ["."]}]'

test: all
@(./rebar skip_deps=true eunit)

APPS = kernel stdlib sasl erts ssl tools os_mon runtime_tools crypto inets \
DIALYZER_APPS = kernel stdlib sasl erts ssl tools os_mon runtime_tools crypto inets \
xmerl webtool snmp public_key mnesia eunit syntax_tools compiler
COMBO_PLT = $(HOME)/.webmachine_dialyzer_plt

check_plt: compile
dialyzer --check_plt --plt $(COMBO_PLT) --apps $(APPS) ebin

build_plt: compile
dialyzer --build_plt --output_plt $(COMBO_PLT) --apps $(APPS) ebin

dialyzer: compile
@echo
@echo Use "'make check_plt'" to check PLT prior to using this target.
@echo Use "'make build_plt'" to build PLT prior to using this target.
@echo
@sleep 1
dialyzer -Wno_return --plt $(COMBO_PLT) ebin

cleanplt:
@echo
@echo "Are you sure? It takes about 1/2 hour to re-build."
@echo Deleting $(COMBO_PLT) in 5 seconds.
@ech
sleep 5
rm $(COMBO_PLT)
include tools.mk

verbosetest: all
@(./rebar -v skip_deps=true eunit)
Expand Down
Binary file modified rebar
Binary file not shown.
11 changes: 5 additions & 6 deletions rebar.config
Expand Up @@ -3,11 +3,10 @@
{cover_enabled, true}.
{edoc_opts, [{preprocess, true}]}.

{xref_checks, [undefined_function_calls]}.

{deps,
[{mochiweb, "1.5.1*", {git, "git://github.com/basho/mochiweb",
{tag, "1.5.1p6"}}},
{meck, "0.7.2", {git, "git://github.com/eproxus/meck.git",
{tag, "0.7.2-56-g8433cf2"}}},
{ibrowse, "4.0.1", {git, "git://github.com/cmullaparthi/ibrowse.git",
{tag, "v4.0.1"}}}
[{mochiweb, "1.5.1*", {git, "git://github.com/basho/mochiweb.git", {tag, "1.5.1p7"}}},
{meck, "0.8.2", {git, "git://github.com/basho/meck.git", {tag, "0.8.2"}}},
{ibrowse, "4.0.1", {git, "git://github.com/cmullaparthi/ibrowse.git", {tag, "v4.0.1"}}}
]}.
26 changes: 17 additions & 9 deletions rebar.config.script
@@ -1,11 +1,19 @@
case erlang:system_info(otp_release) =< "R15B01" of
true ->
HashDefine = [{d,old_hash}],
case lists:keysearch(erl_opts, 1, CONFIG) of
{value, {erl_opts, Opts}} ->
lists:keyreplace(erl_opts,1,CONFIG,{erl_opts,Opts++HashDefine});
false ->
CONFIG ++ [{erl_opts, HashDefine}]
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et

case erlang:system_info(otp_release) of
"R"++_=RVersion ->
case RVersion =< "R15B01" of
true ->
HashDefine = [{d,old_hash}],
case lists:keysearch(erl_opts, 1, CONFIG) of
{value, {erl_opts, Opts}} ->
lists:keyreplace(erl_opts,1,CONFIG,{erl_opts,Opts++HashDefine});
false ->
CONFIG ++ [{erl_opts, HashDefine}]
end;
false -> CONFIG
end;
false -> CONFIG
_ ->
CONFIG
end.
2 changes: 1 addition & 1 deletion src/webmachine.erl
Expand Up @@ -61,7 +61,7 @@ new_request(mochiweb, Request) ->
ReqData = wrq:set_sock(Sock,
wrq:set_peer(Peer,
ReqState#wm_reqstate.reqdata)),
LogData = #wm_log_data{start_time=now(),
LogData = #wm_log_data{start_time=os:timestamp(),
method=Method,
headers=Headers,
peer=Peer,
Expand Down
24 changes: 18 additions & 6 deletions src/webmachine_decision_core.erl
Expand Up @@ -63,7 +63,7 @@ respond(Code) when is_integer(Code) ->
respond({Code, undefined});
respond({_, _}=CodeAndPhrase) ->
Resource = get(resource),
EndTime = now(),
EndTime = os:timestamp(),
respond(CodeAndPhrase, Resource, EndTime).

respond({Code, _ReasonPhrase}=CodeAndPhrase, Resource, EndTime)
Expand Down Expand Up @@ -104,7 +104,7 @@ error_response(Reason) ->

error_response(Code, Reason) ->
Resource = get(resource),
EndTime = now(),
EndTime = os:timestamp(),
error_response({Code, undefined}, Reason, Resource, EndTime).

error_response({Code, _}=CodeAndPhrase, Resource, EndTime) ->
Expand All @@ -118,7 +118,7 @@ error_response({Code, _}=CodeAndPhrase, Reason, Resource, EndTime) ->
{ErrorHTML, ReqState} = ErrorHandler:render_error(
Code, {webmachine_request,get(reqstate)}, Reason),
put(reqstate, ReqState),
wrcall({set_resp_body, ErrorHTML}),
wrcall({set_resp_body, encode_body(ErrorHTML)}),
finish_response(CodeAndPhrase, Resource, EndTime).

decision_test(Test,TestVal,TrueFlow,FalseFlow) ->
Expand Down Expand Up @@ -631,11 +631,23 @@ encode_body(Body) ->
Charsetter =
case resource_call(charsets_provided) of
no_charset -> fun(X) -> X end;
CP -> hd([Fun || {CSet,Fun} <- CP, ChosenCSet =:= CSet])
CP ->
case [Fun || {CSet,Fun} <- CP, ChosenCSet =:= CSet] of
[] ->
fun(X) -> X end;
[F | _] ->
F
end
end,
ChosenEnc = wrcall({get_metadata, 'content-encoding'}),
Encoder = hd([Fun || {Enc,Fun} <- resource_call(encodings_provided),
ChosenEnc =:= Enc]),
Encoder =
case [Fun || {Enc,Fun} <- resource_call(encodings_provided),
ChosenEnc =:= Enc] of
[] ->
fun(X) -> X end;
[E | _] ->
E
end,
case Body of
{stream, StreamBody} ->
{stream, make_encoder_stream(Encoder, Charsetter, StreamBody)};
Expand Down
4 changes: 3 additions & 1 deletion src/webmachine_error_log_handler.erl
Expand Up @@ -109,4 +109,6 @@ format_req(error, 503, Req, _) ->
["[error] ", Reason, ": path=", Path, $\n];
format_req(error, _Code, Req, Reason) ->
{Path, _} = Req:path(),
["[error] path=", Path, $\x20, Reason, $\n].
Str = io_lib:format("~p", [Reason]),
["[error] path=", Path, $\x20, Str, $\n].

8 changes: 4 additions & 4 deletions src/webmachine_request.erl
@@ -1,6 +1,6 @@
%% @author Justin Sheehy <justin@basho.com>
%% @author Andy Gross <andy@basho.com>
%% @copyright 2007-2012 Basho Technologies
%% @copyright 2007-2014 Basho Technologies
%% Based on mochiweb_request.erl, which is Copyright 2007 Mochi Media, Inc.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -100,8 +100,8 @@
-include("wm_reqstate.hrl").
-include("wm_reqdata.hrl").

-define(WMVSN, "1.10.0").
-define(QUIP, "never breaks eye contact").
-define(WMVSN, "1.10.6").
-define(QUIP, "no drinks").
-define(IDLE_TIMEOUT, infinity).

new(#wm_reqstate{}=ReqState) ->
Expand Down Expand Up @@ -271,7 +271,7 @@ call({send_response, {Code, ReasonPhrase}=CodeAndReason}, Req) when is_integer(C
send_response(CodeAndReason, Req)
end,
LogData = NewState#wm_reqstate.log_data,
NewLogData = LogData#wm_log_data{finish_time=now()},
NewLogData = LogData#wm_log_data{finish_time=os:timestamp()},
{Reply, NewState#wm_reqstate{log_data=NewLogData}};
call(resp_body, {?MODULE, ReqState}) ->
{wrq:resp_body(ReqState#wm_reqstate.reqdata), ReqState};
Expand Down
2 changes: 1 addition & 1 deletion src/webmachine_resource.erl
Expand Up @@ -246,7 +246,7 @@ log_decision(File, DecisionID) ->
io:format(File, "{decision, ~p}.~n", [DecisionID]).

open_log_file(Dir, Mod) ->
Now = {_,_,US} = now(),
Now = {_,_,US} = os:timestamp(),
{{Y,M,D},{H,I,S}} = calendar:now_to_universal_time(Now),
Filename = io_lib:format(
"~s/~p-~4..0B-~2..0B-~2..0B"
Expand Down
2 changes: 1 addition & 1 deletion src/webmachine_router.erl
Expand Up @@ -107,7 +107,7 @@ get_routes() ->
get_routes(Name) ->
get_dispatch_list(Name).

%% @spec init_routes() -> ok
%% @spec init_routes([hostmatchterm() | pathmatchterm()]) -> ok
%% @doc Set the default routes, unless the routing table isn't empty.
init_routes(DefaultRoutes) ->
init_routes(default, DefaultRoutes).
Expand Down
12 changes: 12 additions & 0 deletions src/webmachine_util.erl
Expand Up @@ -390,6 +390,8 @@ now_diff_milliseconds({M,S,U}, {M1,S1,U1}) ->
parse_range(RawRange, ResourceLength) when is_list(RawRange) ->
parse_range(mochiweb_http:parse_range_request(RawRange), ResourceLength, []).

parse_range(fail, _ResourceLength, _Acc) ->
[];
parse_range([], _ResourceLength, Acc) ->
lists:reverse(Acc);
parse_range([Spec | Rest], ResourceLength, Acc) ->
Expand Down Expand Up @@ -499,6 +501,16 @@ now_diff_milliseconds_test() ->
?assertEqual(1000, now_diff_milliseconds(Late, Early1)),
?assertEqual(1000001000, now_diff_milliseconds(Late, Early2)).

parse_range_test() ->
ValidRange = "bytes=1-2",
InvalidRange = "bytes=2-1",
EmptyRange = "bytes=",
UnparsableRange = "bytes=foo",
?assertEqual([{1,2}], parse_range(ValidRange, 10)),
?assertEqual([], parse_range(InvalidRange, 10)),
?assertEqual([], parse_range(EmptyRange, 10)),
?assertEqual([], parse_range(UnparsableRange, 10)).

-ifdef(EQC).

-define(QC_OUT(P),
Expand Down
20 changes: 14 additions & 6 deletions test/decision_core_test.erl
Expand Up @@ -27,6 +27,14 @@
-define(HTML_CONTENT, "<html><body>Foo</body></html>").
-define(TEXT_CONTENT, ?HTML_CONTENT).

-ifndef(old_hash).
md5(Bin) ->
crypto:hash(md5,Bin).
-else.
md5(Bin) ->
crypto:md5(Bin).
-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 @@ -642,7 +650,7 @@ content_md5_valid_b9a() ->
ContentType = "text/plain",
put_setting(content_types_accepted, [{ContentType, to_html}]),
Body = "foo",
MD5Sum = base64:encode_to_string(crypto:md5(Body)),
MD5Sum = base64:encode_to_string(md5(Body)),
Headers = [{"Content-MD5", MD5Sum}],
PutRequest = {url("new"), Headers, ContentType, Body},
{ok, Result} = httpc:request(put, PutRequest, [], []),
Expand All @@ -659,7 +667,7 @@ content_md5_valid_b9a_validated() ->
ContentType = "text/plain",
put_setting(content_types_accepted, [{ContentType, to_html}]),
Body = "foo",
MD5Sum = base64:encode_to_string(crypto:md5(Body)),
MD5Sum = base64:encode_to_string(md5(Body)),
Headers = [{"Content-MD5", MD5Sum}],
PutRequest = {url("new"), Headers, ContentType, Body},
{ok, Result} = httpc:request(put, PutRequest, [], []),
Expand Down Expand Up @@ -886,7 +894,7 @@ see_other_n11() ->
put_setting(content_types_accepted, [{ContentType, to_html}]),
put_setting(process_post, {set_resp_redirect, ?RESOURCE_PATH ++ "/new1"}),
PostRequest = {url("post"), [], ContentType, "foo"},
{ok, Result} = httpc:request(post, PostRequest, [], []),
{ok, Result} = httpc:request(post, PostRequest, [{autoredirect,false}], []),
?assertMatch({{"HTTP/1.1", 303, "See Other"}, _, _}, Result),
ExpectedDecisionTrace = ?PATH_TO_N11_VIA_M7_NO_ACPTHEAD,
?assertEqual(ExpectedDecisionTrace, get_decision_ids()),
Expand Down Expand Up @@ -933,7 +941,7 @@ see_other_n11_resource_calls_base_uri(Value) ->
put_setting(create_path, {set_resp_redirect, ?RESOURCE_PATH ++ "/new1"}),
put_setting(base_uri, Value),
PostRequest = {url("post"), [], ContentType, "foo"},
{ok, Result} = httpc:request(post, PostRequest, [], []),
{ok, Result} = httpc:request(post, PostRequest, [{autoredirect,false}], []),
?assertMatch({{"HTTP/1.1", 303, "See Other"}, _, _}, Result),
ExpectedDecisionTrace = ?PATH_TO_N11_VIA_M7_NO_ACPTHEAD,
?assertEqual(ExpectedDecisionTrace, get_decision_ids()),
Expand All @@ -949,7 +957,7 @@ see_other_n5() ->
put_setting(allow_missing_post, true),
put_setting(process_post, {set_resp_redirect, ?RESOURCE_PATH ++ "/new1"}),
PostRequest = {url("post"), [], ContentType, "foo"},
{ok, Result} = httpc:request(post, PostRequest, [], []),
{ok, Result} = httpc:request(post, PostRequest, [{autoredirect,false}], []),
?assertMatch({{"HTTP/1.1", 303, "See Other"}, _, _}, Result),
ExpectedDecisionTrace = ?PATH_TO_N11_VIA_N5_NO_ACPTHEAD,
?assertEqual(ExpectedDecisionTrace, get_decision_ids()),
Expand Down Expand Up @@ -1237,7 +1245,7 @@ stream_content_md5() ->
put_setting(allow_missing_post, true),
ContentType = "text/plain",
Content = "foo",
ValidMD5Sum = base64:encode_to_string(crypto:md5(Content)),
ValidMD5Sum = base64:encode_to_string(md5(Content)),
ibrowse:start(),
Url = url("post"),
Headers = [{"Content-Type", ContentType},
Expand Down
48 changes: 48 additions & 0 deletions tools.mk
@@ -0,0 +1,48 @@
test: compile
./rebar eunit skip_deps=true

docs:
./rebar doc skip_deps=true

xref: compile
./rebar xref skip_deps=true

PLT ?= $(HOME)/.riak_combo_dialyzer_plt
LOCAL_PLT = .local_dialyzer_plt
DIALYZER_FLAGS ?= -Wunmatched_returns

${PLT}: compile
ifneq (,$(wildcard $(PLT)))
dialyzer --check_plt --plt $(PLT) --apps $(DIALYZER_APPS) && \
dialyzer --add_to_plt --plt $(PLT) --output_plt $(PLT) --apps $(DIALYZER_APPS) ; test $$? -ne 1
else
dialyzer --build_plt --output_plt $(PLT) --apps $(DIALYZER_APPS); test $$? -ne 1
endif

${LOCAL_PLT}: compile
ifneq (,$(wildcard deps/*))
ifneq (,$(wildcard $(LOCAL_PLT)))
dialyzer --check_plt --plt $(LOCAL_PLT) deps/*/ebin && \
dialyzer --add_to_plt --plt $(LOCAL_PLT) --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1
else
dialyzer --build_plt --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1
endif
endif

dialyzer: ${PLT} ${LOCAL_PLT}
@echo "==> $(shell basename $(shell pwd)) (dialyzer)"
@if [ -f $(LOCAL_PLT) ]; then \
dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin; \
else \
dialyzer $(DIALYZER_FLAGS) --plts $(PLT) -c ebin; \
fi

cleanplt:
@echo
@echo "Are you sure? It takes several minutes to re-build."
@echo Deleting $(PLT) and $(LOCAL_PLT) in 5 seconds.
@echo
sleep 5
rm $(PLT)
rm $(LOCAL_PLT)

0 comments on commit 26d04d8

Please sign in to comment.