http-2 0.12.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: d1788e5559bb1f36b98896322d1c846ef73b0fba4a7a45b524845735deacb9aa
4
- data.tar.gz: 62ea957139ea576aa4553303f6db141cd9297a8ce75624553e79a90a69f74717
3
+ metadata.gz: c96822381e28e32127984c2dbb7b25b3ad5dd87d69283a752378a9f8778c72ae
4
+ data.tar.gz: beb68a1eb2670d1d0b742224b5ad65bd2bc299656433b120ff31299a481297ce
5
5
  SHA512:
6
- metadata.gz: fb252eeff936187cf2ebebdf93e69fb6f82dba50a0fece880f40a8235b790165ad5d3f167b0c3948adf040388fc7cd49bc1bd1a24b754447c83dd2020be78eaa
7
- data.tar.gz: 0657b1b61f526041167473faf29e50a0cbf4bbfcbac80a458a98a205ab5a01f409da7d62010e5620e5e5fe6cb6e7d1bd5a2ae2a831fcac7da1c1ab2192511c1e
6
+ metadata.gz: 173e0163e2b05ff3eefdfcc420f8c3913c97702873964ef6c653f0329726443c4c10d73d7ffff31583b06567ef12c8f6545eae0f3d32c52d9b13d98322c09e32
7
+ data.tar.gz: 43b38b2bdd3ed6ac90382b98c96b03fd76edefbbf4a385c67c3c8db67e6f755382f09c8a3af848a1d8ed55335ad2925d05793ad71c16c5bb831b07f86e0228be
data/README.md CHANGED
@@ -1,16 +1,17 @@
1
1
  # HTTP-2
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/http-2.svg)](http://rubygems.org/gems/http-2)
4
- [![Coverage Status](https://coveralls.io/repos/igrigorik/http-2/badge.svg)](https://coveralls.io/r/igrigorik/http-2)
4
+ [![Build status](https://github.com/igrigorik/http-2/actions/workflows/ci.yml/badge.svg)](https://github.com/igrigorik/http-2)
5
5
 
6
6
  Pure Ruby, framework and transport agnostic, implementation of HTTP/2 protocol and HPACK header compression with support for:
7
7
 
8
+
8
9
  * [Binary framing](https://hpbn.co/http2/#binary-framing-layer) parsing and encoding
9
10
  * [Stream multiplexing](https://hpbn.co/http2/#streams-messages-and-frames) and [prioritization](https://hpbn.co/http2/#stream-prioritization)
10
11
  * Connection and stream [flow control](https://hpbn.co/http2/#flow-control)
11
12
  * [Header compression](https://hpbn.co/http2/#header-compression) and [server push](https://hpbn.co/http2/#server-push)
12
13
  * Connection and stream management
13
- * And more... see [API docs](http://www.rubydoc.info/github/igrigorik/http-2/frames)
14
+ * And more... see [API docs](https://www.rubydoc.info/gems/http-2)
14
15
 
15
16
  Protocol specifications:
16
17
 
@@ -30,6 +31,7 @@ Your code is responsible for feeding data into the parser, which performs all of
30
31
 
31
32
  ```ruby
32
33
  require 'http/2'
34
+
33
35
  socket = YourTransport.new
34
36
 
35
37
  conn = HTTP2::Client.new
@@ -40,12 +42,12 @@ while bytes = socket.read
40
42
  end
41
43
  ```
42
44
 
43
- Checkout provided [client](https://github.com/igrigorik/http-2/blob/master/example/client.rb) and [server](https://github.com/igrigorik/http-2/blob/master/example/server.rb) implementations for basic examples.
45
+ Checkout provided [client](example/client.rb) and [server](example/server.rb) implementations for basic examples.
44
46
 
45
47
 
46
48
  ### Connection lifecycle management
47
49
 
48
- Depending on the role of the endpoint you must initialize either a [Client](http://www.rubydoc.info/github/igrigorik/http-2/HTTP2/Client) or a [Server](http://www.rubydoc.info/github/igrigorik/http-2/HTTP2/Server) object. Doing so picks the appropriate header compression / decompression algorithms and stream management logic. From there, you can subscribe to connection level events, or invoke appropriate APIs to allocate new streams and manage the lifecycle. For example:
50
+ Depending on the role of the endpoint you must initialize either a [Client](lib/http/2/client.rb) or a [Server](lib/http/2/server.rb) object. Doing so picks the appropriate header compression / decompression algorithms and stream management logic. From there, you can subscribe to connection level events, or invoke appropriate APIs to allocate new streams and manage the lifecycle. For example:
49
51
 
50
52
  ```ruby
51
53
  # - Server ---------------
@@ -148,7 +150,7 @@ conn.on(:stream) do |stream|
148
150
  end
149
151
  ```
150
152
 
151
- Events emitted by the [Stream object](http://www.rubydoc.info/github/igrigorik/http-2/HTTP2/Stream):
153
+ Events emitted by the [Stream object](lib/http/2/stream.rb):
152
154
 
153
155
  <table>
154
156
  <tr>
@@ -252,7 +254,7 @@ conn.on(:stream) do |stream|
252
254
  # split response between multiple DATA frames
253
255
  stream.data(response_chunk, end_stream: false)
254
256
  stream.data(last_chunk)
255
-
257
+
256
258
  # now send the previously promised data
257
259
  push_stream.data(push_data)
258
260
  end
@@ -283,4 +285,5 @@ rake
283
285
 
284
286
  ### License
285
287
 
286
- (MIT License) - Copyright (c) 2013 Ilya Grigorik ![GA](https://www.google-analytics.com/__utm.gif?utmac=UA-71196-9&utmhn=github.com&utmdt=HTTP2&utmp=/http-2/readme)
288
+ (MIT License) - Copyright (c) 2013-2019 Ilya Grigorik ![GA](https://www.google-analytics.com/__utm.gif?utmac=UA-71196-9&utmhn=github.com&utmdt=HTTP2&utmp=/http-2/readme)
289
+ (MIT License) - Copyright (c) 2019 Tiago Cardoso ![GA](https://www.google-analytics.com/__utm.gif?utmac=UA-71196-9&utmhn=github.com&utmdt=HTTP2&utmp=/http-2/readme)
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ if RUBY_VERSION < "3.3.0"
4
+ require "base64"
5
+ elsif !defined?(Base64)
6
+ module HTTP2
7
+ # require "base64" will not be a default gem after ruby 3.4.0
8
+ module Base64
9
+ module_function
10
+
11
+ def encode64(bin)
12
+ [bin].pack("m")
13
+ end
14
+
15
+ def decode64(str)
16
+ str.unpack1("m")
17
+ end
18
+
19
+ def strict_encode64(bin)
20
+ [bin].pack("m0")
21
+ end
22
+
23
+ def strict_decode64(str)
24
+ str.unpack1("m0")
25
+ end
26
+
27
+ def urlsafe_encode64(bin, padding: true)
28
+ str = strict_encode64(bin)
29
+ str.chomp!("==") or str.chomp!("=") unless padding
30
+ str.tr!("+/", "-_")
31
+ str
32
+ end
33
+ end
34
+
35
+ def urlsafe_decode64(str)
36
+ if !str.end_with?("=") && str.length % 4 != 0
37
+ str = str.ljust((str.length + 3) & ~3, "=")
38
+ str.tr!("-_", "+/")
39
+ else
40
+ str = str.tr("-_", "+/")
41
+ end
42
+ strict_decode64(str)
43
+ end
44
+ end
45
+ end
data/lib/http/2/client.rb CHANGED
@@ -20,7 +20,7 @@ module HTTP2
20
20
  #
21
21
  class Client < Connection
22
22
  # Initialize new HTTP 2.0 client object.
23
- def initialize(**settings)
23
+ def initialize(settings = {})
24
24
  @stream_id = 1
25
25
  @state = :waiting_connection_preface
26
26
 
@@ -37,20 +37,23 @@ module HTTP2
37
37
  # @param frame [Hash]
38
38
  def send(frame)
39
39
  send_connection_preface
40
- super(frame)
40
+ super
41
41
  end
42
42
 
43
43
  def receive(frame)
44
44
  send_connection_preface
45
- super(frame)
45
+ super
46
46
  end
47
47
 
48
48
  # sends the preface and initializes the first stream in half-closed state
49
49
  def upgrade
50
+ @h2c_upgrade = :start
50
51
  raise ProtocolError unless @stream_id == 1
51
52
 
52
53
  send_connection_preface
53
- new_stream(state: :half_closed_local)
54
+ stream = new_stream(state: :half_closed_local)
55
+ @h2c_upgrade = :finished
56
+ stream
54
57
  end
55
58
 
56
59
  # Emit the connection preface if not yet
@@ -64,9 +67,15 @@ module HTTP2
64
67
  settings(payload)
65
68
  end
66
69
 
67
- def self.settings_header(**settings)
70
+ def self.settings_header(settings)
68
71
  frame = Framer.new.generate(type: :settings, stream: 0, payload: settings)
69
72
  Base64.urlsafe_encode64(frame[9..-1])
70
73
  end
74
+
75
+ private
76
+
77
+ def verify_pseudo_headers(frame)
78
+ _verify_pseudo_headers(frame, RESPONSE_MANDATORY_HEADERS)
79
+ end
71
80
  end
72
81
  end