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

client stream callbacks #127

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ RequestHeaders = [

RequestBody = <<>>,

{ok, {ResponseHeaders, ResponseBody}}
{ok, {ResponseHeaders, ResponseBody, ResponseTrailers}}
= h2_client:sync_request(Pid, RequestHeaders, RequestBody).
```

Expand All @@ -125,7 +125,7 @@ So you can use a receive block, like this
```erlang
receive
{'END_STREAM', StreamId} ->
{ok, {ResponseHeaders, ResponseBody}} = h2_client:get_response(Pid, StreamId)
{ok, {ResponseHeaders, ResponseBody, ResponseTrailers}} = h2_client:get_response(Pid, StreamId)
end,
```

Expand Down
3 changes: 1 addition & 2 deletions src/chatterbox.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@
{server_max_header_list_size, unlimited},

{server_flow_control, auto}

]},

{maintainers, ["Joe DeVivo"]},
{pkg_name, ts_chatterbox},
{licenses, ["MIT"]},
{links, [{"Github", "https://github.com/joedevivo/chatterbox"}]}
]}.
Expand Down
138 changes: 0 additions & 138 deletions src/chatterbox_static_content_handler.erl

This file was deleted.

14 changes: 7 additions & 7 deletions src/chatterbox_static_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

-export([
init/3,
on_receive_request_headers/2,
on_receive_headers/2,
on_send_push_promise/2,
on_receive_request_data/2,
on_request_end_stream/1
on_receive_data/2,
on_end_stream/1
]).

-record(cb_static, {
Expand All @@ -23,16 +23,16 @@ init(ConnPid, StreamId, _) ->
{ok, #cb_static{connection_pid=ConnPid,
stream_id=StreamId}}.

on_receive_request_headers(Headers, State) ->
on_receive_headers(Headers, State) ->
{ok, State#cb_static{req_headers=Headers}}.

on_send_push_promise(Headers, State) ->
{ok, State#cb_static{req_headers=Headers}}.

on_receive_request_data(_Bin, State)->
on_receive_data(_Bin, State)->
{ok, State}.

on_request_end_stream(State=#cb_static{connection_pid=ConnPid,
on_end_stream(State=#cb_static{connection_pid=ConnPid,
stream_id=StreamId}) ->
Headers = State#cb_static.req_headers,

Expand Down Expand Up @@ -102,7 +102,7 @@ on_request_end_stream(State=#cb_static{connection_pid=ConnPid,

lists:foldl(
fun(R, Acc) ->
NewStreamId = h2_connection:new_stream(ConnPid),
{NewStreamId, _} = h2_connection:new_stream(ConnPid),
PHeaders = generate_push_promise_headers(Headers, <<$/,R/binary>>
),
h2_connection:send_promise(ConnPid, StreamId, NewStreamId, PHeaders),
Expand Down
12 changes: 8 additions & 4 deletions src/h2_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
start_link/2,
start_link/3,
start_link/4,
start_link/5,
start_ssl_upgrade_link/4,
stop/1,
send_request/3,
Expand Down Expand Up @@ -102,14 +103,17 @@ start_link(https, Host, SSLOptions)
| ignore
| {error, term()}.
start_link(Transport, Host, Port, SSLOptions) ->
start_link(Transport, Host, Port, SSLOptions, #{}).

start_link(Transport, Host, Port, SSLOptions, ConnectionSettings) ->
NewT = case Transport of
http -> gen_tcp;
https -> ssl
end,
h2_connection:start_client_link(NewT, Host, Port, SSLOptions, chatterbox:settings(client)).
h2_connection:start_client_link(NewT, Host, Port, SSLOptions, chatterbox:settings(client), ConnectionSettings).

start_ssl_upgrade_link(Host, Port, InitialMessage, SSLOptions) ->
h2_connection:start_ssl_upgrade_link(Host, Port, InitialMessage, SSLOptions, chatterbox:settings(client)).
h2_connection:start_ssl_upgrade_link(Host, Port, InitialMessage, SSLOptions, chatterbox:settings(client), #{}).

-spec stop(pid()) -> ok.
stop(Pid) ->
Expand Down Expand Up @@ -139,7 +143,7 @@ send_request(CliPid, Headers, Body) ->
case h2_connection:new_stream(CliPid) of
{error, _Code} = Err ->
Err;
StreamId ->
{StreamId, _} ->
h2_connection:send_headers(CliPid, StreamId, Headers),
h2_connection:send_body(CliPid, StreamId, Body),
{ok, StreamId}
Expand All @@ -149,7 +153,7 @@ send_ping(CliPid) ->
h2_connection:send_ping(CliPid).

-spec get_response(pid(), stream_id()) ->
{ok, {hpack:header(), iodata()}}
{ok, {hpack:headers(), iodata(), hpack:headers()}}
| not_ready
| {error, term()}.
get_response(CliPid, StreamId) ->
Expand Down
Loading