module Middleman::CoreExtensions::Request::InstanceMethods
def process_request(env, req, res)
-
res
(Rack::Response
) -- -
req
(Rack::Request
) -- -
env
() --
def process_request(env, req, res) start_time = Time.now @current_path = nil request_path = URI.decode(env["PATH_INFO"].dup) if request_path.respond_to? :force_encoding request_path.force_encoding('UTF-8') end request_path = full_path(request_path) # Run before callbacks run_hook :before # Get the resource object for this path resource = sitemap.find_resource_by_destination_path(request_path) # Return 404 if not in sitemap return not_found(res, request_path) unless resource && !resource.ignored? current_path = resource.destination_path # If this path is a static file, send it immediately return send_file(resource.source_file, env, res) unless resource.template? # Set a HTTP content type based on the request's extensions content_type(res, resource.mime_type) begin # Write out the contents of the page output = resource.render do self.req = req self.current_path = current_path end res.write output # Valid content is a 200 status res.status = 200 rescue Middleman::CoreExtensions::Rendering::TemplateNotFound => e res.write "Error: #{e.message}" res.status = 500 end # End the request logger.debug "== Finishing Request: #{current_path} (#{(Time.now - start_time).round(2)}s)" halt res.finish end