Class: Webmachine::Adapters::Rack::RequestBody Private
- Inherits:
-
Object
- Object
- Webmachine::Adapters::Rack::RequestBody
- Defined in:
- lib/webmachine/adapters/rack.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Wraps the Rack input so it can be treated like a String or Enumerable.
Instance Method Summary collapse
-
#each {|chunk| ... } ⇒ Object
private
Iterates over the body in chunks.
-
#initialize(request) ⇒ RequestBody
constructor
private
A new instance of RequestBody.
-
#to_io ⇒ IO
private
Rack Servers differ in the way you can access their request bodys.
-
#to_s ⇒ String
private
Converts the body to a String so you can work with the entire thing.
Constructor Details
#initialize(request) ⇒ RequestBody
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RequestBody.
227 228 229 |
# File 'lib/webmachine/adapters/rack.rb', line 227 def initialize(request) @request = request end |
Instance Method Details
#each {|chunk| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterates over the body in chunks. If the body has previously been read, this method can be called again and get the same sequence of chunks.
261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/webmachine/adapters/rack.rb', line 261 def each if @value @value.each { |chunk| yield chunk } else @value = [] @request.body.each { |chunk| @value << chunk yield chunk } end end |
#to_io ⇒ IO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Rack Servers differ in the way you can access their request bodys. While some allow you to directly get a Ruby IO object others don't. You have to check the methods they expose, like #gets, #read, #each, #rewind and maybe others. See: https://github.com/rack/rack/blob/rack-1.5/lib/rack/lint.rb#L296
236 237 238 |
# File 'lib/webmachine/adapters/rack.rb', line 236 def to_io @request.body end |
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the body to a String so you can work with the entire thing.
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/webmachine/adapters/rack.rb', line 243 def to_s if @value @value.join else # Rack 3 removed the requirement for rack.input to implement #rewind # (Rack::Lint::InputWrapper in Rack 3 does not define it), so guard # the call to avoid a NoMethodError on every PUT/POST request. body = @request.body body.rewind if body.respond_to?(:rewind) body.read end end |