Skip to content

Commit

Permalink
client stream callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Jun 19, 2018
1 parent caec4b0 commit 5e5cdc7
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 296 deletions.
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
2 changes: 1 addition & 1 deletion src/chatterbox.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

]},

{maintainers, ["Joe DeVivo"]},
{maintainers, ["Joe DeVivo", "Tristan Sloughter"]},
{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

0 comments on commit 5e5cdc7

Please sign in to comment.