http-2-next 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 910d4e858a63a1b882621dbf2951f2f8a20c29be458de15c9633b451594b797a
4
- data.tar.gz: a2ab88e4f38a97320f0d338c149485ee5976645fccd110bd839ba96d6f59432f
3
+ metadata.gz: 63f956f2326b803ec836c578b8f98326934897307bda409f2c639e5c88893689
4
+ data.tar.gz: fbb8a4486463e0e0e5c0d4ed04cf4120a73acdf169f99b99365a0805f89fe5c1
5
5
  SHA512:
6
- metadata.gz: 72ca980c5aa292e4e92cdf625f8769c77a2a12a9452736a254c668f55cfcdcdcde493db0d8e760eb7d4c1981aadbcdb08f0f48970b8453b3a59dbb5c9ef2a614
7
- data.tar.gz: 6875ba9d1136b4c146e89c1b5dad811e4225adb03f99340b09dab0a54f7eeee4aab04596e9bed9f1d68de6b2770aa1548a662d4c9969356612ede4c5d48c2864
6
+ metadata.gz: 628b410fe470df16e61d11732c65553381bcb060f2fe2639af4889aff5d9e3a046ee55e1d67599e1c268dd38c3f4ff22f8fb257ee100a96ba384a9ea1e976726
7
+ data.tar.gz: 86e1148ca63e9d36745ab703ab29f174fdae5cb8473b167fa4f09138274899713cb57e7604c6ff51d0fae493ea98262b1d86adf94c42c0248e50721ae2f63add
@@ -71,10 +71,7 @@ module HTTP2Next
71
71
 
72
72
  # Number of active streams between client and server (reserved streams
73
73
  # are not counted towards the stream limit).
74
- attr_reader :active_stream_count
75
-
76
- # Max number of streams that can be in-transit in this connection.
77
- attr_writer :max_streams
74
+ attr_accessor :active_stream_count
78
75
 
79
76
  # Initializes new connection object.
80
77
  #
@@ -86,7 +83,6 @@ module HTTP2Next
86
83
  @decompressor = Header::Decompressor.new(settings)
87
84
 
88
85
  @active_stream_count = 0
89
- @max_streams = nil
90
86
  @last_activated_stream = 0
91
87
  @last_stream_id = 0
92
88
  @streams = {}
@@ -120,8 +116,7 @@ module HTTP2Next
120
116
  # @param parent [Stream]
121
117
  def new_stream(**args)
122
118
  raise ConnectionClosed if @state == :closed
123
-
124
- raise StreamLimitExceeded if @active_stream_count >= (@max_streams || @remote_settings[:settings_max_concurrent_streams])
119
+ raise StreamLimitExceeded if @active_stream_count >= @remote_settings[:settings_max_concurrent_streams]
125
120
 
126
121
  connection_error(:protocol_error, msg: "id is smaller than previous") if @stream_id < @last_activated_stream
127
122
 
@@ -727,24 +722,22 @@ module HTTP2Next
727
722
  def activate_stream(id:, **args)
728
723
  connection_error(msg: "Stream ID already exists") if @streams.key?(id)
729
724
 
730
- raise StreamLimitExceeded if @active_stream_count >= (@max_streams || @local_settings[:settings_max_concurrent_streams])
725
+ raise StreamLimitExceeded if @active_stream_count >= @local_settings[:settings_max_concurrent_streams]
731
726
 
732
727
  stream = Stream.new(connection: self, id: id, **args)
733
728
 
734
- # Streams that are in the "open" state, or either of the "half closed"
735
- # states count toward the maximum number of streams that an endpoint is
736
- # permitted to open.
737
- stream.once(:active) { @active_stream_count += 1 }
738
729
  stream.once(:close) do
739
730
  # Store a reference to the closed stream, such that we can respond
740
731
  # to any in-flight frames while close is registered on both sides.
741
732
  # References to such streams will be purged whenever another stream
742
733
  # is closed, with a minimum of 15s RTT time window.
743
- @streams_recently_closed.reject! do |stream_id, v|
744
- to_delete = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - v) > 15
745
- @streams.delete stream_id if to_delete
746
- to_delete
747
- end
734
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
735
+
736
+ # TODO: use a drop_while! variant whenever there is one.
737
+ @streams_recently_closed = @streams_recently_closed.drop_while do |_, v|
738
+ (now - v) > 15
739
+ end.to_h
740
+
748
741
  @streams_recently_closed[id] = Process.clock_gettime(Process::CLOCK_MONOTONIC)
749
742
  end
750
743
 
@@ -91,6 +91,7 @@ module HTTP2Next
91
91
  @_method = @_content_length = @_status_code = nil
92
92
  @_waiting_on_trailers = false
93
93
  @received_data = false
94
+ @activated = false
94
95
 
95
96
  on(:window) { |v| @remote_window = v }
96
97
  on(:local_window) { |v| @local_window_max_size = @local_window = v }
@@ -169,7 +170,7 @@ module HTTP2Next
169
170
  trailers = frame[:payload]
170
171
  return unless trailers.respond_to?(:each)
171
172
 
172
- trailers.each do |field, _|
173
+ trailers.each do |field, _| # rubocop:disable Style/HashEachMethods
173
174
  @_trailers.delete(field)
174
175
  break if @_trailers.empty?
175
176
  end
@@ -605,7 +606,7 @@ module HTTP2Next
605
606
  case newstate
606
607
  when :open
607
608
  @state = newstate
608
- emit(:active)
609
+ activate_stream_in_conn
609
610
 
610
611
  when :reserved_local, :reserved_remote
611
612
  @state = newstate
@@ -613,7 +614,7 @@ module HTTP2Next
613
614
 
614
615
  when :half_closed_local, :half_closed_remote
615
616
  @closed = newstate
616
- emit(:active) unless @state == :open
617
+ activate_stream_in_conn unless @state == :open
617
618
  @state = :half_closing
618
619
 
619
620
  when :local_closed, :remote_closed, :local_rst, :remote_rst
@@ -624,11 +625,25 @@ module HTTP2Next
624
625
  @state
625
626
  end
626
627
 
628
+ # Streams that are in the "open" state, or either of the "half closed"
629
+ # states count toward the maximum number of streams that an endpoint is
630
+ # permitted to open.
631
+ def activate_stream_in_conn
632
+ @connection.active_stream_count += 1
633
+ @activated = true
634
+ emit(:active)
635
+ end
636
+
637
+ def close_stream_in_conn(*args)
638
+ @connection.active_stream_count -= 1 if @activated
639
+ emit(:close, *args)
640
+ end
641
+
627
642
  def complete_transition(frame)
628
643
  case @state
629
644
  when :closing
630
645
  @state = :closed
631
- emit(:close, frame[:error])
646
+ close_stream_in_conn(frame[:error])
632
647
  when :half_closing
633
648
  @state = @closed
634
649
  emit(:half_close)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTP2Next
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.2"
5
5
  end
data/sig/connection.rbs CHANGED
@@ -17,9 +17,7 @@ module HTTP2Next
17
17
  attr_reader local_settings: settings_hash
18
18
  attr_reader pending_settings: settings_ary
19
19
 
20
- attr_reader active_stream_count: Integer
21
-
22
- attr_writer max_streams: Integer?
20
+ attr_accessor active_stream_count: Integer
23
21
 
24
22
  @stream_id: Integer
25
23
  @active_stream_count: Integer
data/sig/stream.rbs CHANGED
@@ -12,6 +12,16 @@ module HTTP2Next
12
12
  attr_reader local_window: Integer
13
13
  attr_reader closed: Symbol?
14
14
 
15
+ @connection: Connection
16
+ @local_window_max_size: Integer
17
+ @error: bool
18
+ @_method: String?
19
+ @_content_length: Integer?
20
+ @_status_code: Integer?
21
+ @_waiting_on_trailers: bool
22
+ @received_data: bool
23
+ @activated: bool
24
+
15
25
  alias window local_window
16
26
 
17
27
  def closed?: () -> bool
@@ -61,6 +71,10 @@ module HTTP2Next
61
71
 
62
72
  def event: (Symbol newstate) -> void
63
73
 
74
+ def activate_stream_in_conn: () -> void
75
+
76
+ def close_stream_in_conn: (*untyped) -> void
77
+
64
78
  def complete_transition: (frame) -> void
65
79
 
66
80
  def process_priority: ({weight: Integer, dependency: Integer, exclusive: bool}) -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-2-next
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-10-03 00:00:00.000000000 Z
13
+ date: 2023-12-14 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Pure-ruby HTTP 2.0 protocol implementation
16
16
  email: