Class: Rex::Proto::Http::Response
- Defined in:
- lib/rex/proto/http/response.rb
Overview
HTTP response class.
Defined Under Namespace
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#count_100 ⇒ Object
Returns the value of attribute count_100.
-
#message ⇒ Object
Returns the value of attribute message.
-
#proto ⇒ Object
Returns the value of attribute proto.
-
#request ⇒ Object
Used to store a copy of the original request.
Attributes inherited from Packet
#auto_cl, #body, #bufq, #chunk_max_size, #chunk_min_size, #compress, #error, #headers, #incomplete, #max_data, #state, #transfer_chunked
Instance Method Summary collapse
-
#check_100 ⇒ Object
Allow 100 Continues to be ignored by the caller.
-
#cmd_string ⇒ Object
Returns the response based command string.
-
#get_cookies ⇒ Object
Gets cookies from the Set-Cookie header in a format to be used in the ‘cookie’ send_request field.
-
#initialize(code = 200, message = 'OK', proto = DefaultProtocol) ⇒ Response
constructor
Constructage of the HTTP response with the supplied code, message, and protocol.
-
#redirect? ⇒ Boolean
Answers if the response is a redirection one.
-
#redirection ⇒ URI?
Provides the uri of the redirection location.
-
#update_cmd_parts(str) ⇒ Object
Updates the various parts of the HTTP response command string.
Methods inherited from Packet
#[], #[]=, #chunk, #completed?, #from_s, #parse, #reset, #reset_except_queue, #to_s
Constructor Details
#initialize(code = 200, message = 'OK', proto = DefaultProtocol) ⇒ Response
Constructage of the HTTP response with the supplied code, message, and protocol.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rex/proto/http/response.rb', line 44 def initialize(code = 200, = 'OK', proto = DefaultProtocol) super() self.code = code.to_i self. = self.proto = proto # Default responses to auto content length on self.auto_cl = true # default chunk sizes (if chunked is used) self.chunk_min_size = 1 self.chunk_max_size = 10 # 100 continue counter self.count_100 = 0 end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
143 144 145 |
# File 'lib/rex/proto/http/response.rb', line 143 def code @code end |
#count_100 ⇒ Object
Returns the value of attribute count_100.
146 147 148 |
# File 'lib/rex/proto/http/response.rb', line 146 def count_100 @count_100 end |
#message ⇒ Object
Returns the value of attribute message.
144 145 146 |
# File 'lib/rex/proto/http/response.rb', line 144 def @message end |
#proto ⇒ Object
Returns the value of attribute proto.
145 146 147 |
# File 'lib/rex/proto/http/response.rb', line 145 def proto @proto end |
#request ⇒ Object
Used to store a copy of the original request
140 141 142 |
# File 'lib/rex/proto/http/response.rb', line 140 def request @request end |
Instance Method Details
#check_100 ⇒ Object
Allow 100 Continues to be ignored by the caller
103 104 105 106 107 108 109 |
# File 'lib/rex/proto/http/response.rb', line 103 def check_100 # If this was a 100 continue with no data, reset if self.code == 100 and (self.body_bytes_left == -1 or self.body_bytes_left == 0) and self.count_100 < 5 self.reset_except_queue self.count_100 += 1 end end |
#cmd_string ⇒ Object
Returns the response based command string.
133 134 135 |
# File 'lib/rex/proto/http/response.rb', line 133 def cmd_string "HTTP\/#{proto} #{code}#{( and .length > 0) ? ' ' + : ''}\r\n" end |
#get_cookies ⇒ Object
Gets cookies from the Set-Cookie header in a format to be used in the ‘cookie’ send_request field
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rex/proto/http/response.rb', line 66 def = "" if (self.headers.include?('Set-Cookie')) = self.headers['Set-Cookie'] key_vals = .scan(/\s?([^, ;]+?)=([^, ;]*?)[;,]/) key_vals.each do |k, v| # Dont downcase actual cookie name as may be case sensitive name = k.downcase next if name == 'path' next if name == 'expires' next if name == 'domain' next if name == 'max-age' << "#{k}=#{v}; " end end return .strip end |
#redirect? ⇒ Boolean
Answers if the response is a redirection one.
114 115 116 |
# File 'lib/rex/proto/http/response.rb', line 114 def redirect? [301, 302, 303, 307, 308].include?(code) end |
#redirection ⇒ URI?
Provides the uri of the redirection location.
122 123 124 125 126 127 128 |
# File 'lib/rex/proto/http/response.rb', line 122 def redirection begin URI(headers['Location']) rescue ::URI::InvalidURIError nil end end |
#update_cmd_parts(str) ⇒ Object
Updates the various parts of the HTTP response command string.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rex/proto/http/response.rb', line 88 def update_cmd_parts(str) if (md = str.match(/HTTP\/(.+?)\s+(\d+)\s?(.+?)\r?\n?$/)) self. = md[3].gsub(/\r/, '') self.code = md[2].to_i self.proto = md[1] else raise RuntimeError, "Invalid response command string", caller end check_100() end |