Class: SlowServer::ClientConfig

Inherits:
Config
  • Object
show all
Defined in:
lib/slow_server/config.rb

Instance Attribute Summary collapse

Attributes inherited from Config

#chunk_delay, #chunks, #port, #response_delay

Instance Method Summary collapse

Methods inherited from Config

#args

Constructor Details

#initializeClientConfig

Returns a new instance of ClientConfig.



49
50
51
52
53
54
55
# File 'lib/slow_server/config.rb', line 49

def initialize
  super
  self.request_method = 'GET'
  self.host = 'localhost'
  self.request_uri = "/"
  self.request_headers = []
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



47
48
49
# File 'lib/slow_server/config.rb', line 47

def host
  @host
end

#request_headersObject

Returns the value of attribute request_headers.



47
48
49
# File 'lib/slow_server/config.rb', line 47

def request_headers
  @request_headers
end

#request_methodObject

Returns the value of attribute request_method.



47
48
49
# File 'lib/slow_server/config.rb', line 47

def request_method
  @request_method
end

#request_uriObject

Returns the value of attribute request_uri.



47
48
49
# File 'lib/slow_server/config.rb', line 47

def request_uri
  @request_uri
end

Instance Method Details

#optsObject



57
58
59
60
61
62
# File 'lib/slow_server/config.rb', line 57

def opts
  opts = super
  opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] [URI]"
  opts.on_head("-p", "--port NUMBER",            Integer, "Listen Port                         (default: #{self.port})")           { |v| @port_override = v }
  opts.on_head("-X", "--method METHOD",          String,  "Request Method                      (default: #{self.request_method})") { |v| self.request_method = v }
end

#parseObject



64
65
66
67
68
69
70
71
72
# File 'lib/slow_server/config.rb', line 64

def parse
  uri = URI.parse(args[0])
  if !uri.respond_to?(:request_uri) && uri !~ %r{^\w+:\/\/}
    uri = URI.parse("http://#{uri}")
  end
  self.host = uri.host
  self.port = @port_override || uri.port
  self.request_uri = uri.request_uri if uri.request_uri
end