Все работает как положено
[37] pry(main)> p = Faraday.new("http://192.168.5.4:8112")
=> #<Faraday::Connection:0x007fd461259c88
@builder=#<Faraday::RackBuilder:0x007fd4612598f0 @handlers=[Faraday::Request::UrlEncoded, Faraday::Adapter::NetHttp]>,
@default_parallel_manager=nil,
@headers={"User-Agent"=>"Faraday v0.9.1"},
@options=#<struct Faraday::RequestOptions params_encoder=nil, proxy=nil, bind=nil, timeout=nil, open_timeout=nil, boundary=nil, oauth=nil>,
@parallel_manager=nil,
@params={},
@proxy=nil,
@ssl=
#<struct Faraday::SSLOptions
verify=nil,
ca_file=nil,
ca_path=nil,
verify_mode=nil,
cert_store=nil,
client_cert=nil,
client_key=nil,
certificate=nil,
private_key=nil,
verify_depth=nil,
version=nil>,
@url_prefix=#<URI::HTTP:0x007fd461258c48 URL:http://192.168.5.4:8112/>>
[38] pry(main)> p.post '/json', "{\"id\": 0, \"method\":\"auth.login\", \"params\":[\"password\"]}"
=> #<Faraday::Response:0x007fd4611d3bd8
@env=
#<struct Faraday::Env
method=:post,
body="{\"id\": 0, \"result\": false, \"error\": null}",
url=#<URI::HTTP:0x007fd4611e21d8 URL:http://192.168.5.4:8112/json>,
request=
#<struct Faraday::RequestOptions params_encoder=nil, proxy=nil, bind=nil, timeout=nil, open_timeout=nil, boundary=nil, oauth=nil>,
request_headers={"User-Agent"=>"Faraday v0.9.1", "Content-Type"=>"application/x-www-form-urlencoded"},
ssl=
#<struct Faraday::SSLOptions
verify=nil,
ca_file=nil,
ca_path=nil,
verify_mode=nil,
cert_store=nil,
client_cert=nil,
client_key=nil,
certificate=nil,
private_key=nil,
verify_depth=nil,
version=nil>,
parallel_manager=nil,
params=nil,
response=nil,
response_headers=
{"transfer-encoding"=>"chunked",
"date"=>"Sat, 10 Jan 2015 01:47:43 GMT",
"connection"=>"close",
"content-type"=>"application/x-json",
"server"=>"TwistedWeb/12.0.0"},
status=200>,
@on_complete_callbacks=[]>
Наверное, не отвечает.
[39] pry(main)> p = Faraday.new("http://192.168.5.4:8112") { |f| f.response :logger }
=> #<Faraday::Connection:0x007fd460a44f98
@builder=#<Faraday::RackBuilder:0x007fd460a44930 @handlers=[Faraday::Response::Logger]>,
@default_parallel_manager=nil,
@headers={"User-Agent"=>"Faraday v0.9.1"},
@options=#<struct Faraday::RequestOptions params_encoder=nil, proxy=nil, bind=nil, timeout=nil, open_timeout=nil, boundary=nil, oauth=nil>,
@parallel_manager=nil,
@params={},
@proxy=nil,
@ssl=
#<struct Faraday::SSLOptions
verify=nil,
ca_file=nil,
ca_path=nil,
verify_mode=nil,
cert_store=nil,
client_cert=nil,
client_key=nil,
certificate=nil,
private_key=nil,
verify_depth=nil,
version=nil>,
@url_prefix=#<URI::HTTP:0x007fd460a44520 URL:http://192.168.5.4:8112/>>
[40] pry(main)> p.post '/json', "{\"id\": 0, \"method\":\"auth.login\", \"params\":[\"password\"]}"
I, [2015-01-10T04:48:16.268374 #77388] INFO -- : post http://192.168.5.4:8112/json
D, [2015-01-10T04:48:16.268467 #77388] DEBUG -- request: User-Agent: "Faraday v0.9.1"
I, [2015-01-10T04:48:16.268619 #77388] INFO -- Status:
NoMethodError: undefined method `map' for nil:NilClass
from /Users/tehkode/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/faraday-0.9.1/lib/faraday/response/logger.rb:36:in `dump_headers'
Не делает никаких запросов.
[41] pry(main)> p = Faraday.new("http://192.168.5.4:8112") { |f| f.request :json }
=> #<Faraday::Connection:0x007fd460c68e78
@builder=#<Faraday::RackBuilder:0x007fd460c68a40 @handlers=[FaradayMiddleware::EncodeJson]>,
@default_parallel_manager=nil,
@headers={"User-Agent"=>"Faraday v0.9.1"},
@options=#<struct Faraday::RequestOptions params_encoder=nil, proxy=nil, bind=nil, timeout=nil, open_timeout=nil, boundary=nil, oauth=nil>,
@parallel_manager=nil,
@params={},
@proxy=nil,
@ssl=
#<struct Faraday::SSLOptions
verify=nil,
ca_file=nil,
ca_path=nil,
verify_mode=nil,
cert_store=nil,
client_cert=nil,
client_key=nil,
certificate=nil,
private_key=nil,
verify_depth=nil,
version=nil>,
@url_prefix=#<URI::HTTP:0x007fd460c68770 URL:http://192.168.5.4:8112/>>
[42] pry(main)> p.post '/json', "{\"id\": 0, \"method\":\"auth.login\", \"params\":[\"password\"]}"
=> #<Faraday::Response:0x007fd460b922b0
@env=
#<struct Faraday::Env
method=:post,
body="{\"id\": 0, \"method\":\"auth.login\", \"params\":[\"torrent\"]}",
url=#<URI::HTTP:0x007fd460b92c38 URL:http://192.168.5.4:8112/json>,
request=
#<struct Faraday::RequestOptions params_encoder=nil, proxy=nil, bind=nil, timeout=nil, open_timeout=nil, boundary=nil, oauth=nil>,
request_headers={"User-Agent"=>"Faraday v0.9.1", "Content-Type"=>"application/json"},
ssl=
#<struct Faraday::SSLOptions
verify=nil,
ca_file=nil,
ca_path=nil,
verify_mode=nil,
cert_store=nil,
client_cert=nil,
client_key=nil,
certificate=nil,
private_key=nil,
verify_depth=nil,
version=nil>,
parallel_manager=nil,
params=nil,
response=nil,
response_headers=nil,
status=nil>,
@on_complete_callbacks=[]>
[43] pry(main)> p = Faraday.new("http://192.168.5.4:8112") { |f| f.response :json }
=> #<Faraday::Connection:0x007fd4611eaae0
@builder=#<Faraday::RackBuilder:0x007fd4611ea680 @handlers=[FaradayMiddleware::ParseJson]>,
@default_parallel_manager=nil,
@headers={"User-Agent"=>"Faraday v0.9.1"},
@options=#<struct Faraday::RequestOptions params_encoder=nil, proxy=nil, bind=nil, timeout=nil, open_timeout=nil, boundary=nil, oauth=nil>,
@parallel_manager=nil,
@params={},
@proxy=nil,
@ssl=
#<struct Faraday::SSLOptions
verify=nil,
ca_file=nil,
ca_path=nil,
verify_mode=nil,
cert_store=nil,
client_cert=nil,
client_key=nil,
certificate=nil,
private_key=nil,
verify_depth=nil,
version=nil>,
@url_prefix=#<URI::HTTP:0x007fd4611ea360 URL:http://192.168.5.4:8112/>>
[44] pry(main)> p.post '/json', "{\"id\": 0, \"method\":\"auth.login\", \"params\":[\"torrent\"]}"
NoMethodError: undefined method `[]' for nil:NilClass
from /Users/tehkode/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:59:in `response_type'
Извините за недоумение. Когда вы передаете рубиновый блок для настройки промежуточного программного обеспечения, вы также должны явно настроить адаптер, иначе ничего не будет работать. https://github.com/lostisland/faraday/issues/325#issuecomment -30370061
@mislav Вероятно, хорошей идеей было бы вернуться к адаптеру по умолчанию, если он не указан явно. Текущее поведение очень сбивает с толку.
@mislav другой вариант - вызвать описательное исключение, если в блоке не установлен адаптер
Я согласен с тем, что текущее поведение довольно сбивает с толку.