Module: Faraday::Adapter::EMHttp::Options
- Included in:
- Faraday::Adapter::EMHttp
- Defined in:
- lib/faraday/adapter/em_http.rb
Overview
Options is a module containing helpers to convert the Faraday env object into options hashes for EMHTTP method calls.
Instance Method Summary collapse
-
#configure_compression(options, env) ⇒ Object
Reads out compression header settings from env into options.
-
#configure_proxy(options, env) ⇒ Object
Reads out proxy settings from env into options.
-
#configure_socket(options, env) ⇒ Object
Reads out host and port settings from env into options.
-
#configure_ssl(options, env) ⇒ Object
Reads out SSL certificate settings from env into options.
-
#configure_timeout(options, env) ⇒ Object
Reads out timeout settings from env into options.
- #connection_config(env) ⇒ Hash
- #read_body(env) ⇒ Object
- #request_config(env) ⇒ Object
- #request_options(env) ⇒ Object
Instance Method Details
#configure_compression(options, env) ⇒ Object
Reads out compression header settings from env into options
93 94 95 96 97 98 |
# File 'lib/faraday/adapter/em_http.rb', line 93 def configure_compression(, env) return unless (env[:method] == :get) && ![:head].key?('accept-encoding') [:head]['accept-encoding'] = 'gzip, compressed' end |
#configure_proxy(options, env) ⇒ Object
Reads out proxy settings from env into options
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/faraday/adapter/em_http.rb', line 53 def configure_proxy(, env) proxy = (env)[:proxy] return unless proxy [:proxy] = { host: proxy[:uri].host, port: proxy[:uri].port, authorization: [proxy[:user], proxy[:password]] } end |
#configure_socket(options, env) ⇒ Object
Reads out host and port settings from env into options
65 66 67 68 69 70 71 72 73 |
# File 'lib/faraday/adapter/em_http.rb', line 65 def configure_socket(, env) bind = (env)[:bind] return unless bind [:bind] = { host: bind[:host], port: bind[:port] } end |
#configure_ssl(options, env) ⇒ Object
Reads out SSL certificate settings from env into options
76 77 78 79 80 81 82 83 |
# File 'lib/faraday/adapter/em_http.rb', line 76 def configure_ssl(, env) return unless env[:url].scheme == 'https' && env[:ssl] [:ssl] = { cert_chain_file: env[:ssl][:ca_file], verify_peer: env[:ssl].fetch(:verify, true) } end |
#configure_timeout(options, env) ⇒ Object
Reads out timeout settings from env into options
86 87 88 89 90 |
# File 'lib/faraday/adapter/em_http.rb', line 86 def configure_timeout(, env) req = (env) [:inactivity_timeout] = request_timeout(:read, req) [:connect_timeout] = request_timeout(:open, req) end |
#connection_config(env) ⇒ Hash
27 28 29 30 31 32 33 34 |
# File 'lib/faraday/adapter/em_http.rb', line 27 def connection_config(env) = {} configure_proxy(, env) configure_timeout(, env) configure_socket(, env) configure_ssl(, env) end |
#read_body(env) ⇒ Object
47 48 49 50 |
# File 'lib/faraday/adapter/em_http.rb', line 47 def read_body(env) body = env[:body] body.respond_to?(:read) ? body.read : body end |
#request_config(env) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/faraday/adapter/em_http.rb', line 36 def request_config(env) = { body: read_body(env), head: env[:request_headers] # keepalive: true, # file: 'path/to/file', # stream data off disk } configure_compression(, env) end |
#request_options(env) ⇒ Object
100 101 102 |
# File 'lib/faraday/adapter/em_http.rb', line 100 def (env) env[:request] end |