module Middleman::CoreExtensions::Request::InstanceMethods

def process_request(env, req, res)

Parameters:
  • res (Rack::Response) --
  • req (Rack::Request) --
  • env () --
def process_request(env, req, res)
  start_time = Time.now
  # Normalize the path and add index if we're looking at a directory
  original_path = URI.decode(env["PATH_INFO"].dup)
  if original_path.respond_to? :force_encoding
    original_path.force_encoding('UTF-8')
  end
  request_path  = full_path(original_path)
  # Run before callbacks
  run_hook :before
  if original_path != request_path
    # Get the resource object for this path
    resource = sitemap.find_resource_by_destination_path(original_path)
  end
  # Get the resource object for this full path
  resource ||= sitemap.find_resource_by_destination_path(request_path)
  # Return 404 if not in sitemap
  return not_found(res) unless resource && !resource.ignored?
  # If this path is a static file, send it immediately
  return send_file(resource.source_file, env, res) unless resource.template?
  # Set the current path for use in helpers
  self.current_path = request_path.dup
  # 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
    res.write resource.render
    # 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
  puts "== Finishing Request: #{self.current_path} (#{(Time.now - start_time).round(2)}s)" if logging?
  halt res.finish
end