Class: Sinatra::Request

### Home Classes Methods

### In Files

- lib/sinatra/base.rb

### Parent

Rack::Request

### Namespace

- CLASS Sinatra::Request::AcceptEntry

### Methods

- #accept
- #accept?
- #forwarded?
- #idempotent?
- #link?
- #preferred_type
- #safe?
- #unlink?

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Sinatra
- Sinatra::Application
- Sinatra::CommonLogger
- Sinatra::ExtendedRack
- Sinatra::Helpers
- Sinatra::Helpers::Stream
- Sinatra::Helpers::Stream::Application
- Sinatra::Helpers::Stream::Base
- Sinatra::Helpers::Stream::Templates
- Sinatra::Helpers::Stream::Templates::ContentTyped
- Sinatra::Helpers::Stream::Wrapper
- Sinatra::Request
- Sinatra::Request::AcceptEntry
- Sinatra::Response
- Sinatra::ShowExceptions
- Rack
- Rack::Builder

No matching classes.

# Sinatra::Request

The request object. See Rack::Request for more info: rack.rubyforge.org/doc/classes/Rack/Request.html

### Constants

HEADER_PARAM
HEADER_VALUE_WITH_PARAMS

### Public Instance Methods

accept() click to toggle source

Returns an array of acceptable media types for the response

    # File lib/sinatra/base.rb, line 23
    def accept
      @env['sinatra.accept'] ||= begin
        if @env.include? 'HTTP_ACCEPT' and @env['HTTP_ACCEPT'].to_s != ''
          @env['HTTP_ACCEPT'].to_s.scan(HEADER_VALUE_WITH_PARAMS).
            map! { |e| AcceptEntry.new(e) }.sort
        else
          [AcceptEntry.new('*/*')]
        end
      end
    end

accept?(type) click to toggle source

    # File lib/sinatra/base.rb, line 34
    def accept?(type)
      preferred_type(type).include?(type)
    end

forwarded?() click to toggle source

    # File lib/sinatra/base.rb, line 51
    def forwarded?
      @env.include? "HTTP_X_FORWARDED_HOST"
    end

idempotent?() click to toggle source

    # File lib/sinatra/base.rb, line 59
    def idempotent?
      safe? or put? or delete? or link? or unlink?
    end

link?() click to toggle source

    # File lib/sinatra/base.rb, line 63
    def link?
      request_method == "LINK"
    end

preferred_type(*types) click to toggle source

    # File lib/sinatra/base.rb, line 38
    def preferred_type(*types)
      accepts = accept # just evaluate once
      return accepts.first if types.empty?
      types.flatten!
      return types.first if accepts.empty?
      accepts.detect do |pattern|
        type = types.detect { |t| File.fnmatch(pattern, t) }
        return type if type
      end
    end

safe?() click to toggle source

    # File lib/sinatra/base.rb, line 55
    def safe?
      get? or head? or options? or trace?
    end

unlink?() click to toggle source

    # File lib/sinatra/base.rb, line 67
    def unlink?
      request_method == "UNLINK"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.