Class: Rex::Proto::Nuuo::ClientRequest
- Inherits:
-
Object
- Object
- Rex::Proto::Nuuo::ClientRequest
- Defined in:
- lib/rex/proto/nuuo/client_request.rb
Constant Summary collapse
- DefaultConfig =
{ # # Nuuo stuff # 'method' => 'USERLOGIN', 'server_version' => nil, 'data' => nil, 'headers' => nil, 'proto' => 'NUCM', 'version' => '1.0', 'file_name' => nil, 'file_type' => nil, 'user_session' => nil, }
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ ClientRequest
constructor
A new instance of ClientRequest.
- #set_body ⇒ Object
-
#set_extra_headers ⇒ Object
Return additional headers.
- #set_formatted_header(var, val) ⇒ Object
-
#set_header(key, name) ⇒ Object
Return <name> header.
- #set_method ⇒ Object
- #set_proto_version ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ ClientRequest
Returns a new instance of ClientRequest.
26 27 28 29 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 26 def initialize(opts={}) @opts = DefaultConfig.merge(opts) @opts['headers'] ||= {} end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
24 25 26 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 24 def opts @opts end |
Instance Method Details
#set_body ⇒ Object
78 79 80 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 78 def set_body return "\r\n#{opts['data']}" end |
#set_extra_headers ⇒ Object
Return additional headers
69 70 71 72 73 74 75 76 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 69 def set_extra_headers buf = '' opts['headers'].each_pair do |var,val| buf << set_formatted_header(var,val) end buf end |
#set_formatted_header(var, val) ⇒ Object
82 83 84 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 82 def set_formatted_header(var, val) "#{var}: #{val}\r\n" end |
#set_header(key, name) ⇒ Object
Return <name> header
60 61 62 63 64 65 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 60 def set_header(key, name) unless opts['headers'] && opts['headers'].keys.map(&:downcase).include?(name.downcase) return opts[key] ? set_formatted_header(name, opts[key]) : '' end '' end |
#set_method ⇒ Object
49 50 51 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 49 def set_method "#{opts['method']}" end |
#set_proto_version ⇒ Object
53 54 55 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 53 def set_proto_version "#{opts['proto']}/#{opts['version']}\r\n" end |
#to_s ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rex/proto/nuuo/client_request.rb', line 31 def to_s # Set default header: <method> <proto/version> req = '' req << set_method req << ' ' req << set_proto_version # Set headers req << set_header('server_version', 'Version') req << set_header('user_session', 'User-Session-No') # Add any additional headers req << set_extra_headers # Set data req << set_body end |