class RequestParsers::OcciParser
Constants
- AVAILABLE_PARSERS
Public Class Methods
new(app)
click to toggle source
# File lib/request_parsers/occi_parser.rb, line 16 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/request_parsers/occi_parser.rb, line 20 def call(env) request = ::ActionDispatch::Request.new(env) # make a copy of the request body @body = request.body.respond_to?(:read) ? request.body.read : request.body.string @body = Marshal.load(Marshal.dump(@body)) # save copy some additional information @media_type = request.media_type.to_s @headers = sanitize_request_headers(request.headers) @fullpath = request.fullpath.to_s env['rocci_server.request.parser'] = self @app.call(env) end
parse_occi_messages(entity_type = nil)
click to toggle source
# File lib/request_parsers/occi_parser.rb, line 36 def parse_occi_messages(entity_type = nil) fail ::Errors::UnsupportedMediaTypeError, "Media type '#{@media_type}' is not supported by the RequestParser" unless AVAILABLE_PARSERS.key?(@media_type) collection = if entity_type AVAILABLE_PARSERS[@media_type].parse(@media_type, @body, @headers, @fullpath, entity_type) else AVAILABLE_PARSERS[@media_type].parse(@media_type, @body, @headers, @fullpath) end Rails.logger.debug "[Parser] [#{self.class}] Parsed request into coll=#{collection.inspect}" collection end