Skip to content

Commit

Permalink
fix: ES properly set on certain HEADERS frames
Browse files Browse the repository at this point in the history
  • Loading branch information
hpopp committed Dec 18, 2017
1 parent f390361 commit 8f64194
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.3.6
- Fixed: ES flag properly set on certain HEADERS frames

## v0.3.5
- Fixed: Memory leak on connection crashes
- New supervision structure. `Kadabra.open/2` now returns a supervisor pid,
Expand Down
3 changes: 3 additions & 0 deletions lib/frame/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ defmodule Kadabra.Frame.Settings do
%__MODULE__{ack: true, settings: nil}
end

def new(%{payload: "", flags: flags}) do
{:ok, %__MODULE__{settings: nil, ack: Flags.ack?(flags)}}
end
def new(%{payload: p, flags: flags}) do
s_list = parse_settings(p)
case put_settings(%Connection.Settings{}, s_list) do
Expand Down
22 changes: 14 additions & 8 deletions lib/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ defmodule Kadabra.Stream do
@headers 0x1

@closed :closed
@half_closed_local :half_closed_local
@half_closed_remote :half_closed_remote
@hc_local :half_closed_local
@hc_remote :half_closed_remote
@idle :idle
@open :open
# @reserved_local :reserved_local
Expand Down Expand Up @@ -93,9 +93,14 @@ defmodule Kadabra.Stream do
{:keep_state, %{stream | flow: flow}}
end

def recv(%Data{end_stream: true,
data: data}, state, stream) when state in [@hc_local] do
stream = %Stream{stream | body: stream.body <> data}
{:next_state, @closed, stream}
end
def recv(%Data{end_stream: true, data: data}, _state, stream) do
stream = %Stream{stream | body: stream.body <> data}
{:next_state, @half_closed_remote, stream}
{:next_state, @hc_remote, stream}
end
def recv(%Data{end_stream: false, data: data}, _state, stream) do
stream = %Stream{stream | body: stream.body <> data}
Expand All @@ -107,7 +112,7 @@ defmodule Kadabra.Stream do

{:ok, headers} = Hpack.decode(stream.ref, fragment)
stream = %Stream{stream | headers: stream.headers ++ headers}
{:next_state, @half_closed_remote, stream}
{:next_state, @hc_remote, stream}
end
def recv(%Headers{header_block_fragment: fragment,
end_stream: false}, _state, stream) do
Expand Down Expand Up @@ -137,7 +142,7 @@ defmodule Kadabra.Stream do
end

def recv(%RstStream{} = _frame, state, stream)
when state in [@open, @half_closed_local, @half_closed_remote, @closed] do
when state in [@open, @hc_local, @hc_remote, @closed] do
# IO.inspect(frame, label: "Got RST_STREAM")
{:next_state, :closed, stream}
end
Expand All @@ -160,7 +165,7 @@ defmodule Kadabra.Stream do

# Enter Events

def handle_event(:enter, _old, @half_closed_remote, stream) do
def handle_event(:enter, _old, @hc_remote, stream) do
bin = stream.id |> RstStream.new |> Encodable.to_bin
:ssl.send(stream.socket, bin)

Expand Down Expand Up @@ -205,9 +210,10 @@ defmodule Kadabra.Stream do
{:ok, encoded} = Hpack.encode(stream.ref, headers)
headers_payload = :erlang.iolist_to_binary(encoded)

h = Http2.build_frame(@headers, 0x4, stream.id, headers_payload)
flags = if payload, do: 0x4, else: 0x5
h = Http2.build_frame(@headers, flags, stream.id, headers_payload)
:ssl.send(stream.socket, h)
# IO.puts("Sending, Stream ID: #{stream.id}")
# IO.puts("Sending, Stream ID: #{stream.id}, size: #{byte_size(h)}")

flow =
if payload do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Kadabra.Mixfile do
use Mix.Project

@version "0.3.5"
@version "0.3.6"

def project do
[
Expand Down

0 comments on commit 8f64194

Please sign in to comment.