Class: WEBrick::HTTPRequest
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/webrick/https.rb, lib/webrick/httprequest.rb |
Request line
-
#http_version
readonly
The HTTP version of the request.
-
#request_line
readonly
The complete request line such as:
-
#request_method
readonly
The request method, GET, POST, PUT, etc.
-
#unparsed_uri
readonly
The unparsed URI of the request.
Request-URI
-
#path
readonly
The request path.
-
#path_info
rw
The path info (CGI variable).
-
#query_string
rw
The query from the URI of the request.
-
#request_uri
readonly
The parsed URI of the request.
-
#script_name
rw
The script name (CGI variable).
Header and entity body
-
#accept
readonly
The Accept header value.
-
#accept_charset
readonly
The Accept-Charset header value.
-
#accept_encoding
readonly
The Accept-Encoding header value.
-
#accept_language
readonly
The Accept-Language header value.
-
#cookies
readonly
The parsed request cookies.
-
#header
readonly
The parsed header of the request.
-
#raw_header
readonly
The raw header of the request.
Class Method Summary
-
.new(config) ⇒ HTTPRequest
constructor
Creates a new HTTP request.
Instance Attribute Summary
-
#user
rw
The remote user (CGI variable).
-
#addr
readonly
The socket address of the server.
-
#attributes
readonly
Hash of request attributes.
-
#cipher
readonly
HTTP request SSL cipher.
-
#client_cert
readonly
HTTP request client certificate.
-
#keep_alive
readonly
Is this a keep-alive connection?
-
#keep_alive? ⇒ Boolean
readonly
Should the connection this request was made on be kept alive?
-
#peeraddr
readonly
The socket address of the client.
-
#request_time
readonly
The local time this request was received.
-
#server_cert
readonly
HTTP request server certificate.
-
#ssl? ⇒ Boolean
readonly
Is this an SSL request?
Instance Method Summary
-
#[](header_name)
Retrieves
header_name
-
#body(&block)
Returns the request body.
-
#content_length
The content-length header.
-
#content_type
The content-type header.
-
#each
Iterates over the request headers.
-
#host
The host this request is for.
-
#port
The port this request is for.
-
#query
Request query as a Hash.
-
#remote_ip
The client's IP address.
-
#server_name
The server name this request is for.
Constructor Details
.new(config) ⇒ HTTPRequest
Creates a new HTTP request. Config::HTTP is the default configuration.
# File 'lib/webrick/httprequest.rb', line 152
def initialize(config) @config = config @buffer_size = @config[:InputBufferSize] @logger = config[:Logger] @request_line = @request_method = @unparsed_uri = @http_version = nil @request_uri = @host = @port = @path = nil @script_name = @path_info = nil @query_string = nil @query = nil @form_data = nil @raw_header = Array.new @header = nil @cookies = [] @accept = [] @accept_charset = [] @accept_encoding = [] @accept_language = [] @body = "" @addr = @peeraddr = nil @attributes = {} @user = nil @keep_alive = false @request_time = nil @remaining_size = nil @socket = nil @forwarded_proto = @forwarded_host = @forwarded_port = @forwarded_server = @forwarded_for = nil end
Instance Attribute Details
#accept (readonly)
The Accept header value
# File 'lib/webrick/httprequest.rb', line 99
attr_reader :accept
#accept_charset (readonly)
The Accept-Charset header value
# File 'lib/webrick/httprequest.rb', line 104
attr_reader :accept_charset
#accept_encoding (readonly)
The Accept-Encoding header value
# File 'lib/webrick/httprequest.rb', line 109
attr_reader :accept_encoding
#accept_language (readonly)
The Accept-Language header value
# File 'lib/webrick/httprequest.rb', line 114
attr_reader :accept_language
#addr (readonly)
The socket address of the server
# File 'lib/webrick/httprequest.rb', line 126
attr_reader :addr
#attributes (readonly)
Hash of request attributes
# File 'lib/webrick/httprequest.rb', line 136
attr_reader :attributes
#cipher (readonly)
HTTP request SSL cipher
# File 'lib/webrick/https.rb', line 28
attr_reader :cipher
#client_cert (readonly)
HTTP request client certificate
# File 'lib/webrick/https.rb', line 38
attr_reader :client_cert
#cookies (readonly)
The parsed request cookies
# File 'lib/webrick/httprequest.rb', line 94
attr_reader :
#header (readonly)
The parsed header of the request
# File 'lib/webrick/httprequest.rb', line 89
attr_reader :header
#http_version (readonly)
The HTTP version of the request
# File 'lib/webrick/httprequest.rb', line 50
attr_reader :http_version
#keep_alive (readonly)
Is this a keep-alive connection?
# File 'lib/webrick/httprequest.rb', line 141
attr_reader :keep_alive
#keep_alive? ⇒ Boolean
(readonly)
Should the connection this request was made on be kept alive?
# File 'lib/webrick/httprequest.rb', line 344
def keep_alive? @keep_alive end
#path (readonly)
The request path
# File 'lib/webrick/httprequest.rb', line 62
attr_reader :path
#path_info (rw)
The path info (CGI variable)
# File 'lib/webrick/httprequest.rb', line 72
attr_accessor :path_info
#peeraddr (readonly)
The socket address of the client
# File 'lib/webrick/httprequest.rb', line 131
attr_reader :peeraddr
#query_string (rw)
The query from the URI of the request
# File 'lib/webrick/httprequest.rb', line 77
attr_accessor :query_string
#raw_header (readonly)
The raw header of the request
# File 'lib/webrick/httprequest.rb', line 84
attr_reader :raw_header
#request_line (readonly)
The complete request line such as:
GET / HTTP/1.1
# File 'lib/webrick/httprequest.rb', line 35
attr_reader :request_line
#request_method (readonly)
The request method, GET, POST, PUT, etc.
# File 'lib/webrick/httprequest.rb', line 40
attr_reader :request_method
#request_time (readonly)
The local time this request was received
# File 'lib/webrick/httprequest.rb', line 146
attr_reader :request_time
#request_uri (readonly)
The parsed URI of the request
# File 'lib/webrick/httprequest.rb', line 57
attr_reader :request_uri
#script_name (rw)
The script name (CGI variable)
# File 'lib/webrick/httprequest.rb', line 67
attr_accessor :script_name
#server_cert (readonly)
HTTP request server certificate
# File 'lib/webrick/https.rb', line 33
attr_reader :server_cert
#ssl? ⇒ Boolean
(readonly)
Is this an SSL request?
# File 'lib/webrick/httprequest.rb', line 337
def ssl? return @request_uri.scheme == "https" end
#unparsed_uri (readonly)
The unparsed URI of the request
# File 'lib/webrick/httprequest.rb', line 45
attr_reader :unparsed_uri
#user (rw)
The remote user (CGI variable)
# File 'lib/webrick/httprequest.rb', line 121
attr_accessor :user
Instance Method Details
#[](header_name)
Retrieves header_name
# File 'lib/webrick/httprequest.rb', line 287
def [](header_name) if @header value = @header[header_name.downcase] value.empty? ? nil : value.join(", ") end end
#body(&block)
Returns the request body.
#content_length
The content-length header
# File 'lib/webrick/httprequest.rb', line 273
def content_length return Integer(self['content-length']) end
#content_type
The content-type header
# File 'lib/webrick/httprequest.rb', line 280
def content_type return self['content-type'] end
#each
Iterates over the request headers
# File 'lib/webrick/httprequest.rb', line 297
def each if @header @header.each{|k, v| value = @header[k] yield(k, value.empty? ? nil : value.join(", ")) } end end
#host
The host this request is for
# File 'lib/webrick/httprequest.rb', line 309
def host return @forwarded_host || @host end
#port
The port this request is for
# File 'lib/webrick/httprequest.rb', line 316
def port return @forwarded_port || @port end
#query
Request query as a Hash
# File 'lib/webrick/httprequest.rb', line 263
def query unless @query parse_query() end @query end
#remote_ip
The client's IP address
# File 'lib/webrick/httprequest.rb', line 330
def remote_ip return self["client-ip"] || @forwarded_for || @peeraddr[3] end
#server_name
The server name this request is for
# File 'lib/webrick/httprequest.rb', line 323
def server_name return @forwarded_server || @config[:ServerName] end