HTTPRequest

class
Superclass
Mongrel2::Request
Extended With
Loggability

The Mongrel2 HTTP Request class. Instances of this class represent an HTTP request from a Mongrel2 server.

Constants

HANDLED_HTTP_METHODS

HTTP verbs from RFC2616

Public Class Methods

anchor
response_class()

Override the type of response returned by this request type.

# File lib/mongrel2/httprequest.rb, line 27
def self::response_class
        return Mongrel2::HTTPResponse
end

Public Instance Methods

anchor
content_encoding()

Fetch the encoding type of the request's content, as set in its header.

# File lib/mongrel2/httprequest.rb, line 82
def content_encoding
        return self.headers.content_encoding
end
anchor
content_encoding=( type )

Set the request's encoding type.

# File lib/mongrel2/httprequest.rb, line 88
def content_encoding=( type )
        return self.headers.content_encoding = type
end
anchor
content_length()

Returns the size of the request's entity body, as specified by its 'Content-Length' header. Note that this may or may not correspond to the actual byte size of the body.

# File lib/mongrel2/httprequest.rb, line 63
def content_length
        return 0 unless self.header.member?( :content_length )
        return Integer( self.header.content_length )
end
anchor
content_type()

Fetch the mimetype of the request's content, as set in its header.

# File lib/mongrel2/httprequest.rb, line 70
def content_type
        return self.headers.content_type
end
anchor
content_type=( type )

Set the current request's Content-Type.

# File lib/mongrel2/httprequest.rb, line 76
def content_type=( type )
        return self.headers.content_type = type
end
anchor
keepalive?()

Return true if the request is an HTTP/1.1 request and its 'Connection' header indicates that the connection should stay open.

# File lib/mongrel2/httprequest.rb, line 39
def keepalive?
        unless self.headers[:version] == 'HTTP/1.1'
                self.log.debug "Not an http/1.1 request: not persistent"
                return false
        end
        conn_header = self.headers[:connection]
        if !conn_header
                self.log.debug "No Connection header: assume persistence"
                return true
        end

        if conn_header.split( /\s*,\s*/ ).include?( 'close' )
                self.log.debug "Connection: close header."
                return false
        else
                self.log.debug "Connection header didn't contain 'close': assume persistence"
                return true
        end
end
anchor
scheme()

Convenience method for getting the request's 'url-scheme' header.

# File lib/mongrel2/httprequest.rb, line 94
def scheme
        return self.headers.url_scheme || 'http'
end
anchor
secure?()
Alias for: ssl?
anchor
ssl?()

Returns true if the request's URL scheme indicates that it used an HTTPS connection. This only works on versions of Mongrel2 after 1.8.0.

# File lib/mongrel2/httprequest.rb, line 101
def ssl?
        return self.scheme == 'https'
end
Also aliased as: used_ssl? , secure?
anchor
used_ssl?()
Alias for: ssl?

Protected Instance Methods

anchor
inspect_details()

Return the details to include in the contents of the inspected object.

# File lib/mongrel2/httprequest.rb, line 113
def inspect_details
        body_size = self.body.size || 0

        return %Q{[%s] "%s %s %s" -- %0.2fK body} % [
                self.headers.x_forwarded_for,
                self.headers[:method],
                self.headers.uri,
                self.headers.version,
                (body_size / 1024.0),
        ]
end