http-protocol 0.10.0 → 0.10.1

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: 6d7eb5677113a92a47997510c060e0105f2c10ee594216469f655b1c669f9972
4
- data.tar.gz: d1e93786ffd93d16b9d0d7958af486d21d60c8c231ce9a6ee614606295bf8bfb
3
+ metadata.gz: 6d38445cd1c5486bace349b4df0776d4a65dce709ff478d2d24d315a01d73a19
4
+ data.tar.gz: d93043c98af222f1c9ec6bb7fe341c8c53ac6225512e18f7cc09d012c7b4f656
5
5
  SHA512:
6
- metadata.gz: 92fddea1dabc6fdfd8e866a1fce397224f675f21ba4c113e294b1cd90d59fcd1c539fc96192fb0e733745fb62e41f8f6f2d2922dee2da028fd97e90ed3afff2b
7
- data.tar.gz: 68be4ce7f96677418e2a366da3c72591ced7837b720700345395cebda9be07189aee71de2998eb439a288766864f80d60c2eb17532c87972d1b8175d1c2f67a3
6
+ metadata.gz: 99414ae8ac5f88258d17d2e3e963ad112e61c744d30b898db419876c8b28208c356d5b185a34b327740e7c92bd85569a547d4adbbe6eb02c6a08cd68abd4253e
7
+ data.tar.gz: 004dedb83a3d63d795e994b581bbacf417182518f845d7b593cb45b438c17ec2f7af8702104ea36c6f0009c94afffd1539b3157b7461053fe6edb1b05c196c12
@@ -0,0 +1,38 @@
1
+
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
3
+
4
+ require 'async'
5
+ require 'async/io/stream'
6
+ require 'async/http/url_endpoint'
7
+ require 'http/protocol/http1/connection'
8
+ require 'pry'
9
+
10
+ Async.run do
11
+ endpoint = Async::HTTP::URLEndpoint.parse("https://www.google.com/search?q=kittens", alpn_protocols: ["http/1.1"])
12
+
13
+ peer = endpoint.connect
14
+
15
+ puts "Connected to #{peer} #{peer.remote_address.inspect}"
16
+
17
+ # IO Buffering...
18
+ stream = Async::IO::Stream.new(peer)
19
+ client = HTTP::Protocol::HTTP1::Connection.new(stream)
20
+
21
+ def client.read_line
22
+ @stream.read_until(HTTP::Protocol::HTTP1::Connection::CRLF) or raise EOFError
23
+ end
24
+
25
+ puts "Writing request..."
26
+ client.write_request("www.google.com", "GET", "/search?q=kittens", "HTTP/1.1", [["Accept", "*/*"]])
27
+ client.write_body(nil)
28
+
29
+ puts "Reading response..."
30
+ response = client.read_response("GET")
31
+
32
+ puts "Got response: #{response.inspect}"
33
+
34
+ puts "Closing client..."
35
+ client.close
36
+ end
37
+
38
+ puts "Exiting."
@@ -0,0 +1,68 @@
1
+
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
3
+
4
+ require 'async'
5
+ require 'async/io/stream'
6
+ require 'async/http/url_endpoint'
7
+ require 'http/protocol/http2/client'
8
+ require 'pry'
9
+
10
+ Async.run do
11
+ endpoint = Async::HTTP::URLEndpoint.parse("https://www.google.com/search?q=kittens")
12
+
13
+ peer = endpoint.connect
14
+
15
+ puts "Connected to #{peer.inspect}"
16
+
17
+ # IO Buffering...
18
+ stream = Async::IO::Stream.new(peer)
19
+
20
+ framer = HTTP::Protocol::HTTP2::Framer.new(stream)
21
+ client = HTTP::Protocol::HTTP2::Client.new(framer)
22
+
23
+ puts "Sending connection preface..."
24
+ client.send_connection_preface
25
+
26
+ puts "Creating stream..."
27
+ stream = client.create_stream
28
+
29
+ headers = [
30
+ [":scheme", endpoint.scheme],
31
+ [":method", "GET"],
32
+ [":authority", "www.google.com"],
33
+ [":path", endpoint.path],
34
+ ["accept", "*/*"],
35
+ ]
36
+
37
+ puts "Sending request on stream id=#{stream.id} state=#{stream.state}..."
38
+ stream.send_headers(nil, headers, HTTP::Protocol::HTTP2::END_STREAM)
39
+
40
+ puts "Waiting for response..."
41
+ $count = 0
42
+
43
+ def stream.process_headers(frame)
44
+ headers = super
45
+ puts "Got response headers: #{headers} (#{frame.end_stream?})"
46
+ end
47
+
48
+ def stream.receive_data(frame)
49
+ data = super
50
+
51
+ $count += data.scan(/kittens/).count
52
+
53
+ puts "Got response data: #{data.bytesize}"
54
+ end
55
+
56
+ until stream.closed?
57
+ frame = client.read_frame
58
+ end
59
+
60
+ puts "Got #{$count} kittens!"
61
+
62
+ binding.pry
63
+
64
+ puts "Closing client..."
65
+ client.close
66
+ end
67
+
68
+ puts "Exiting."
@@ -0,0 +1,57 @@
1
+
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
3
+
4
+ require 'async'
5
+ require 'async/io/stream'
6
+ require 'async/http/url_endpoint'
7
+ require 'http/protocol/http2/client'
8
+ require 'pry'
9
+
10
+ queries = ["apple", "orange", "teapot", "async"]
11
+
12
+ Async.run do
13
+ endpoint = Async::HTTP::URLEndpoint.parse("https://www.google.com")
14
+
15
+ peer = endpoint.connect
16
+ stream = Async::IO::Stream.new(peer)
17
+ framer = HTTP::Protocol::HTTP2::Framer.new(stream)
18
+ client = HTTP::Protocol::HTTP2::Client.new(framer)
19
+
20
+ puts "Sending connection preface..."
21
+ client.send_connection_preface
22
+
23
+ puts "Creating stream..."
24
+ streams = queries.collect do |keyword|
25
+ client.create_stream.tap do |stream|
26
+ headers = [
27
+ [":scheme", endpoint.scheme],
28
+ [":method", "GET"],
29
+ [":authority", "www.google.com"],
30
+ [":path", "/search?q=#{keyword}"],
31
+ ["accept", "*/*"],
32
+ ]
33
+
34
+ puts "Sending request on stream id=#{stream.id} state=#{stream.state}..."
35
+ stream.send_headers(nil, headers, HTTP::Protocol::HTTP2::END_STREAM)
36
+
37
+ def stream.process_headers(frame)
38
+ headers = super
39
+ puts "Stream #{self.id}: Got response headers: #{headers} (#{frame.end_stream?})"
40
+ end
41
+
42
+ def stream.receive_data(frame)
43
+ data = super
44
+ puts "Stream #{self.id}: Got response data: #{data.bytesize}"
45
+ end
46
+ end
47
+ end
48
+
49
+ until streams.all?{|stream| stream.closed?}
50
+ frame = client.read_frame
51
+ end
52
+
53
+ puts "Closing client..."
54
+ client.close
55
+ end
56
+
57
+ puts "Exiting."
@@ -0,0 +1,44 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module HTTP
22
+ module Protocol
23
+ # CGI keys (https://tools.ietf.org/html/rfc3875#section-4.1)
24
+ module CGI
25
+ AUTH_TYPE = "AUTH_TYPE".freeze
26
+ CONTENT_LENGTH = "CONTENT_LENGTH".freeze
27
+ CONTENT_TYPE = "CONTENT_TYPE".freeze
28
+ GATEWAY_INTERFACE = "GATEWAY_INTERFACE".freeze
29
+ PATH_INFO = "PATH_INFO".freeze
30
+ PATH_TRANSLATED = "PATH_TRANSLATED".freeze
31
+ QUERY_STRING = "QUERY_STRING".freeze
32
+ REMOTE_ADDR = "REMOTE_ADDR".freeze
33
+ REMOTE_HOST = "REMOTE_HOST".freeze
34
+ REMOTE_IDENT = "REMOTE_IDENT".freeze
35
+ REMOTE_USER = "REMOTE_USER".freeze
36
+ REQUEST_METHOD = "REQUEST_METHOD".freeze
37
+ SCRIPT_NAME = "SCRIPT_NAME".freeze
38
+ SERVER_NAME = "SERVER_NAME".freeze
39
+ SERVER_PORT = "SERVER_PORT".freeze
40
+ SERVER_PROTOCOL = "SERVER_PROTOCOL".freeze
41
+ SERVER_SOFTWARE = "SERVER_SOFTWARE".freeze
42
+ end
43
+ end
44
+ end
@@ -28,7 +28,7 @@ module HTTP
28
28
  super(framer, 1)
29
29
  end
30
30
 
31
- def send_connection_preface(settings = nil)
31
+ def send_connection_preface(settings = [])
32
32
  if @state == :new
33
33
  @framer.write_connection_preface
34
34
 
@@ -163,7 +163,7 @@ module HTTP
163
163
  read_header(stream) unless @length
164
164
 
165
165
  if @length > maximum_frame_size
166
- raise FrameSizeError, "Frame length #{@length} exceeds maximum frame size #{maximum_frame_size}!"
166
+ raise FrameSizeError, "#{self.class} (type=#{@type}) frame length #{@length} exceeds maximum frame size #{maximum_frame_size}!"
167
167
  end
168
168
 
169
169
  read_payload(stream)
@@ -97,6 +97,8 @@ module HTTP
97
97
  frame.write(@stream)
98
98
 
99
99
  @stream.flush
100
+
101
+ return frame
100
102
  end
101
103
 
102
104
  def read_header
@@ -28,7 +28,7 @@ module HTTP
28
28
  super(framer, 2)
29
29
  end
30
30
 
31
- def read_connection_preface(settings)
31
+ def read_connection_preface(settings = [])
32
32
  if @state == :new
33
33
  @framer.read_connection_preface
34
34
 
@@ -84,7 +84,7 @@ module HTTP
84
84
  @enable_push = 1
85
85
  @maximum_concurrent_streams = 0xFFFFFFFF
86
86
  @initial_window_size = 0xFFFF # 2**16 - 1
87
- @maximum_frame_size = 0x3FFF # 2**14 - 1
87
+ @maximum_frame_size = 0x4000 # 2**14
88
88
  @maximum_header_list_size = 0xFFFFFFFF
89
89
  end
90
90
 
@@ -0,0 +1,39 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module HTTP
22
+ module Protocol
23
+ # HTTP method verbs
24
+ module Methods
25
+ GET = 'GET'.freeze
26
+ POST = 'POST'.freeze
27
+ PUT = 'PUT'.freeze
28
+ PATCH = 'PATCH'.freeze
29
+ DELETE = 'DELETE'.freeze
30
+ HEAD = 'HEAD'.freeze
31
+ OPTIONS = 'OPTIONS'.freeze
32
+ LINK = 'LINK'.freeze
33
+ UNLINK = 'UNLINK'.freeze
34
+ TRACE = 'TRACE'.freeze
35
+
36
+ # Use Methods.constants to get all constants.
37
+ end
38
+ end
39
+ end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module HTTP
22
22
  module Protocol
23
- VERSION = "0.10.0"
23
+ VERSION = "0.10.1"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-protocol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-10 00:00:00.000000000 Z
11
+ date: 2018-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-hpack
@@ -79,8 +79,12 @@ files:
79
79
  - Gemfile
80
80
  - README.md
81
81
  - Rakefile
82
+ - examples/http1/request.rb
83
+ - examples/http2/request.rb
84
+ - examples/http2/requests.rb
82
85
  - http-protocol.gemspec
83
86
  - lib/http/protocol.rb
87
+ - lib/http/protocol/cgi.rb
84
88
  - lib/http/protocol/error.rb
85
89
  - lib/http/protocol/headers.rb
86
90
  - lib/http/protocol/http1/connection.rb
@@ -102,6 +106,7 @@ files:
102
106
  - lib/http/protocol/http2/settings_frame.rb
103
107
  - lib/http/protocol/http2/stream.rb
104
108
  - lib/http/protocol/http2/window_update_frame.rb
109
+ - lib/http/protocol/methods.rb
105
110
  - lib/http/protocol/reference.rb
106
111
  - lib/http/protocol/version.rb
107
112
  homepage: https://github.com/socketry/http-protocol