Class: SlowServer::ClientConfig
- Defined in:
- lib/slow_server/config.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#request_headers ⇒ Object
Returns the value of attribute request_headers.
-
#request_method ⇒ Object
Returns the value of attribute request_method.
-
#request_uri ⇒ Object
Returns the value of attribute request_uri.
Attributes inherited from Config
#chunk_delay, #chunks, #port, #response_delay
Instance Method Summary collapse
-
#initialize ⇒ ClientConfig
constructor
A new instance of ClientConfig.
- #opts ⇒ Object
- #parse ⇒ Object
Methods inherited from Config
Constructor Details
#initialize ⇒ ClientConfig
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
#host ⇒ Object
Returns the value of attribute host.
47 48 49 |
# File 'lib/slow_server/config.rb', line 47 def host @host end |
#request_headers ⇒ Object
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_method ⇒ Object
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_uri ⇒ Object
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
#opts ⇒ Object
57 58 59 60 61 62 |
# File 'lib/slow_server/config.rb', line 57 def opts opts = super opts. = "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 |
#parse ⇒ Object
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 |