Module: Protocol::Rack::Body
- Defined in:
- lib/protocol/rack/body.rb,
lib/protocol/rack/body/streaming.rb,
lib/protocol/rack/body/enumerable.rb,
lib/protocol/rack/body/input_wrapper.rb
Defined Under Namespace
Classes: Enumerable, InputWrapper, Streaming
Constant Summary
collapse
- CONTENT_LENGTH =
'content-length'
Class Method Summary
collapse
Class Method Details
.completion_callback(response_finished, env, status, headers) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/protocol/rack/body.rb', line 47
def self.completion_callback(response_finished, env, status, )
proc do |error|
response_finished.each do |callback|
callback.call(env, status, , error)
end
end
end
|
.wrap(env, status, headers, body, input = nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/protocol/rack/body.rb', line 15
def self.wrap(env, status, , body, input = nil)
if length = .delete(CONTENT_LENGTH)
length = Integer(length)
end
if body.is_a?(::Protocol::HTTP::Body::Readable)
elsif status == 200 and body.respond_to?(:to_path)
begin
body = ::Protocol::HTTP::Body::File.open(body.to_path).tap do
body.close if body.respond_to?(:close) end
rescue Errno::ENOENT
end
elsif body.respond_to?(:each)
body = Body::Enumerable.wrap(body, length)
else
body = Body::Streaming.new(body, input)
end
if response_finished = env[RACK_RESPONSE_FINISHED] and response_finished.any?
body = ::Protocol::HTTP::Body::Completable.new(body, completion_callback(response_finished, env, status, ))
end
return body
end
|