class Esplanade::Request::Raw::Body

Public Class Methods

new(raw_request, env) click to toggle source
# File lib/esplanade/request/raw/body.rb, line 7
def initialize(raw_request, env)
  @raw_request = raw_request
  @env = env
end

Public Instance Methods

reduced_version() click to toggle source
# File lib/esplanade/request/raw/body.rb, line 26
def reduced_version
  @reduced_version ||= if to_string && to_string.size >= 1000
                         "#{to_string[0..499]}...#{to_string[500..-1]}"
                       else
                         to_string
                       end
end
to_hash() click to toggle source
# File lib/esplanade/request/raw/body.rb, line 20
def to_hash
  @hash ||= MultiJson.load(to_string)
rescue MultiJson::ParseError
  raise BodyIsNotJson.new(**message)
end
to_string() click to toggle source
# File lib/esplanade/request/raw/body.rb, line 12
def to_string
  return @string if @string

  @string = @env['rack.input'].read
  @env['rack.input'].rewind
  @string
end

Private Instance Methods

message() click to toggle source
# File lib/esplanade/request/raw/body.rb, line 36
def message
  {
    method: @raw_request.method,
    path: @raw_request.path,
    raw_path: @raw_request.raw_path,
    content_type: @raw_request.content_type,
    body: reduced_version
  }
end