Class: Webmachine::Adapters::Rack::RequestBody Private

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • request (Rack::Request)

    the Rack request



149
150
151
# File 'lib/webmachine/adapters/rack.rb', line 149

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.

Yields:

  • (chunk)

Yield Parameters:

  • chunk (String)

    a chunk of the request body



179
180
181
182
183
184
185
186
# File 'lib/webmachine/adapters/rack.rb', line 179

def each
  if @value
    @value.each {|chunk| yield chunk }
  else
    @value = []
    @request.body.each {|chunk| @value << chunk; yield chunk }
  end
end

#to_ioIO

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: github.com/rack/rack/blob/rack-1.5/lib/rack/lint.rb#L296

Returns:

  • (IO)

    the request body



158
159
160
# File 'lib/webmachine/adapters/rack.rb', line 158

def to_io
  @request.body
end

#to_sString

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.

Returns:

  • (String)

    the request body as a string



165
166
167
168
169
170
171
172
# File 'lib/webmachine/adapters/rack.rb', line 165

def to_s
  if @value
    @value.join
  else
    @request.body.rewind
    @request.body.read
  end
end