protocol-http 0.34.0 → 0.35.0

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: cb1197435097557cab74b1b61b92fe0a15a938892dd07486ee9f9db06360decd
4
- data.tar.gz: 78bcbbd73817b03ce63b55b2bbd4408afeaeaa127e3c19f9dfd5d6ddb120f05d
3
+ metadata.gz: b60538bc2a8f661748e6a70b92bf46932440e56f69e0cb22348fa14b0c59706f
4
+ data.tar.gz: 9a6629a169c0afff229eed8b660fc94c918cc9f0a953e5251b5f5f283e4e28fa
5
5
  SHA512:
6
- metadata.gz: 34db4e5940f59773708692bc080706be457f9f41445b6858e01da474f0ba36aba31d8d8c2f3ccd329f2120f412d9c4bcc42c568c057db3e0cef816c83ab34db1
7
- data.tar.gz: 23baab35d26b5b367fa556d4a302f81680b944fef07b2ca0a581fab7b36ac8320cb3c4a62cdc50f8cfd21efb408eee01e348c06b4c538a5cfbcf8cd6ce99b28f
6
+ metadata.gz: 707f195fa9b7b2bfe446b6a2132dfe608570ec8fed696c8df558686e80da07c5026fac90941109dc7d743e3806daf8fdfb4d28ce051ba1412242b8fde4f45a99
7
+ data.tar.gz: 41a940d1dee93bc30d90fc0ae63fa34103d82379862c502a2ec11ec6f06521491e8eb6586ef43707957ff8ebc7f7016e893ad3b88751e93fdcf14976de8227d2
checksums.yaml.gz.sig CHANGED
Binary file
@@ -273,8 +273,8 @@ module Protocol
273
273
 
274
274
  # Close the input and output bodies.
275
275
  def close(error = nil)
276
- self.close_read
277
- self.close_write
276
+ self.close_read(error)
277
+ self.close_write(error)
278
278
 
279
279
  return nil
280
280
  ensure
@@ -17,20 +17,12 @@ module Protocol
17
17
  #
18
18
  # When invoking `call(stream)`, the stream can be read from and written to, and closed. However, the stream is only guaranteed to be open for the duration of the `call(stream)` call. Once the method returns, the stream **should** be closed by the server.
19
19
  module Streamable
20
- def self.new(*arguments)
21
- if arguments.size == 1
22
- DeferredBody.new(*arguments)
23
- else
24
- Body.new(*arguments)
25
- end
26
- end
27
-
28
20
  def self.request(&block)
29
- DeferredBody.new(block)
21
+ RequestBody.new(block)
30
22
  end
31
23
 
32
24
  def self.response(request, &block)
33
- Body.new(block, request.body)
25
+ ResponseBody.new(block, request.body)
34
26
  end
35
27
 
36
28
  class Output
@@ -109,32 +101,37 @@ module Protocol
109
101
  raise
110
102
  end
111
103
 
112
- # Closing a stream indicates we are no longer interested in reading from it.
113
- def close(error = nil)
114
- if output = @output
115
- @output = nil
116
- # Closing the output here may take some time, as it may need to finish handling the stream:
117
- output.close(error)
118
- end
119
-
104
+ def close_input(error = nil)
120
105
  if input = @input
121
106
  @input = nil
122
107
  input.close(error)
123
108
  end
124
109
  end
110
+
111
+ def close_output(error = nil)
112
+ @output&.close(error)
113
+ end
125
114
  end
126
115
 
127
- # A deferred body has an extra `stream` method which can be used to stream data into the body, as the response body won't be available until the request has been sent.
128
- class DeferredBody < Body
116
+ # A response body is used on the server side to generate the response body using a block.
117
+ class ResponseBody < Body
118
+ def close(error = nil)
119
+ # Close will be invoked when all the output is written.
120
+ self.close_output(error)
121
+ end
122
+ end
123
+
124
+ # A request body is used on the client side to generate the request body using a block.
125
+ #
126
+ # As the response body isn't available until the request is sent, the response body must be {stream}ed into the request body.
127
+ class RequestBody < Body
129
128
  def initialize(block)
130
129
  super(block, Writable.new)
131
130
  end
132
131
 
133
- # Closing a stream indicates we are no longer interested in reading from it, but in this case that does not mean that the output block is finished generating data.
134
132
  def close(error = nil)
135
- if error
136
- super
137
- end
133
+ # Close will be invoked when all the input is read.
134
+ self.close_input(error)
138
135
  end
139
136
 
140
137
  # Stream the response body into the block's input.
@@ -143,7 +140,6 @@ module Protocol
143
140
  @input.write(chunk)
144
141
  end
145
142
  rescue => error
146
- raise
147
143
  ensure
148
144
  @input.close_write(error)
149
145
  end
@@ -55,7 +55,14 @@ module Protocol
55
55
  raise @error
56
56
  end
57
57
 
58
- @queue.pop
58
+ # This operation may result in @error being set.
59
+ chunk = @queue.pop
60
+
61
+ if @error
62
+ raise @error
63
+ end
64
+
65
+ return chunk
59
66
  end
60
67
 
61
68
  # Write a single chunk to the body. Signal completion by calling `#finish`.
@@ -118,7 +125,11 @@ module Protocol
118
125
  end
119
126
 
120
127
  def inspect
121
- "\#<#{self.class} #{@count} chunks written, #{status}>"
128
+ if @error
129
+ "\#<#{self.class} #{@count} chunks written, #{status}, error=#{@error}>"
130
+ else
131
+ "\#<#{self.class} #{@count} chunks written, #{status}>"
132
+ end
122
133
  end
123
134
 
124
135
  private
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.34.0"
8
+ VERSION = "0.35.0"
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.34.0
4
+ version: 0.35.0
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-09-10 00:00:00.000000000 Z
50
+ date: 2024-09-16 00:00:00.000000000 Z
51
51
  dependencies: []
52
52
  description:
53
53
  email:
metadata.gz.sig CHANGED
Binary file