module Roda::RodaPlugins::TypeRouting::RequestMethods

def _remaining_path(env)

the requested type if so.
Removes a trailing file extension from the path, and sets
def _remaining_path(env)
  opts = scope.opts[:type_routing]
  path = super
  if opts[:use_extension]
    if m = opts[:extension_regexp].match(path)
      @type_routing_extension =  @requested_type = m[2].to_sym
      path = m[1]
    end
  end
  path
end

def accept_response_type

The response type indicated by the Accept request header.
def accept_response_type
  mimes = @scope.opts[:type_routing][:mimes]
  @env['HTTP_ACCEPT'].to_s.split(/\s*,\s*/).map do |part|
    mime, _= part.split(/\s*;\s*/, 2)
    if sym = mimes[mime]
      response[RodaResponseHeaders::VARY] = (vary = response[RodaResponseHeaders::VARY]) ? "#{vary}, Accept" : 'Accept'
      return sym
    end
  end
  nil
end

def on_type(type, &block)

the request afterwards, returning the result of the block.
Yields if the given +type+ matches the requested data type and halts
def on_type(type, &block)
  return unless type == requested_type
  response[RodaResponseHeaders::CONTENT_TYPE] ||= @scope.opts[:type_routing][:types][type]
  always(&block)
end

def real_remaining_path

removed before routing.
Append the type routing extension back to the path if it was
def real_remaining_path
  if defined?(@type_routing_extension)
    "#{super}.#{@type_routing_extension}"
  else
    super
  end
end

def requested_type

Returns the data type the client requests.
def requested_type
  return @requested_type if defined?(@requested_type)
  opts = @scope.opts[:type_routing]
  @requested_type = accept_response_type if opts[:use_header]
  @requested_type ||= opts[:default_type]
end