This is an unofficial chat room, if you want to reach out to the Faraday core team, join us on GitHub Discussions (https://github.com/lostisland/faraday/discussions) instead
Faraday::Connection
exposes a few attr_reader
s you can use to check these things. Check out https://github.com/lostisland/faraday/blob/main/lib/faraday/connection.rb#L21
params
are exposed as-is and middleware is stored in the builder
. As for options, there's a getter method here: https://github.com/lostisland/faraday/blob/main/lib/faraday/connection.rb#L222
Faraday::RackBuilder::Handler
objects. The reason they show as class names in the Ruby console is because we override the inspect
method (see https://github.com/lostisland/faraday/blob/main/lib/faraday/rack_builder.rb#L42). If you try calling conn.builder.handlers.first.class
you'll see the actual class and if you call conn.builder.handlers.first.build
you'll get an actual configured instance of the middleware.
headers: true
and was able to see other headers except "Authorization". Which is good actually just want to confirm. The API calls are still working so I guess you are not showing it intentionally for security reasons ?
builder.request :basic_auth, user, password
headers: true
. I suspect what is happening here is that you've put the :logger
middleware BEFORE the basic_auth
one :). The logger logs the request the moment it receives it, so if the :basic_auth
middleware is added later in the stack, it won't have added the Authorization
header to the request yet. If this is what you want, then it's a pretty good solution on how to log the request without exposing the Authorization
header :D
builder.response(:logger, nil, headers: true, bodies: true,
log_level: Rails.application.config.log_level) do |logger|
logger.filter(/(Authorization)([^&]+)/, '\1[REMOVED]')
end
filter_auth
flag to logger which does the filtering thing. I will be happy to open a PR.
filter_auth
sounds a bit too specific. Maybe a more generic method to filter headers? I’d suggest opening an issue before jumping on an implementation so we could discuss a proposal (how would that be used, how it will differ from the current filter
method, …)
net-http-persistent
team and ask them about this. In the end, Faraday is just a wrapper on the adapters, so whatever they suggest as the best approach will work in Faraday as well
@conn = Faraday.new(url: Sso::BASE_URL) do |faraday|
# faraday.authorization :Bearer, access_token if access_token.present?
faraday.request :authorization, :Bearer, access_token if access_token.present?
faraday.request :json
faraday.response :json
faraday.adapter Faraday.default_adapter
end
end
:authorization, :Bearer...
which was previously :authorization :Bearer, ...
I am using faraday with rspec for single request I am facing below issue
NoMethodError:
undefined method `register_middleware' for Faraday::Adapter:Class
Faraday::Adapter.register_middleware(net_http: Faraday::Adapter::NetHttp)
I have tried to install faraday_middleware gem but it is not found
Not sure where I am worng
Hello all!
I am new to faraday and net-http (we use the default adapter). I have a rails application and it calls many other services to fetch data using faraday gem. However, we are experiencing a lot of timeout errors and we were thinking of reducing the timeout value etc...
I wanted to try one thing, I wanted to collect few data here.
Given that I want to perform a GET API request
I want to log or print the value of the time it takes to open the connection with the server
And I also want to log or print the time it takes till the client starts or ends receiving the response back from the server
And I also want to log or print the time it takes to close the connection with the server.
(Iterating again, I am using Rails application :) ) How can I achieve this? Thanks!
require 'faraday'
require 'faraday/multipart'
cloud_upload_connection = Faraday.new(cloud_url) do |c|
c.request :multipart
c.request :url_encoded
c.request :authorization, :basic, cloud_useremail, cloud_apitoken
c.adapter :net_http
c.headers['X-Atlassian-Token'] = 'nocheck'
end
# upload attachment
payload = { :file => Faraday::UploadIO.new("#{download_directory}/#{page['id']}.csv", 'text/plain') }
cloud_upload_connection.put( "rest/api/content/#{cloud_page_details['id'].to_i}/child/attachment", payload)