protocol-http 0.26.3 → 0.26.4

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: '0817ddd3e60c6de45f9e5a73ecedb00e60c11c8171bcddca6b1da0b3bc898708'
4
+ data.tar.gz: bac2be42911aab9457374fc16d80ca4db76e9b7b4a9bacb5d6937e63e5520298
5
5
  SHA512:
6
- metadata.gz: 8d243e058e7cd0dd9825c44de883e5badf0df4aa150608ffdc034e4c0259412d64699cb97e0132e2d9307bcf874a2ce67f03e02046d00c761415d71c5c0a7941
7
- data.tar.gz: 0d29c9fd133dede2b2d7a545405df8e64dcfb497477c1252bb34e41fffac7fc9540142b9d1961a146d2e4afcedc86fb4cb9ce2e75d55a5c1a5e4ac4c0ced8659
6
+ metadata.gz: f78f1dcb03b5d203fae96a278a2152ee938ac8256692bf379819d44742104bc3c310ed1e6ce09f652f71ac86a08b1157705e7500974a4b2cdfdba7a00ed5a6fb
7
+ data.tar.gz: 1bba3d55382e65a7a79f60c81d089c129dde3b4bc2ab5e550172797a86be0d962426d1beb4910710c96a418f5b4460c2578f34bcac15cb34e1e0f93f1fdcf253
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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
@@ -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
@@ -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
@@ -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.4"
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -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
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)