protocol-http 0.26.3 → 0.26.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd49532afd66aa61fc45281ce3fd9493e241790cd3daaf59c071793f91b5b42a
4
- data.tar.gz: a8b0cefa5ad518293558a66a2db77fb4bd9ef3ba381134d9051d24ad1bcb64a5
3
+ metadata.gz: ec1274383518ed67d583ca4bd675984a61c34b2bc4b19600a064fd80e595548a
4
+ data.tar.gz: cdf454fb4d8c1513dab3f9e1dd48a2b8bf466af01cbb97fcee256fd79d7ec91c
5
5
  SHA512:
6
- metadata.gz: 8d243e058e7cd0dd9825c44de883e5badf0df4aa150608ffdc034e4c0259412d64699cb97e0132e2d9307bcf874a2ce67f03e02046d00c761415d71c5c0a7941
7
- data.tar.gz: 0d29c9fd133dede2b2d7a545405df8e64dcfb497477c1252bb34e41fffac7fc9540142b9d1961a146d2e4afcedc86fb4cb9ce2e75d55a5c1a5e4ac4c0ced8659
6
+ metadata.gz: af8dc10e55a1079c3862fe05316d8e1716a0ff4af45e705927e310f707c49fb2c10a13954af9ddee21cca9814037faddeed035691bbc35136bbe058facf354ac
7
+ data.tar.gz: fdf5fcbb3d7a184aa77e55b3016820fcd34863b401301901232f188cc350c357e76590448ee67a74c032c931f064b9a833291c2b95c48a7da69f767e6887df69
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'wrapper'
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
  # Copyright, 2023, by Bruno Sutic.
6
6
 
7
7
  module Protocol
@@ -93,7 +93,7 @@ module Protocol
93
93
  end
94
94
  end
95
95
 
96
- def as_json
96
+ def as_json(...)
97
97
  {
98
98
  class: self.class.name,
99
99
  length: self.length,
@@ -102,6 +102,10 @@ module Protocol
102
102
  empty: self.empty?
103
103
  }
104
104
  end
105
+
106
+ def to_json(...)
107
+ as_json.to_json(...)
108
+ end
105
109
  end
106
110
  end
107
111
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'readable'
7
7
 
@@ -51,13 +51,17 @@ module Protocol
51
51
  @body.read
52
52
  end
53
53
 
54
- def as_json
54
+ def as_json(...)
55
55
  {
56
56
  class: self.class.name,
57
57
  body: @body&.as_json
58
58
  }
59
59
  end
60
60
 
61
+ def to_json(...)
62
+ as_json.to_json(...)
63
+ end
64
+
61
65
  def inspect
62
66
  @body.inspect
63
67
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2023, by Samuel Williams.
4
+ # Copyright, 2018-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'header/split'
7
7
  require_relative 'header/multiple'
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
6
  require_relative '../middleware'
7
7
 
@@ -30,7 +30,13 @@ module Protocol
30
30
  def self.build(&block)
31
31
  builder = Builder.new
32
32
 
33
- builder.instance_eval(&block)
33
+ if block_given?
34
+ if block.arity == 0
35
+ builder.instance_exec(&block)
36
+ else
37
+ yield builder
38
+ end
39
+ end
34
40
 
35
41
  return builder.to_app
36
42
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'body/buffered'
7
7
  require_relative 'body/reader'
@@ -73,7 +73,7 @@ module Protocol
73
73
  @method != Methods::POST && (@body.nil? || @body.empty?)
74
74
  end
75
75
 
76
- def as_json
76
+ def as_json(...)
77
77
  {
78
78
  scheme: @scheme,
79
79
  authority: @authority,
@@ -86,6 +86,10 @@ module Protocol
86
86
  }
87
87
  end
88
88
 
89
+ def to_json(...)
90
+ as_json.to_json(...)
91
+ end
92
+
89
93
  def to_s
90
94
  "#{@scheme}://#{@authority}: #{@method} #{@path} #{@version}"
91
95
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'body/buffered'
7
7
  require_relative 'body/reader'
@@ -104,7 +104,7 @@ module Protocol
104
104
  Response[500, Headers['content-type' => 'text/plain'], ["#{exception.class}: #{exception.message}"]]
105
105
  end
106
106
 
107
- def as_json
107
+ def as_json(...)
108
108
  {
109
109
  version: @version,
110
110
  status: @status,
@@ -114,6 +114,10 @@ module Protocol
114
114
  }
115
115
  end
116
116
 
117
+ def to_json(...)
118
+ as_json.to_json(...)
119
+ end
120
+
117
121
  def to_s
118
122
  "#{@status} #{@version}"
119
123
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.26.3"
8
+ VERSION = "0.26.5"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.3
4
+ version: 0.26.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -47,7 +47,7 @@ cert_chain:
47
47
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
48
48
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
49
49
  -----END CERTIFICATE-----
50
- date: 2024-04-16 00:00:00.000000000 Z
50
+ date: 2024-05-04 00:00:00.000000000 Z
51
51
  dependencies: []
52
52
  description:
53
53
  email:
@@ -55,7 +55,6 @@ executables: []
55
55
  extensions: []
56
56
  extra_rdoc_files: []
57
57
  files:
58
- - design.md
59
58
  - lib/protocol/http.rb
60
59
  - lib/protocol/http/accept_encoding.rb
61
60
  - lib/protocol/http/body/buffered.rb
@@ -99,6 +98,7 @@ licenses:
99
98
  - MIT
100
99
  metadata:
101
100
  documentation_uri: https://socketry.github.io/protocol-http/
101
+ source_code_uri: https://github.com/socketry/protocol-http.git
102
102
  post_install_message:
103
103
  rdoc_options: []
104
104
  require_paths:
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '3.0'
110
+ version: '3.1'
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
metadata.gz.sig CHANGED
Binary file
data/design.md DELETED
@@ -1,167 +0,0 @@
1
- # Middleware Design
2
-
3
- `Body::Writable` is a queue of String chunks.
4
-
5
- ## Request Response Model
6
-
7
- ~~~ruby
8
- class Request
9
- attr :verb
10
- attr :target
11
- attr :body
12
- end
13
-
14
- class Response
15
- attr :status
16
- attr :headers
17
- attr :body
18
- end
19
-
20
- def call(request)
21
- return response
22
- end
23
-
24
- def call(request)
25
- return @app.call(request)
26
- end
27
- ~~~
28
-
29
- ## Stream Model
30
-
31
- ~~~ruby
32
- class Stream
33
- attr :verb
34
- attr :target
35
-
36
- def respond(status, headers) = ...
37
-
38
- attr_accessor :input
39
- attr_accessor :output
40
- end
41
-
42
- class Response
43
- def initialize(verb, target)
44
- @input = Body::Writable.new
45
- @output = Body::Writable.new
46
- end
47
-
48
- def request(verb, target)
49
- # Create a request stream suitable for writing into the buffered response:
50
- Stream.new(verb, target, @input, @output)
51
- end
52
-
53
- def write(...)
54
- @input.write(...)
55
- end
56
-
57
- def read
58
- @output.read
59
- end
60
- end
61
-
62
- def call(stream)
63
- # nothing. maybe error
64
- end
65
-
66
- def call(stream)
67
- @app.call(stream)
68
- end
69
- ~~~
70
-
71
- # Client Design
72
-
73
- ## Request Response Model
74
-
75
- ~~~ruby
76
- request = Request.new("GET", url)
77
- response = call(request)
78
-
79
- response.headers
80
- response.read
81
- ~~~
82
-
83
- ## Stream Model
84
-
85
- ~~~ruby
86
- response = Response.new
87
- call(response.request("GET", url))
88
-
89
- response.headers
90
- response.read
91
- ~~~
92
-
93
- ## Differences
94
-
95
- The request/response model has a symmetrical design which naturally uses the return value for the result of executing the request. The result encapsulates the behaviour of how to read the response status, headers and body. Because of that, streaming input and output becomes a function of the result object itself. As in:
96
-
97
- ~~~ruby
98
- def call(request)
99
- body = Body::Writable.new
100
-
101
- Fiber.schedule do
102
- while chunk = request.input.read
103
- body.write(chunk.reverse)
104
- end
105
- end
106
-
107
- return Response[200, [], body]
108
- end
109
-
110
- input = Body::Writable.new
111
- response = call(... body ...)
112
-
113
- input.write("Hello World")
114
- input.close
115
- response.read -> "dlroW olleH"
116
- ~~~
117
-
118
- The streaming model does not have the same symmetry, and instead opts for a uni-directional flow of information.
119
-
120
- ~~~ruby
121
- def call(stream)
122
- Fiber.schedule do
123
- while chunk = stream.read
124
- stream.write(chunk.reverse)
125
- end
126
- end
127
- end
128
-
129
- input = Body::Writable.new
130
- response = Response.new(...input...)
131
- call(response.stream)
132
-
133
- input.write("Hello World")
134
- input.close
135
- response.read -> "dlroW olleH"
136
- ~~~
137
-
138
- The value of this uni-directional flow is that it is natural for the stream to be taken out of the scope imposed by the nested `call(request)` model. However, the user must explicitly close the stream, since it's no longer scoped to the client and/or server.
139
-
140
- ## Connection Upgrade
141
-
142
- ### HTTP/1
143
-
144
- ```
145
- GET /path/to/websocket HTTP/1.1
146
- connection: upgrade
147
- upgrade: websocket
148
- ```
149
-
150
- Request.new(GET, ..., protocol = websocket)
151
- -> Response.new(101, ..., protocol = websocket)
152
-
153
- ```
154
- 101 Switching Protocols
155
- upgrade: websocket
156
- ```
157
-
158
- ### HTTP/2
159
-
160
- ```
161
- :method CONNECT
162
- :path /path/to/websocket
163
- :protocol websocket
164
- ```
165
-
166
- Request.new(CONNECT, ..., protocol = websocket)
167
- -> Response.new(200, ..., protocol = websocket)