2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-07-24 20:53:54 +00:00
|
|
|
require 'rex/proto/http'
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Proto
|
|
|
|
module Http
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# HTTP response class.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Response < Packet
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Builtin response class wrappers.
|
|
|
|
#
|
2012-05-24 23:10:26 +00:00
|
|
|
##
|
2005-07-24 20:53:54 +00:00
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# HTTP 200/OK response class wrapper.
|
|
|
|
#
|
2005-07-24 20:53:54 +00:00
|
|
|
class OK < Response
|
|
|
|
def initialize(message = 'OK', proto = DefaultProtocol)
|
|
|
|
super(200, message, proto)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# HTTP 404/File not found response class wrapper.
|
|
|
|
#
|
2005-07-24 20:53:54 +00:00
|
|
|
class E404 < Response
|
|
|
|
def initialize(message = 'File not found', proto = DefaultProtocol)
|
|
|
|
super(404, message, proto)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Constructage of the HTTP response with the supplied code, message, and
|
|
|
|
# protocol.
|
2005-07-24 20:53:54 +00:00
|
|
|
#
|
|
|
|
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
|
2006-01-05 22:20:28 +00:00
|
|
|
|
2006-01-25 21:57:30 +00:00
|
|
|
# default chunk sizes (if chunked is used)
|
|
|
|
self.chunk_min_size = 1
|
|
|
|
self.chunk_max_size = 10
|
2012-10-29 03:57:18 +00:00
|
|
|
|
|
|
|
# 100 continue counter
|
|
|
|
self.count_100 = 0
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Updates the various parts of the HTTP response command string.
|
|
|
|
#
|
|
|
|
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]
|
2005-07-25 02:18:37 +00:00
|
|
|
else
|
|
|
|
raise RuntimeError, "Invalid response command string", caller
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
2012-10-29 03:57:18 +00:00
|
|
|
|
|
|
|
check_100()
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Allow 100 Continues to be ignored by the caller
|
|
|
|
#
|
|
|
|
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
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the response based command string.
|
|
|
|
#
|
|
|
|
def cmd_string
|
|
|
|
"HTTP\/#{proto} #{code}#{(message and message.length > 0) ? ' ' + message : ''}\r\n"
|
|
|
|
end
|
|
|
|
|
2010-11-13 05:25:39 +00:00
|
|
|
#
|
|
|
|
# Used to store a copy of the original request
|
|
|
|
#
|
2012-05-24 23:10:26 +00:00
|
|
|
attr_accessor :request
|
|
|
|
|
|
|
|
|
|
|
|
attr_accessor :code
|
2005-07-24 20:53:54 +00:00
|
|
|
attr_accessor :message
|
|
|
|
attr_accessor :proto
|
2012-10-29 03:57:18 +00:00
|
|
|
attr_accessor :count_100
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2010-11-13 05:25:39 +00:00
|
|
|
end
|