Class: WEBrick::HTTPRequest
- Inherits:
-
Object
- Object
- WEBrick::HTTPRequest
- Defined in:
- lib/webrick/httprequest.rb,
lib/webrick/https.rb
Overview
An HTTP request.
Constant Summary collapse
- BODY_CONTAINABLE_METHODS =
[ "POST", "PUT" ]
Instance Attribute Summary collapse
-
#accept ⇒ Object
readonly
Returns the value of attribute accept.
-
#accept_charset ⇒ Object
readonly
Returns the value of attribute accept_charset.
-
#accept_encoding ⇒ Object
readonly
Returns the value of attribute accept_encoding.
-
#accept_language ⇒ Object
readonly
Returns the value of attribute accept_language.
-
#addr ⇒ Object
readonly
Returns the value of attribute addr.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#cipher ⇒ Object
readonly
Returns the value of attribute cipher.
-
#client_cert ⇒ Object
readonly
Returns the value of attribute client_cert.
-
#cookies ⇒ Object
readonly
:section: Header and entity body.
-
#header ⇒ Object
readonly
:section: Header and entity body.
-
#http_version ⇒ Object
readonly
Returns the value of attribute http_version.
-
#keep_alive ⇒ Object
readonly
Returns the value of attribute keep_alive.
-
#path ⇒ Object
readonly
:section: Request-URI.
-
#path_info ⇒ Object
Returns the value of attribute path_info.
-
#peeraddr ⇒ Object
readonly
Returns the value of attribute peeraddr.
-
#query_string ⇒ Object
Returns the value of attribute query_string.
-
#raw_header ⇒ Object
readonly
:section: Header and entity body.
-
#request_line ⇒ Object
readonly
:section: Request line.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#request_time ⇒ Object
readonly
Returns the value of attribute request_time.
-
#request_uri ⇒ Object
readonly
:section: Request-URI.
-
#script_name ⇒ Object
Returns the value of attribute script_name.
-
#server_cert ⇒ Object
readonly
Returns the value of attribute server_cert.
-
#unparsed_uri ⇒ Object
readonly
Returns the value of attribute unparsed_uri.
-
#user ⇒ Object
:section:.
Instance Method Summary collapse
-
#[](header_name) ⇒ Object
Retrieves
header_name
. - #body(&block) ⇒ Object
-
#content_length ⇒ Object
The content-length header.
-
#content_type ⇒ Object
The content-type header.
-
#continue ⇒ Object
Generate HTTP/1.1 100 continue response if the client expects it, otherwise does nothing.
-
#each ⇒ Object
Iterates over the request headers.
- #fixup ⇒ Object
-
#host ⇒ Object
The host this request is for.
-
#initialize(config) ⇒ HTTPRequest
constructor
A new instance of HTTPRequest.
-
#keep_alive? ⇒ Boolean
Should the connection this request was made on be kept alive?.
-
#meta_vars ⇒ Object
This method provides the metavariables defined by the revision 3 of “The WWW Common Gateway Interface Version 1.1” Web.Golux.Com/coar/cgi/.
- #orig_meta_vars ⇒ Object
- #orig_parse ⇒ Object
- #orig_parse_uri ⇒ Object
- #parse(socket = nil) ⇒ Object
-
#port ⇒ Object
The port this request is for.
-
#query ⇒ Object
Request query as a Hash.
-
#remote_ip ⇒ Object
The client’s IP address.
-
#server_name ⇒ Object
The server name this request is for.
-
#ssl? ⇒ Boolean
Is this an SSL request?.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(config) ⇒ HTTPRequest
Returns a new instance of HTTPRequest.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/webrick/httprequest.rb', line 45 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 ⇒ Object (readonly)
Returns the value of attribute accept.
35 36 37 |
# File 'lib/webrick/httprequest.rb', line 35 def accept @accept end |
#accept_charset ⇒ Object (readonly)
Returns the value of attribute accept_charset.
35 36 37 |
# File 'lib/webrick/httprequest.rb', line 35 def accept_charset @accept_charset end |
#accept_encoding ⇒ Object (readonly)
Returns the value of attribute accept_encoding.
36 37 38 |
# File 'lib/webrick/httprequest.rb', line 36 def accept_encoding @accept_encoding end |
#accept_language ⇒ Object (readonly)
Returns the value of attribute accept_language.
36 37 38 |
# File 'lib/webrick/httprequest.rb', line 36 def accept_language @accept_language end |
#addr ⇒ Object (readonly)
Returns the value of attribute addr.
40 41 42 |
# File 'lib/webrick/httprequest.rb', line 40 def addr @addr end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
41 42 43 |
# File 'lib/webrick/httprequest.rb', line 41 def attributes @attributes end |
#cipher ⇒ Object (readonly)
Returns the value of attribute cipher.
19 20 21 |
# File 'lib/webrick/https.rb', line 19 def cipher @cipher end |
#client_cert ⇒ Object (readonly)
Returns the value of attribute client_cert.
19 20 21 |
# File 'lib/webrick/https.rb', line 19 def client_cert @client_cert end |
#cookies ⇒ Object (readonly)
:section: Header and entity body
34 35 36 |
# File 'lib/webrick/httprequest.rb', line 34 def @cookies end |
#header ⇒ Object (readonly)
:section: Header and entity body
34 35 36 |
# File 'lib/webrick/httprequest.rb', line 34 def header @header end |
#http_version ⇒ Object (readonly)
Returns the value of attribute http_version.
27 28 29 |
# File 'lib/webrick/httprequest.rb', line 27 def http_version @http_version end |
#keep_alive ⇒ Object (readonly)
Returns the value of attribute keep_alive.
42 43 44 |
# File 'lib/webrick/httprequest.rb', line 42 def keep_alive @keep_alive end |
#path ⇒ Object (readonly)
:section: Request-URI
30 31 32 |
# File 'lib/webrick/httprequest.rb', line 30 def path @path end |
#path_info ⇒ Object
Returns the value of attribute path_info.
31 32 33 |
# File 'lib/webrick/httprequest.rb', line 31 def path_info @path_info end |
#peeraddr ⇒ Object (readonly)
Returns the value of attribute peeraddr.
40 41 42 |
# File 'lib/webrick/httprequest.rb', line 40 def peeraddr @peeraddr end |
#query_string ⇒ Object
Returns the value of attribute query_string.
31 32 33 |
# File 'lib/webrick/httprequest.rb', line 31 def query_string @query_string end |
#raw_header ⇒ Object (readonly)
:section: Header and entity body
34 35 36 |
# File 'lib/webrick/httprequest.rb', line 34 def raw_header @raw_header end |
#request_line ⇒ Object (readonly)
:section: Request line
26 27 28 |
# File 'lib/webrick/httprequest.rb', line 26 def request_line @request_line end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
27 28 29 |
# File 'lib/webrick/httprequest.rb', line 27 def request_method @request_method end |
#request_time ⇒ Object (readonly)
Returns the value of attribute request_time.
43 44 45 |
# File 'lib/webrick/httprequest.rb', line 43 def request_time @request_time end |
#request_uri ⇒ Object (readonly)
:section: Request-URI
30 31 32 |
# File 'lib/webrick/httprequest.rb', line 30 def request_uri @request_uri end |
#script_name ⇒ Object
Returns the value of attribute script_name.
31 32 33 |
# File 'lib/webrick/httprequest.rb', line 31 def script_name @script_name end |
#server_cert ⇒ Object (readonly)
Returns the value of attribute server_cert.
19 20 21 |
# File 'lib/webrick/https.rb', line 19 def server_cert @server_cert end |
#unparsed_uri ⇒ Object (readonly)
Returns the value of attribute unparsed_uri.
27 28 29 |
# File 'lib/webrick/httprequest.rb', line 27 def unparsed_uri @unparsed_uri end |
#user ⇒ Object
:section:
39 40 41 |
# File 'lib/webrick/httprequest.rb', line 39 def user @user end |
Instance Method Details
#[](header_name) ⇒ Object
Retrieves header_name
171 172 173 174 175 176 |
# File 'lib/webrick/httprequest.rb', line 171 def [](header_name) if @header value = @header[header_name.downcase] value.empty? ? nil : value.join(", ") end end |
#body(&block) ⇒ Object
138 139 140 141 142 |
# File 'lib/webrick/httprequest.rb', line 138 def body(&block) block ||= Proc.new{|chunk| @body << chunk } read_body(@socket, block) @body.empty? ? nil : @body end |
#content_length ⇒ Object
The content-length header
157 158 159 |
# File 'lib/webrick/httprequest.rb', line 157 def content_length return Integer(self['content-length']) end |
#content_type ⇒ Object
The content-type header
164 165 166 |
# File 'lib/webrick/httprequest.rb', line 164 def content_type return self['content-type'] end |
#continue ⇒ Object
Generate HTTP/1.1 100 continue response if the client expects it, otherwise does nothing.
131 132 133 134 135 136 |
# File 'lib/webrick/httprequest.rb', line 131 def continue if self['expect'] == '100-continue' && @config[:HTTPVersion] >= "1.1" @socket << "HTTP/#{@config[:HTTPVersion]} 100 continue#{CRLF}#{CRLF}" @header.delete('expect') end end |
#each ⇒ Object
Iterates over the request headers
181 182 183 184 185 186 187 188 |
# File 'lib/webrick/httprequest.rb', line 181 def each if @header @header.each{|k, v| value = @header[k] yield(k, value.empty? ? nil : value.join(", ")) } end end |
#fixup ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/webrick/httprequest.rb', line 240 def fixup() begin body{|chunk| } # read remaining body rescue HTTPStatus::Error => ex @logger.error("HTTPRequest#fixup: #{ex.class} occured.") @keep_alive = false rescue => ex @logger.error(ex) @keep_alive = false end end |
#host ⇒ Object
The host this request is for
193 194 195 |
# File 'lib/webrick/httprequest.rb', line 193 def host return @forwarded_host || @host end |
#keep_alive? ⇒ Boolean
Should the connection this request was made on be kept alive?
228 229 230 |
# File 'lib/webrick/httprequest.rb', line 228 def keep_alive? @keep_alive end |
#meta_vars ⇒ Object
This method provides the metavariables defined by the revision 3 of “The WWW Common Gateway Interface Version 1.1” Web.Golux.Com/coar/cgi/
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/webrick/httprequest.rb', line 256 def = if server_cert ["HTTPS"] = "on" ["SSL_SERVER_CERT"] = @server_cert.to_pem ["SSL_CLIENT_CERT"] = @client_cert ? @client_cert.to_pem : "" if @client_cert_chain @client_cert_chain.each_with_index{|cert, i| ["SSL_CLIENT_CERT_CHAIN_#{i}"] = cert.to_pem } end ["SSL_CIPHER"] = @cipher[0] ["SSL_PROTOCOL"] = @cipher[1] ["SSL_CIPHER_USEKEYSIZE"] = @cipher[2].to_s ["SSL_CIPHER_ALGKEYSIZE"] = @cipher[3].to_s end end |
#orig_meta_vars ⇒ Object
43 |
# File 'lib/webrick/https.rb', line 43 alias |
#orig_parse ⇒ Object
21 |
# File 'lib/webrick/https.rb', line 21 alias orig_parse parse |
#orig_parse_uri ⇒ Object
33 |
# File 'lib/webrick/https.rb', line 33 alias orig_parse_uri parse_uri |
#parse(socket = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/webrick/https.rb', line 23 def parse(socket=nil) if socket.respond_to?(:cert) @server_cert = socket.cert || @config[:SSLCertificate] @client_cert = socket.peer_cert @client_cert_chain = socket.peer_cert_chain @cipher = socket.cipher end orig_parse(socket) end |
#port ⇒ Object
The port this request is for
200 201 202 |
# File 'lib/webrick/httprequest.rb', line 200 def port return @forwarded_port || @port end |
#query ⇒ Object
Request query as a Hash
147 148 149 150 151 152 |
# File 'lib/webrick/httprequest.rb', line 147 def query unless @query parse_query() end @query end |
#remote_ip ⇒ Object
The client’s IP address
214 215 216 |
# File 'lib/webrick/httprequest.rb', line 214 def remote_ip return self["client-ip"] || @forwarded_for || @peeraddr[3] end |
#server_name ⇒ Object
The server name this request is for
207 208 209 |
# File 'lib/webrick/httprequest.rb', line 207 def server_name return @forwarded_server || @config[:ServerName] end |
#ssl? ⇒ Boolean
Is this an SSL request?
221 222 223 |
# File 'lib/webrick/httprequest.rb', line 221 def ssl? return @request_uri.scheme == "https" end |
#to_s ⇒ Object
:nodoc:
232 233 234 235 236 237 238 |
# File 'lib/webrick/httprequest.rb', line 232 def to_s # :nodoc: ret = @request_line.dup @raw_header.each{|line| ret << line } ret << CRLF ret << body if body ret end |