Class: HttpClientOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/em-http/http_client_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options, method)
  @keepalive = options[:keepalive] || false  # default to single request per connection
  @redirects = options[:redirects] ||= 0     # default number of redirects to follow
  @followed  = options[:followed]  ||= 0     # keep track of number of followed requests

  @method   = method.to_s.upcase
  @headers  = options[:head] || {}

  @file     = options[:file]
  @body     = options[:body]

  @pass_cookies = options.fetch(:pass_cookies, true)  # pass cookies between redirects
  @decoding     = options.fetch(:decoding, true)      # auto-decode compressed response
  @compressed   = options.fetch(:compressed, true)    # auto-negotiated compressed response

  set_uri(uri, options[:path], options[:query])
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/em-http/http_client_options.rb', line 3

def body
  @body
end

#compressedObject (readonly)

Returns the value of attribute compressed.



4
5
6
# File 'lib/em-http/http_client_options.rb', line 4

def compressed
  @compressed
end

#decodingObject (readonly)

Returns the value of attribute decoding.



4
5
6
# File 'lib/em-http/http_client_options.rb', line 4

def decoding
  @decoding
end

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/em-http/http_client_options.rb', line 3

def file
  @file
end

#followedObject

Returns the value of attribute followed.



6
7
8
# File 'lib/em-http/http_client_options.rb', line 6

def followed
  @followed
end

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/em-http/http_client_options.rb', line 3

def headers
  @headers
end

#hostObject (readonly)

Returns the value of attribute host.



2
3
4
# File 'lib/em-http/http_client_options.rb', line 2

def host
  @host
end

#keepaliveObject (readonly)

Returns the value of attribute keepalive.



4
5
6
# File 'lib/em-http/http_client_options.rb', line 4

def keepalive
  @keepalive
end

#methodObject (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_cookiesObject (readonly)

Returns the value of attribute pass_cookies.



4
5
6
# File 'lib/em-http/http_client_options.rb', line 4

def pass_cookies
  @pass_cookies
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/em-http/http_client_options.rb', line 3

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



2
3
4
# File 'lib/em-http/http_client_options.rb', line 2

def port
  @port
end

#queryObject (readonly)

Returns the value of attribute query.



3
4
5
# File 'lib/em-http/http_client_options.rb', line 3

def query
  @query
end

#redirectsObject

Returns the value of attribute redirects.



6
7
8
# File 'lib/em-http/http_client_options.rb', line 6

def redirects
  @redirects
end

#uriObject (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

Returns:

  • (Boolean)


26
# File 'lib/em-http/http_client_options.rb', line 26

def follow_redirect?; @followed < @redirects; end

#no_body?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


27
# File 'lib/em-http/http_client_options.rb', line 27

def ssl?; @uri.scheme == "https" || @uri.port == 443; end