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

remove lager as a dependency #125

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@
{root_dir, "/home/joe/dev/joedevivo/euc2015"}
]}

]},
{lager, [
{handlers, [
{lager_console_backend, debug}
]}
]}
].
10 changes: 4 additions & 6 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
{erl_opts, [
%% Until the inevitable gen_statem migration
%% warnings_as_errors,
{parse_transform, lager_transform},
warnings_as_errors,
debug_info
]}.

{deps,
[lager,
{hpack, {pkg, hpack_erl}}]}.
[{hpack, {pkg, hpack_erl}}]}.

{cover_enabled, true}.

Expand All @@ -23,7 +20,8 @@
{test, [
{erl_opts,
[
{i,["include"]}
{i,["include"]},
nowarn_export_all
]},
{deps,
[{ranch, "1.2.1"}]}
Expand Down
1 change: 0 additions & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ case erlang:function_exported(rebar3, main, 1) of
%% Rebuild deps, possibly including those that have been moved to
%% profiles
[{deps, [
{lager, ".*", {git, "https://github.com/basho/lager.git", {tag, "3.2.4"}}},
{hpack, ".*", {git, "https://github.com/joedevivo/hpack.git", {tag, "0.2.3"}}}
]} | lists:keydelete(deps, 1, CONFIG)]
end.
8 changes: 2 additions & 6 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{"1.1.0",
[{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},0},
{<<"lager">>,{pkg,<<"lager">>,<<"3.2.4">>},0}]}.
[{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},0}]}.
[
{pkg_hash,[
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
{<<"hpack">>, <<"17670F83FF984AE6CD74B1C456EDDE906D27FF013740EE4D9EFAA4F1BF999633">>},
{<<"lager">>, <<"A6DEB74DAE7927F46BD13255268308EF03EB206EC784A94EAF7C1C0F3B811615">>}]}
{<<"hpack">>, <<"17670F83FF984AE6CD74B1C456EDDE906D27FF013740EE4D9EFAA4F1BF999633">>}]}
].
3 changes: 1 addition & 2 deletions src/chatterbox.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
crypto,
public_key,
ssl,
hpack,
lager
hpack
]},
{env,
[
Expand Down
3 changes: 1 addition & 2 deletions src/chatterbox_ranch_protocol.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ transport(gen_tcp) ->
gen_tcp;
transport(ssl) ->
ssl;
transport(Other) ->
lager:error("chatterbox_ranch_protocol doesn't support ~p", [Other]),
transport(_Other) ->
error(unknown_protocol).
9 changes: 1 addition & 8 deletions src/chatterbox_static_content_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ spawn_handle(Pid, StreamId, Headers, ReqBody) ->
iodata()
) -> ok.
handle(ConnPid, StreamId, Headers, _ReqBody) ->
lager:debug("handle(~p, ~p, ~p, _)", [ConnPid, StreamId, Headers]),
Path = binary_to_list(proplists:get_value(<<":path">>, Headers)),

%% QueryString Hack?
Expand Down Expand Up @@ -54,8 +53,6 @@ handle(ConnPid, StreamId, Headers, _ReqBody) ->
%% TODO: Logic about "/" vs "index.html", "index.htm", etc...
%% Directory browsing?
File = RootDir ++ Path4,
lager:debug("[chatterbox_static_content_handler] serving ~p on stream ~p", [File, StreamId]),
%%lager:info("Request Headers: ~p", [Headers]),

case {filelib:is_file(File), filelib:is_dir(File)} of
{_, true} ->
Expand Down Expand Up @@ -96,8 +93,6 @@ handle(ConnPid, StreamId, Headers, _ReqBody) ->
_ -> []
end,

lager:debug("Resources to push: ~p", [Resources]),

NewStreams =
lists:foldl(fun(R, Acc) ->
NewStreamId = h2_connection:new_stream(ConnPid),
Expand All @@ -110,9 +105,7 @@ handle(ConnPid, StreamId, Headers, _ReqBody) ->
Resources
),

lager:debug("New Streams for promises: ~p", [NewStreams]),

[spawn_handle(ConnPid, NewStreamId, PHeaders, <<>>) || {NewStreamId, PHeaders} <- NewStreams],
[spawn_handle(ConnPid, NewStreamId, PHeaders, <<>>) || {NewStreamId, PHeaders} <- NewStreams],

ok;
_ ->
Expand Down
36 changes: 13 additions & 23 deletions src/chatterbox_static_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@ init(ConnPid, StreamId, _) ->
stream_id=StreamId}}.

on_receive_request_headers(Headers, State) ->
lager:info("on_receive_request_headers(~p, ~p)", [Headers, State]),
{ok, State#cb_static{req_headers=Headers}}.

on_send_push_promise(Headers, State) ->
lager:info("on_send_push_promise(~p, ~p)", [Headers, State]),
{ok, State#cb_static{req_headers=Headers}}.

on_receive_request_data(Bin, State)->
lager:info("on_receive_request_data(~p, ~p)", [Bin, State]),
on_receive_request_data(_Bin, State)->
{ok, State}.

on_request_end_stream(State=#cb_static{connection_pid=ConnPid,
stream_id=StreamId}) ->
lager:info("on_request_end_stream(~p)", [State]),
Headers = State#cb_static.req_headers,

Method = proplists:get_value(<<":method">>, Headers),
Expand Down Expand Up @@ -69,9 +65,6 @@ on_request_end_stream(State=#cb_static{connection_pid=ConnPid,
%% TODO: Logic about "/" vs "index.html", "index.htm", etc...
%% Directory browsing?
File = RootDir ++ Path4,
lager:debug("[chatterbox_static_stream] ~p serving ~p on stream ~p", [self(), File, StreamId]),
%%lager:info("Request Headers: ~p", [Headers]),

{HeadersToSend, BodyToSend} =
case {filelib:is_file(File), filelib:is_dir(File)} of
{_, true} ->
Expand Down Expand Up @@ -106,21 +99,18 @@ on_request_end_stream(State=#cb_static{connection_pid=ConnPid,
[dot_hack(lists:last(M)) || M <- Matches];
_ -> []
end,
lager:debug("Resources to push: ~p", [Resources]),

NewStreams =
lists:foldl(
fun(R, Acc) ->
NewStreamId = h2_connection:new_stream(ConnPid),
PHeaders = generate_push_promise_headers(Headers, <<$/,R/binary>>
),
h2_connection:send_promise(ConnPid, StreamId, NewStreamId, PHeaders),
[{NewStreamId, PHeaders}|Acc]
end,
[],
Resources
),
lager:debug("New Streams for promises: ~p", [NewStreams]),

lists:foldl(
fun(R, Acc) ->
NewStreamId = h2_connection:new_stream(ConnPid),
PHeaders = generate_push_promise_headers(Headers, <<$/,R/binary>>
),
h2_connection:send_promise(ConnPid, StreamId, NewStreamId, PHeaders),
[{NewStreamId, PHeaders}|Acc]
end,
[],
Resources
),
ok;
_ ->
ok
Expand Down
Loading