Sha256: 768ab73c7ab8162c76d24ac3763f570ead8e1f7d940cecd36bc6df9078dc30d1

Contents?: true

Size: 1.55 KB

Versions: 79

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

RSpec.describe Faraday::Utils do
  describe 'headers parsing' do
    let(:multi_response_headers) do
      "HTTP/1.x 500 OK\r\nContent-Type: text/html; charset=UTF-8\r\n" \
      "HTTP/1.x 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n"
    end

    it 'parse headers for aggregated responses' do
      headers = Faraday::Utils::Headers.new
      headers.parse(multi_response_headers)

      result = headers.to_hash

      expect(result['Content-Type']).to eq('application/json; charset=UTF-8')
    end
  end

  describe 'URI parsing' do
    let(:url) { 'http://example.com/abc' }

    it 'escapes safe buffer' do
      str = FakeSafeBuffer.new('$32,000.00')
      expect(Faraday::Utils.escape(str)).to eq('%2432%2C000.00')
    end

    it 'parses with default parser' do
      with_default_uri_parser(nil) do
        uri = normalize(url)
        expect(uri.host).to eq('example.com')
      end
    end

    it 'parses with URI' do
      with_default_uri_parser(::URI) do
        uri = normalize(url)
        expect(uri.host).to eq('example.com')
      end
    end

    it 'parses with block' do
      with_default_uri_parser(->(u) { "booya#{'!' * u.size}" }) do
        expect(normalize(url)).to eq('booya!!!!!!!!!!!!!!!!!!!!!!')
      end
    end

    it 'replaces headers hash' do
      headers = Faraday::Utils::Headers.new('authorization' => 't0ps3cr3t!')
      expect(headers).to have_key('authorization')

      headers.replace('content-type' => 'text/plain')
      expect(headers).not_to have_key('authorization')
    end
  end
end

Version data entries

79 entries across 66 versions & 15 rubygems

Version Path
faraday-1.10.4 spec/faraday/utils_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/faraday-1.2.0/spec/faraday/utils_spec.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.3/spec/faraday/utils_spec.rb
faraday-1.10.3 spec/faraday/utils_spec.rb
faraday-1.10.2 spec/faraday/utils_spec.rb
faraday-1.10.1 spec/faraday/utils_spec.rb
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/faraday-1.0.1/spec/faraday/utils_spec.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/faraday-1.10.0/spec/faraday/utils_spec.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/faraday-1.10.0/spec/faraday/utils_spec.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/faraday-1.10.0/spec/faraday/utils_spec.rb
faraday-1.10.0 spec/faraday/utils_spec.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/faraday-1.9.3/spec/faraday/utils_spec.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.8.0/spec/faraday/utils_spec.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.9.3/spec/faraday/utils_spec.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/faraday-1.9.3/spec/faraday/utils_spec.rb
faraday-1.9.3 spec/faraday/utils_spec.rb
faraday-1.9.2 spec/faraday/utils_spec.rb
faraday-1.9.1 spec/faraday/utils_spec.rb
faraday-1.9.0 spec/faraday/utils_spec.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.8.0/spec/faraday/utils_spec.rb