mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/webrick: Add Documentation
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7e3ec1db0d
commit
071a678a15
12 changed files with 591 additions and 18 deletions
|
@ -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"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue