anchor.diff:           new_stream/1,
            new_stream/2,
            new_stream/4,
  +         new_stream/6,
            send_promise/4,
            get_response/2,
            get_peer/1,
  
positive.code:              #connection{}=Conn) ->
      {keep_state,
       send_settings(Http2Settings, Conn)};
  handle_event(_, {send_headers, StreamId, Headers, Opts},
               #connection{
                  encode_context=EncodeContext,
                  streams = Streams,
                  socket = Socket
                 }=Conn
              ) ->
     StreamComplete = proplists:get_value(send_end_stream, Opts, false),
  
      Stream = h2_stream_set:get(StreamId, Streams),
      case h2_stream_set:type(Stream) of
          active ->
              {FramesToSend, NewContext} =
                  h2_frame_headers:to_frames(h2_stream_set:stream_id(Stream),
                                             Headers,
                                             EncodeContext,
                                              (Conn#connection.peer_settings)#settings.max_frame_size,
                                             StreamComplete
                                            ),
              [sock:send(Socket, h2_frame:to_binary(Frame)) || Frame <- FramesToSend],
              send_h(Stream, Headers),
              {keep_state,
               Conn#connection{
                 encode_context=NewContext
                }};
          idle ->
              %% In theory this is a client maybe activating a stream,
              %% but in practice, we've already activated the stream in
              %% new_stream/1
              {keep_state, Conn};
          closed ->
              {keep_state, Conn}
      end;
  handle_event(_, {send_trailers, StreamId, Headers, Opts},
               #connection{
                  encode_context=EncodeContext,
  
negative.code:                                  streams=NewStreams
                                  }, [{reply, From, Reply}]}.
  
  new_stream_(From, CallbackMod, CallbackState, Headers, Opts, NotifyPid, Conn=#connection{streams=Streams,
                                                                                           next_available_stream_id=NextId}) ->
      {Reply, NewStreams} =
          case
              h2_stream_set:new_stream(
                NextId,
                NotifyPid,
                CallbackMod,
                CallbackState,
                Conn#connection.socket,
                Conn#connection.peer_settings#settings.initial_window_size,
                Conn#connection.self_settings#settings.initial_window_size,
                Conn#connection.type,
                Streams)
          of
              {error, Code, _NewStream} ->
                  %% TODO: probably want to have events like this available for metrics
                  %% tried to create new_stream but there are too many
                  {{error, Code}, Streams};
              {Pid, GoodStreamSet} ->
                  {{NextId, Pid}, GoodStreamSet}
          end,
  
      Conn1 = Conn#connection{
                next_available_stream_id=NextId+2,
                streams=NewStreams
               },
      {keep_state, Conn2} = send_headers_(NextId, Headers, Opts, Conn1),
  
      {keep_state, Conn2, [{reply, From, Reply}]}.
  
  send_headers_(StreamId, Headers, Opts, #connection{encode_context=EncodeContext,
                                                     streams = Streams,
                                                     socket = Socket
                                                    }=Conn) ->
      StreamComplete = proplists:get_value(send_end_stream, Opts, false),
  
      Stream = h2_stream_set:get(StreamId, Streams),
      case h2_stream_set:type(Stream) of
          active ->
              {FramesToSend, NewContext} =
                  h2_frame_headers:to_frames(h2_stream_set:stream_id(Stream),
                                             Headers,
                                             EncodeContext,
                                             (Conn#connection.peer_settings)#settings.max_frame_size,
                                             StreamComplete
                                            ),
              [sock:send(Socket, h2_frame:to_binary(Frame)) || Frame <- FramesToSend],
              send_h(Stream, Headers),
              {keep_state,
               Conn#connection{
                 encode_context=NewContext
                }};
          idle ->
              %% In theory this is a client maybe activating a stream,
              %% but in practice, we've already activated the stream in
              %% new_stream/1
              {keep_state, Conn};
          closed ->
              {keep_state, Conn}
      end.
  
  -spec go_away(error_code(), connection()) -> {next_state, closing, connection()}.
  go_away(ErrorCode,
          #connection{
  