Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Matt
    @iMacTia
    Appreciate this is not ideal, but it's the only way I'm aware of to check what you need
    Wei Jun
    @Physium
    Thanks @iMacTia ! i will give it a shot! shows how bad i am with ruby...
    Matt
    @iMacTia
    Not at all! If anything it shows how much room for improvement we have in our documentation 😅!
    raghu bhupatiraju
    @raghuvarmabh
    Hi @iMacTia I just upgraded to faraday 1.8. Do you automatically filter "Authorization" headers while logging. I did 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 ?
    by the way i am using basic auth like this builder.request :basic_auth, user, password
    Matt
    @iMacTia
    @raghuvarmabh not to my knowledge, all headers should be logged if enabled with 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
    raghu bhupatiraju
    @raghuvarmabh
    Thats correct thanks for the inputs and great work on the gem. :thumbsup:
    raghu bhupatiraju
    @raghuvarmabh
    now I am seeing two logs for headers one with "Authorization" filtered and other without filtering for one POST API call.
    request: Accept: "application/json"
    Content-Type: "application/json"
    User-Agent: "Faraday v1.8.0"
    Authorization[REMOVED]
    and
    @iMacTia any guess why it is happening ? My goal is to filter the authentication tokens in logs.
    raghu bhupatiraju
    @raghuvarmabh
        builder.response :logger, nil, headers: true, bodies: true,
                         log_level: Rails.application.config.log_level
        builder.response :logger do |logger|
          logger.filter(/(Authorization)([^&]+)/, '\1[REMOVED]')
        end
    Matt
    @iMacTia
    @raghuvarmabh You're adding the logger twice this way, I guess that's unintentional, you can merge the two lines like this:
    builder.response(:logger, nil, headers: true, bodies: true,
                     log_level: Rails.application.config.log_level) do |logger|
      logger.filter(/(Authorization)([^&]+)/, '\1[REMOVED]')
    end
    raghu bhupatiraju
    @raghuvarmabh
    ya thats the issue for seeing duplicate logs. Thanks again @iMacTia for quick resonse.
    Will it be helpful to add a filter_auth flag to logger which does the filtering thing. I will be happy to open a PR.
    Matt
    @iMacTia
    You’re welcome @raghuvarmabh 🙌!
    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, …)
    Dan Milne
    @dkam
    Hi guys - I have a problem where a header I'm adding to a request "authorizationToken" is having its case changed to "Authorizationtoken". The server apparently is case sensitive and returns a 500 when the case is changed.
    Matt
    @iMacTia
    Hey @dkam, that might be because you're using symbols to set headers or a known issue affecting Net::HTTP, I posted some more details in this comment: https://github.com/lostisland/faraday/issues/747#issuecomment-439864181
    Eddie Cheung
    @eddiecheung-shopify
    Hi guys, I am new to use Faraday connection for sending POST request. Based on some research, I notice that using net_http_persistent adapter (instead of the Faraday.default_adapter (which is net_http according to the Faraday documentation) will improve performance due to reusing the same connection. Basically, I would like to learn the best practice on some of the setting (like pool_size, idle_timeout, keep_alive and max_requests) for net_http_persistent adapter in order have a high performance and stable Faraday connection. Thanks in advance.
    Matt
    @iMacTia
    Hi @eddiecheung-shopify and thanks for joining! I personally don't have expertise in every Faraday adapter (hence why we recently went through the work of splitting them into their own repos), so I don't feel like the best person to provide "bets practices values" for their configuration. I hope someone here (@/all) will be able to help, but otherwise you could reach out to the 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
    1 reply
    Matt
    @iMacTia

    Announcement

    We've decided to move over to GitHub Discussions for community discussions on getting help and asking questions.
    The Faraday core team will not be monitoring this chat anymore, but you're more than welcome to stay and continue the discussion if you prefer.
    If you want to reach out to the Faraday core team, you can find us here
    Samuel Williams
    @ioquatix
    @eddiecheung-shopify you should check out the async backend.
    giri5681
    @giri5681
    Hi all, In below shared code, commented line is old one, old code is returning faraday.headers is {"Authorization"=>"Bearer access_token"}, but when i added new code, faraday.headers is empty !
    def initialize(options = {})
    @config = Sso::Configure.new(options)
    access_token = @config.access_token
      @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
    Please help me on this
    Lewis Cowles
    @Lewiscowles1986
    @giri5681 fairly certain it is that comma after :authorization, :Bearer... which was previously :authorization :Bearer, ...
    https://lostisland.github.io/faraday/usage/#:~:text=Detailed%20HTTP%20Requests shows using a block if making multiple calls, in the same way you have.
    Although https://lostisland.github.io/faraday/middleware/authentication#with-a-proc says I am incorrect in this and the comma is not the issue.
    Vibhanshu Jain
    @vjvibhanshu
    Hi folks
    I am a newbie here
    Can anyone suggest me how to run the test cases with faraday
    basically how to start, any documentation except official website etc
    Wei Jun
    @Physium
    what do you mean how to run test cases with faraday? are you talking about writing rspecs?
    Vibhanshu Jain
    @vjvibhanshu

    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

    Rod Jenkins
    @scriptmonkey
    hello all. Can someone point me to an example of using Faraday to download very large files? It looks like it is reading the file in to memory, which will not work on a 75G file, lol.
    1 reply
    Samuel Williams
    @ioquatix
    @scriptmonkey If you are interested in robust chunked (HTTP range) downloading check out https://github.com/socketry/async-http/blob/main/examples/download/chunked.rb
    BotMaverick
    @BotMaverick

    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!

    Eric Pugh
    @epugh
    Hi all.. Checking out Faraday to integrate into the Quepid project (github.com/o19s/quepid). Quepid interacts with various search engines via the users Browser hitting the search engine. Now that Chrome is getting tighter on permissions, I am looking at moving that logic from the client JS app to the Rails app on the server side.
    3 replies
    Martin Streicher
    @martinstreicher
    I assume this is the new API call to do Bearer token... f.request :authorization, :Bearer, scanner_token
    Where does the documentation explain what things get called via f.request?
    Sandeep
    @sanadella
    Hi All,
    I was using faraday 1.7.1 where I was using f.request :retry during connection initialization. My colleague updated the gem to 2.2.0 and it started failing with :retry is not registered on Faraday::Request error. How to configure this for 2.2.0?
    Sandeep
    @sanadella

    I think I found it. Under release docs

    Gemfile

    gem 'faraday-multipart'
    gem 'faraday-retry'

    Connection initializer

    require 'faraday/retry'
    require 'faraday/multipart'

    conn = Faraday.new(url) do |f|
    f.request :multipart
    f.request :retry

    ...

    end

    Simon Hönscheid
    @SimonHoenscheid
    Hello Community, I try to convert a curl request using forms to faraday, the curl request is documented here: https://developer.atlassian.com/cloud/confluence/rest/api-group-content---attachments/#api-wiki-rest-api-content-id-child-attachment-put
    I have this code so far and the upload itself is working:
    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)
    How do I add the form Data?