Sha256: 768ab73c7ab8162c76d24ac3763f570ead8e1f7d940cecd36bc6df9078dc30d1

Contents?: true

Size: 1.55 KB

Versions: 83

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

83 entries across 70 versions & 16 rubygems

Version Path
passbase-1.3.0 vendor/bundle/ruby/2.7.0/gems/faraday-1.4.2/spec/faraday/utils_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/faraday-1.4.2/spec/faraday/utils_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/spec/faraday/utils_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/faraday-1.4.2/spec/faraday/utils_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/spec/faraday/utils_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/faraday-1.1.0/spec/faraday/utils_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/faraday-1.2.0/spec/faraday/utils_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/utils_spec.rb
faraday-1.4.2 spec/faraday/utils_spec.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/faraday-1.4.1/spec/faraday/utils_spec.rb
faraday-1.4.1 spec/faraday/utils_spec.rb
faraday-1.4.0 spec/faraday/utils_spec.rb
faraday-1.3.1 spec/faraday/utils_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/utils_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/spec/faraday/utils_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/faraday-1.1.0/spec/faraday/utils_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/faraday-1.2.0/spec/faraday/utils_spec.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/faraday-1.3.0/spec/faraday/utils_spec.rb
faraday-1.3.0 spec/faraday/utils_spec.rb
faraday-1.2.0 spec/faraday/utils_spec.rb