Class: Rex::Proto::Http::Response

Inherits:
Packet
  • Object
show all
Defined in:
lib/rex/proto/http/response.rb

Overview

HTTP response class.

Direct Known Subclasses

E404, OK

Defined Under Namespace

Classes: E404, OK, UnitTest

Instance Attribute Summary collapse

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

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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rex/proto/http/response.rb', line 43

def initialize(code = 200, message = 'OK', proto = DefaultProtocol)
	super()

	self.code    = code.to_i
	self.message = message
	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
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



84
85
86
# File 'lib/rex/proto/http/response.rb', line 84

def code
  @code
end

#messageObject

Returns the value of attribute message.



85
86
87
# File 'lib/rex/proto/http/response.rb', line 85

def message
  @message
end

#protoObject

Returns the value of attribute proto.



86
87
88
# File 'lib/rex/proto/http/response.rb', line 86

def proto
  @proto
end

#requestObject

Used to store a copy of the original request



81
82
83
# File 'lib/rex/proto/http/response.rb', line 81

def request
  @request
end

Instance Method Details

#cmd_stringObject

Returns the response based command string.



74
75
76
# File 'lib/rex/proto/http/response.rb', line 74

def cmd_string
	"HTTP\/#{proto} #{code}#{(message and message.length > 0) ? ' ' + message : ''}\r\n"
end

#update_cmd_parts(str) ⇒ Object

Updates the various parts of the HTTP response command string.



61
62
63
64
65
66
67
68
69
# File 'lib/rex/proto/http/response.rb', line 61

def update_cmd_parts(str)
	if (md = str.match(/HTTP\/(.+?)\s+(\d+)\s?(.+?)\r?\n?$/))
		self.message = md[3].gsub(/\r/, '')
		self.code    = md[2].to_i
		self.proto   = md[1]
	else
		raise RuntimeError, "Invalid response command string", caller
	end
end