Class: WEBrick::HTTPRequest
- Inherits:
-
Object
- Object
- WEBrick::HTTPRequest
- Defined in:
- lib/webrick/https.rb,
lib/webrick/httprequest.rb
Constant Summary collapse
- BODY_CONTAINABLE_METHODS =
[ "POST", "PUT" ]
- BUFSIZE =
1024*4
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
Header and entity body.
-
#header ⇒ Object
readonly
Header and entity body.
-
#host ⇒ Object
readonly
Request-URI.
-
#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
Request-URI.
-
#path_info ⇒ Object
Returns the value of attribute path_info.
-
#peeraddr ⇒ Object
readonly
Returns the value of attribute peeraddr.
-
#port ⇒ Object
readonly
Request-URI.
-
#query_string ⇒ Object
Returns the value of attribute query_string.
-
#raw_header ⇒ Object
readonly
Header and entity body.
-
#request_line ⇒ Object
readonly
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
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
Misc.
Instance Method Summary collapse
- #[](header_name) ⇒ Object
- #body(&block) ⇒ Object
- #content_length ⇒ Object
- #content_type ⇒ Object
- #each ⇒ Object
- #fixup ⇒ Object
-
#initialize(config) ⇒ HTTPRequest
constructor
A new instance of HTTPRequest.
- #keep_alive? ⇒ Boolean
- #meta_vars ⇒ Object
- #orig_meta_vars ⇒ Object
- #orig_parse ⇒ Object
- #orig_parse_uri ⇒ Object
- #parse(socket = nil) ⇒ Object
- #query ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(config) ⇒ 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 |
# File 'lib/webrick/httprequest.rb', line 45 def initialize(config) @config = config @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 = [] @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 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)
Header and entity body
34 35 36 |
# File 'lib/webrick/httprequest.rb', line 34 def end |
#header ⇒ Object (readonly)
Header and entity body
34 35 36 |
# File 'lib/webrick/httprequest.rb', line 34 def header @header end |
#host ⇒ Object (readonly)
Request-URI
30 31 32 |
# File 'lib/webrick/httprequest.rb', line 30 def host @host 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)
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 |
#port ⇒ Object (readonly)
Request-URI
30 31 32 |
# File 'lib/webrick/httprequest.rb', line 30 def port @port 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)
Header and entity body
34 35 36 |
# File 'lib/webrick/httprequest.rb', line 34 def raw_header @raw_header end |
#request_line ⇒ Object (readonly)
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)
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
Misc
39 40 41 |
# File 'lib/webrick/httprequest.rb', line 39 def user @user end |
Instance Method Details
#[](header_name) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/webrick/httprequest.rb', line 145 def [](header_name) if @header value = @header[header_name.downcase] value.empty? ? nil : value.join(", ") end end |
#body(&block) ⇒ Object
124 125 126 127 128 |
# File 'lib/webrick/httprequest.rb', line 124 def body(&block) block ||= Proc.new{|chunk| @body << chunk } read_body(@socket, block) @body.empty? ? nil : @body end |
#content_length ⇒ Object
137 138 139 |
# File 'lib/webrick/httprequest.rb', line 137 def content_length return Integer(self['content-length']) end |
#content_type ⇒ Object
141 142 143 |
# File 'lib/webrick/httprequest.rb', line 141 def content_type return self['content-type'] end |
#each ⇒ Object
152 153 154 155 156 157 |
# File 'lib/webrick/httprequest.rb', line 152 def each @header.each{|k, v| value = @header[k] yield(k, value.empty? ? nil : value.join(", ")) } end |
#fixup ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/webrick/httprequest.rb', line 171 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 |
#keep_alive? ⇒ Boolean
159 160 161 |
# File 'lib/webrick/httprequest.rb', line 159 def keep_alive? @keep_alive end |
#meta_vars ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/webrick/https.rb', line 44 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
42 |
# File 'lib/webrick/https.rb', line 42 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 |
#query ⇒ Object
130 131 132 133 134 135 |
# File 'lib/webrick/httprequest.rb', line 130 def query unless @query parse_query() end @query end |
#to_s ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/webrick/httprequest.rb', line 163 def to_s ret = @request_line.dup @raw_header.each{|line| ret << line } ret << CRLF ret << body if body ret end |