Class: HttpClientOptions
- Inherits:
-
Object
- Object
- HttpClientOptions
- Defined in:
- lib/em-http/http_client_options.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#compressed ⇒ Object
readonly
Returns the value of attribute compressed.
-
#decoding ⇒ Object
readonly
Returns the value of attribute decoding.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#followed ⇒ Object
Returns the value of attribute followed.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#keepalive ⇒ Object
readonly
Returns the value of attribute keepalive.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#pass_cookies ⇒ Object
readonly
Returns the value of attribute pass_cookies.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#redirects ⇒ Object
Returns the value of attribute redirects.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #follow_redirect? ⇒ Boolean
-
#initialize(uri, options, method) ⇒ HttpClientOptions
constructor
A new instance of HttpClientOptions.
- #no_body? ⇒ Boolean
- #set_uri(uri, path = nil, query = nil) ⇒ Object
- #ssl? ⇒ Boolean
Constructor Details
#initialize(uri, options, method) ⇒ HttpClientOptions
Returns a new instance of HttpClientOptions.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/em-http/http_client_options.rb', line 8 def initialize(uri, , method) @keepalive = [:keepalive] || false # default to single request per connection @redirects = [:redirects] ||= 0 # default number of redirects to follow @followed = [:followed] ||= 0 # keep track of number of followed requests @method = method.to_s.upcase @headers = [:head] || {} @file = [:file] @body = [:body] @pass_cookies = .fetch(:pass_cookies, true) # pass cookies between redirects @decoding = .fetch(:decoding, true) # auto-decode compressed response @compressed = .fetch(:compressed, true) # auto-negotiated compressed response set_uri(uri, [:path], [:query]) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/em-http/http_client_options.rb', line 3 def body @body end |
#compressed ⇒ Object (readonly)
Returns the value of attribute compressed.
4 5 6 |
# File 'lib/em-http/http_client_options.rb', line 4 def compressed @compressed end |
#decoding ⇒ Object (readonly)
Returns the value of attribute decoding.
4 5 6 |
# File 'lib/em-http/http_client_options.rb', line 4 def decoding @decoding end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/em-http/http_client_options.rb', line 3 def file @file end |
#followed ⇒ Object
Returns the value of attribute followed.
6 7 8 |
# File 'lib/em-http/http_client_options.rb', line 6 def followed @followed end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/em-http/http_client_options.rb', line 3 def headers @headers end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
2 3 4 |
# File 'lib/em-http/http_client_options.rb', line 2 def host @host end |
#keepalive ⇒ Object (readonly)
Returns the value of attribute keepalive.
4 5 6 |
# File 'lib/em-http/http_client_options.rb', line 4 def keepalive @keepalive end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
2 3 4 |
# File 'lib/em-http/http_client_options.rb', line 2 def method @method end |
#pass_cookies ⇒ Object (readonly)
Returns the value of attribute pass_cookies.
4 5 6 |
# File 'lib/em-http/http_client_options.rb', line 4 def @pass_cookies end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/em-http/http_client_options.rb', line 3 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
2 3 4 |
# File 'lib/em-http/http_client_options.rb', line 2 def port @port end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
3 4 5 |
# File 'lib/em-http/http_client_options.rb', line 3 def query @query end |
#redirects ⇒ Object
Returns the value of attribute redirects.
6 7 8 |
# File 'lib/em-http/http_client_options.rb', line 6 def redirects @redirects end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
2 3 4 |
# File 'lib/em-http/http_client_options.rb', line 2 def uri @uri end |
Instance Method Details
#follow_redirect? ⇒ Boolean
26 |
# File 'lib/em-http/http_client_options.rb', line 26 def follow_redirect?; @followed < @redirects; end |
#no_body? ⇒ Boolean
28 |
# File 'lib/em-http/http_client_options.rb', line 28 def no_body?; @method == "HEAD"; end |
#set_uri(uri, path = nil, query = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/em-http/http_client_options.rb', line 30 def set_uri(uri, path = nil, query = nil) uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s) uri.path = path if path uri.path = '/' if uri.path.empty? @uri = uri @path = uri.path @host = uri.hostname @port = uri.port @query = query # Make sure the ports are set as Addressable::URI doesn't # set the port if it isn't there if @port.nil? @port = @uri.scheme == "https" ? 443 : 80 end uri end |
#ssl? ⇒ Boolean
27 |
# File 'lib/em-http/http_client_options.rb', line 27 def ssl?; @uri.scheme == "https" || @uri.port == 443; end |