Class: Mongrel2::HTTPRequest

Inherits:
Request
  • Object
show all
Extended by:
Loggability
Defined in:
lib/mongrel2/httprequest.rb

Overview

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

Direct Known Subclasses

WebSocket::ClientHandshake

Constant Summary collapse

HANDLED_HTTP_METHODS =

HTTP verbs from RFC2616

[ :OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE, :CONNECT ]

Instance Attribute Summary

Attributes inherited from Request

#body, #conn_id, #headers, #path, #raw, #sender_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

#extended_reply?, #initialize, #inspect, #is_disconnect?, parse, register_request_type, #remote_ip, #response, #server_chroot, #socket_id, subclass_for_method, #upload_done?, #upload_headers_match?, #upload_started?, #uploaded_file, #valid_upload?

Constructor Details

This class inherits a constructor from Mongrel2::Request

Class Method Details

.response_classObject

Override the type of response returned by this request type.



28
29
30
# File 'lib/mongrel2/httprequest.rb', line 28

def self::response_class
  return Mongrel2::HTTPResponse
end

Instance Method Details

#content_encodingObject

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



83
84
85
# File 'lib/mongrel2/httprequest.rb', line 83

def content_encoding
  return self.headers.content_encoding
end

#content_encoding=(type) ⇒ Object

Set the request’s encoding type.



89
90
91
# File 'lib/mongrel2/httprequest.rb', line 89

def content_encoding=( type )
  return self.headers.content_encoding = type
end

#content_lengthObject

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.



64
65
66
67
# File 'lib/mongrel2/httprequest.rb', line 64

def content_length
  return 0 unless self.header.member?( :content_length )
  return Integer( self.header.content_length )
end

#content_typeObject

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



71
72
73
# File 'lib/mongrel2/httprequest.rb', line 71

def content_type
  return self.headers.content_type
end

#content_type=(type) ⇒ Object

Set the current request’s Content-Type.



77
78
79
# File 'lib/mongrel2/httprequest.rb', line 77

def content_type=( type )
  return self.headers.content_type = type
end

#keepalive?Boolean

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

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mongrel2/httprequest.rb', line 40

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

#schemeObject

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



95
96
97
# File 'lib/mongrel2/httprequest.rb', line 95

def scheme
  return self.headers.url_scheme || 'http'
end

#ssl?Boolean Also known as: used_ssl?, secure?

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.

Returns:

  • (Boolean)


102
103
104
# File 'lib/mongrel2/httprequest.rb', line 102

def ssl?
  return self.scheme == 'https'
end