summaryrefslogtreecommitdiff
path: root/lib/webrick/httprequest.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/webrick/httprequest.rb')
-rw-r--r--lib/webrick/httprequest.rb55
1 files changed, 46 insertions, 9 deletions
diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb
index d179995d77..5dda878e99 100644
--- a/lib/webrick/httprequest.rb
+++ b/lib/webrick/httprequest.rb
@@ -15,23 +15,27 @@ require 'webrick/httputils'
require 'webrick/cookie'
module WEBrick
+
+ ##
+ # An HTTP request.
class HTTPRequest
+
BODY_CONTAINABLE_METHODS = [ "POST", "PUT" ]
- # Request line
+ # :section: Request line
attr_reader :request_line
attr_reader :request_method, :unparsed_uri, :http_version
- # Request-URI
+ # :section: Request-URI
attr_reader :request_uri, :path
attr_accessor :script_name, :path_info, :query_string
- # Header and entity body
+ # :section: Header and entity body
attr_reader :raw_header, :header, :cookies
attr_reader :accept, :accept_charset
attr_reader :accept_encoding, :accept_language
- # Misc
+ # :section:
attr_accessor :user
attr_reader :addr, :peeraddr
attr_reader :attributes
@@ -137,6 +141,9 @@ module WEBrick
@body.empty? ? nil : @body
end
+ ##
+ # Request query as a Hash
+
def query
unless @query
parse_query()
@@ -144,14 +151,23 @@ module WEBrick
@query
end
+ ##
+ # The content-length header
+
def content_length
return Integer(self['content-length'])
end
+ ##
+ # The content-type header
+
def content_type
return self['content-type']
end
+ ##
+ # Retrieves +header_name+
+
def [](header_name)
if @header
value = @header[header_name.downcase]
@@ -159,6 +175,9 @@ module WEBrick
end
end
+ ##
+ # Iterates over the request headers
+
def each
@header.each{|k, v|
value = @header[k]
@@ -166,31 +185,49 @@ module WEBrick
}
end
+ ##
+ # The host this request is for
+
def host
return @forwarded_host || @host
end
+ ##
+ # The port this request is for
+
def port
return @forwarded_port || @port
end
+ ##
+ # The server name this request is for
+
def server_name
return @forwarded_server || @config[:ServerName]
end
+ ##
+ # The client's IP address
+
def remote_ip
return self["client-ip"] || @forwarded_for || @peeraddr[3]
end
+ ##
+ # Is this an SSL request?
+
def ssl?
return @request_uri.scheme == "https"
end
+ ##
+ # Should the connection this request was made on be kept alive?
+
def keep_alive?
@keep_alive
end
- def to_s
+ def to_s # :nodoc:
ret = @request_line.dup
@raw_header.each{|line| ret << line }
ret << CRLF
@@ -210,11 +247,11 @@ module WEBrick
end
end
- def meta_vars
- # This method provides the metavariables defined by the revision 3
- # of ``The WWW Common Gateway Interface Version 1.1''.
- # (http://Web.Golux.Com/coar/cgi/)
+ # This method provides the metavariables defined by the revision 3
+ # of "The WWW Common Gateway Interface Version 1.1"
+ # http://Web.Golux.Com/coar/cgi/
+ def meta_vars
meta = Hash.new
cl = self["Content-Length"]