File tree 2 files changed +3
-94
lines changed
2 files changed +3
-94
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
spec . add_dependency "async-pool" , "~> 0.7"
29
29
spec . add_dependency "io-endpoint" , "~> 0.11"
30
30
spec . add_dependency "io-stream" , "~> 0.4"
31
- spec . add_dependency "protocol-http" , "~> 0.30 "
31
+ spec . add_dependency "protocol-http" , "~> 0.33 "
32
32
spec . add_dependency "protocol-http1" , "~> 0.20"
33
33
spec . add_dependency "protocol-http2" , "~> 0.18"
34
34
spec . add_dependency "traces" , ">= 0.10"
Original file line number Diff line number Diff line change 3
3
# Released under the MIT License.
4
4
# Copyright, 2018-2023, by Samuel Williams.
5
5
6
- require 'protocol/http/body/readable '
6
+ require 'protocol/http/body/writable '
7
7
require 'async/queue'
8
8
9
9
module Async
10
10
module HTTP
11
11
module Body
12
- include ::Protocol ::HTTP ::Body
13
-
14
- # A dynamic body which you can write to and read from.
15
- class Writable < Readable
16
- class Closed < StandardError
17
- end
18
-
19
- # @param [Integer] length The length of the response body if known.
20
- # @param [Async::Queue] queue Specify a different queue implementation, e.g. `Async::LimitedQueue.new(8)` to enable back-pressure streaming.
21
- def initialize ( length = nil , queue : Async ::Queue . new )
22
- @queue = queue
23
-
24
- @length = length
25
-
26
- @count = 0
27
-
28
- @finished = false
29
-
30
- @closed = false
31
- @error = nil
32
- end
33
-
34
- def length
35
- @length
36
- end
37
-
38
- # Stop generating output; cause the next call to write to fail with the given error.
39
- def close ( error = nil )
40
- unless @closed
41
- @queue . enqueue ( nil )
42
-
43
- @closed = true
44
- @error = error
45
- end
46
-
47
- super
48
- end
49
-
50
- def closed?
51
- @closed
52
- end
53
-
54
- def ready?
55
- !@queue . empty?
56
- end
57
-
58
- # Has the producer called #finish and has the reader consumed the nil token?
59
- def empty?
60
- @finished
61
- end
62
-
63
- # Read the next available chunk.
64
- def read
65
- return if @finished
66
-
67
- unless chunk = @queue . dequeue
68
- @finished = true
69
- end
70
-
71
- return chunk
72
- end
73
-
74
- # Write a single chunk to the body. Signal completion by calling `#finish`.
75
- def write ( chunk )
76
- # If the reader breaks, the writer will break.
77
- # The inverse of this is less obvious (*)
78
- if @closed
79
- raise ( @error || Closed )
80
- end
81
-
82
- @count += 1
83
- @queue . enqueue ( chunk )
84
- end
85
-
86
- alias << write
87
-
88
- def inspect
89
- "\# <#{ self . class } #{ @count } chunks written, #{ status } >"
90
- end
91
-
92
- private
93
-
94
- def status
95
- if @finished
96
- 'finished'
97
- elsif @closed
98
- 'closing'
99
- else
100
- 'waiting'
101
- end
102
- end
103
- end
12
+ Writable = ::Protocol ::HTTP ::Body ::Writable
104
13
end
105
14
end
106
15
end
You can’t perform that action at this time.
0 commit comments