Sha256: 2cab57004556c116793207db26f2b3cda10bcb2e73500ae9022f3fb92319c5f3
Contents?: true
Size: 1.77 KB
Versions: 2
Compression:
Stored size: 1.77 KB
Contents
class Rack::App::Endpoint attr_reader :properties LAST_MODIFIED_HEADER = "Last-Modified".freeze def initialize(properties) @properties = properties @error_handler = properties[:error_handler] @serializer = properties[:serializer] @api_class = properties[:app_class] @headers = properties[:default_headers] @path_params_matcher = {} @endpoint_method_name = register_method_to_app_class(properties[:user_defined_logic]) end def call(request_env) request = Rack::Request.new(request_env) response = Rack::Response.new set_response_body(response, get_response_body(request, response)) return response.finish end def get_response_body(rack_request, rack_response) request_handler = @api_class.new set_default_headers(rack_response) request_handler.request = rack_request request_handler.response = rack_response rack_request.env['rack.app.path_params_matcher']= @path_params_matcher.dup return @error_handler.execute_with_error_handling_for(request_handler, @endpoint_method_name) end def register_path_params_matcher(params_matcher) @path_params_matcher.merge!(params_matcher) end protected def set_response_body(response, result) if result.is_a?(::Rack::App::File::Streamer) response.length += result.length response.headers[LAST_MODIFIED_HEADER]= result.mtime response.body = result else response.write(String(@serializer.serialize(result))) end nil end def set_default_headers(response) @headers.each do |header, value| response.header[header]=value end end def register_method_to_app_class(proc) method_name = ::Rack::App::Utils.uuid @api_class.__send__(:define_method, method_name, &proc) return method_name end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rack-app-0.19.0 | lib/rack/app/endpoint.rb |
rack-app-0.18.0 | lib/rack/app/endpoint.rb |