Module: Faraday::Adapter::EMHttp::Options

Included in:
Faraday::Adapter::EMHttp, Faraday::Adapter::EMSynchrony
Defined in:
lib/faraday/adapter/em_http.rb

Instance Method Summary collapse

Instance Method Details

#configure_compression(options, env) ⇒ Object



69
70
71
72
73
# File 'lib/faraday/adapter/em_http.rb', line 69

def configure_compression(options, env)
  if env[:method] == :get and not options[:head].key? 'accept-encoding'
    options[:head]['accept-encoding'] = 'gzip, compressed'
  end
end

#configure_proxy(options, env) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/faraday/adapter/em_http.rb', line 45

def configure_proxy(options, env)
  if proxy = request_options(env)[:proxy]
    options[:proxy] = {
      :host => proxy[:uri].host,
      :port => proxy[:uri].port
    }
  end
end

#configure_socket(options, env) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/faraday/adapter/em_http.rb', line 54

def configure_socket(options, env)
  if bind = request_options(env)[:bind]
    options[:bind] = {
      :host => bind[:host],
      :port => bind[:port]
    }
  end
end

#configure_ssl(options, env) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/faraday/adapter/em_http.rb', line 36

def configure_ssl(options, env)
  if ssl = env[:ssl]
    # :ssl => {
    #   :private_key_file => '/tmp/server.key',
    #   :cert_chain_file => '/tmp/server.crt',
    #   :verify_peer => false
  end
end

#configure_timeout(options, env) ⇒ Object



63
64
65
66
67
# File 'lib/faraday/adapter/em_http.rb', line 63

def configure_timeout(options, env)
  timeout, open_timeout = request_options(env).values_at(:timeout, :open_timeout)
  options[:connect_timeout] = options[:inactivity_timeout] = timeout
  options[:connect_timeout] = open_timeout if open_timeout
end

#connection_config(env) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/faraday/adapter/em_http.rb', line 8

def connection_config(env)
  options = {}
  configure_ssl(options, env)
  configure_proxy(options, env)
  configure_timeout(options, env)
  configure_socket(options, env)
  options
end

#read_body(env) ⇒ Object



31
32
33
34
# File 'lib/faraday/adapter/em_http.rb', line 31

def read_body(env)
  body = env[:body]
  body.respond_to?(:read) ? body.read : body
end

#request_config(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/faraday/adapter/em_http.rb', line 17

def request_config(env)
  options = {
    :body => read_body(env),
    :head => env[:request_headers],
    # :keepalive => true,
    # :file => 'path/to/file', # stream data off disk
  }
  configure_compression(options, env)
  # configure_proxy_auth
  # :proxy => {:authorization => [user, pass]}
  # proxy[:username] && proxy[:password]
  options
end

#request_options(env) ⇒ Object



75
76
77
# File 'lib/faraday/adapter/em_http.rb', line 75

def request_options(env)
  env[:request]
end