def process_request(env, req, res)
      start_time = Time.now

      request_path = URI.decode(env['PATH_INFO'].dup)
      request_path.force_encoding('UTF-8') if request_path.respond_to? :force_encoding
      request_path = ::Middleman::Util.full_path(request_path, @middleman)
      full_request_path = File.join(env['SCRIPT_NAME'], request_path) # Path including rack mount

      # Get the resource object for this path
      resource = @middleman.sitemap.by_destination_path(request_path.gsub(' ', '%20'))

      # Return 404 if not in sitemap
      return not_found(res, full_request_path) unless resource && !resource.ignored?

      # If this path is a binary file, send it immediately
      return send_file(resource, env) if resource.binary? || resource.static_file?

      res['Content-Type'] = resource.content_type || 'text/plain'

      begin
        # Write out the contents of the page
        res.write resource.render({}, rack: { request: req })

        # Valid content is a 200 status
        res.status = 200
      rescue Middleman::TemplateRenderer::TemplateNotFound => e
        res.write "Error: #{e.message}"
        res.status = 500
      end

      # End the request
      logger.debug "== Finishing Request: #{resource.destination_path} (#{(Time.now - start_time).round(2)}s)"
      halt res.finish
    end
def process_request(env, req, res)
      start_time = Time.now

      request_path = URI.decode(env['PATH_INFO'].dup)
      request_path.force_encoding('UTF-8') if request_path.respond_to? :force_encoding
      request_path = ::Middleman::Util.full_path(request_path, @middleman)
      full_request_path = File.join(env['SCRIPT_NAME'], request_path) # Path including rack mount

      # Get the resource object for this path
      resource = @middleman.sitemap.by_destination_path(request_path.gsub(' ', '%20'))

      # Return 404 if not in sitemap
      return not_found(res, full_request_path) unless resource && !resource.ignored?

      # If this path is a binary file, send it immediately
      return send_file(resource, env) if resource.binary? || resource.static_file?

      res['Content-Type'] = resource.content_type || 'text/plain'

      begin
        # Write out the contents of the page
        res.write resource.render({}, rack: { request: req })

        # Valid content is a 200 status
        res.status = 200
      rescue Middleman::TemplateRenderer::TemplateNotFound => e
        res.write "Error: #{e.message}"
        res.status = 500
      end

      # End the request
      logger.debug "== Finishing Request: #{resource.destination_path} (#{(Time.now - start_time).round(2)}s)"
      halt res.finish
    end
Core response method. We process the request, check with
 the sitemap, and return the correct file, response or status
 message.

 @param env
 @param [Rack::Request] req
 @param [Rack::Response] res