def dispatch(req)
      debug_log(req)

      response = Response.new
      @request = req

      if ! @request.valid?
        response.body = handle_invalid_request
        response.code = :error
      else
        begin
          debug_log("do lookup for #{@request.selector}")
          @params, block = lookup(@request.selector)

          #
          # call the block that handles this lookup
          #
          response.body = block.bind(self).call
          response.code = :success
        rescue Gopher::NotFoundError => e
          debug_log("#{@request.selector} -- not found")
          response.body = handle_not_found
          response.code = :missing
        rescue Exception => e
          debug_log("#{@request.selector} -- error")
          debug_log(e.inspect)
          debug_log(e.backtrace)

          response.body = handle_error(e)
          response.code = :error
        end
      end

      access_log(req, response)
      response
    end
def dispatch(req)
      debug_log(req)

      response = Response.new
      @request = req

      if ! @request.valid?
        response.body = handle_invalid_request
        response.code = :error
      else
        begin
          debug_log("do lookup for #{@request.selector}")
          @params, block = lookup(@request.selector)

          #
          # call the block that handles this lookup
          #
          response.body = block.bind(self).call
          response.code = :success
        rescue Gopher::NotFoundError => e
          debug_log("#{@request.selector} -- not found")
          response.body = handle_not_found
          response.code = :missing
        rescue Exception => e
          debug_log("#{@request.selector} -- error")
          debug_log(e.inspect)
          debug_log(e.backtrace)

          response.body = handle_error(e)
          response.code = :error
        end
      end

      access_log(req, response)
      response
    end
find and run the first route which matches the incoming request
 @param [Request] req Gopher::Request object