Sha256: d33ca94f3f31580241881e9197ac6438dae084c97b94c3a36251afa9057096d0

Contents?: true

Size: 1.98 KB

Versions: 6477

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

describe Ethon::Easy::Header do
  let(:easy) { Ethon::Easy.new }

  describe "#headers=" do
    let(:headers) { { 'User-Agent' => 'Ethon' } }

    it "sets header" do
      expect_any_instance_of(Ethon::Easy).to receive(:set_callbacks)
      expect(Ethon::Curl).to receive(:set_option)
      easy.headers = headers
    end

    context "when requesting" do
      before do
        easy.headers = headers
        easy.url = "http://localhost:3001"
        easy.perform
      end

      it "sends" do
        expect(easy.response_body).to include('"HTTP_USER_AGENT":"Ethon"')
      end

      context "when header value contains null byte" do
        let(:headers) { { 'User-Agent' => "Ethon\0" } }

        it "escapes" do
          expect(easy.response_body).to include('"HTTP_USER_AGENT":"Ethon\\\\0"')
        end
      end

      context "when header value has leading whitespace" do
        let(:headers) { { 'User-Agent' => " Ethon" } }

        it "removes" do
          expect(easy.response_body).to include('"HTTP_USER_AGENT":"Ethon"')
        end
      end

      context "when header value has traiing whitespace" do
        let(:headers) { { 'User-Agent' => "Ethon " } }

        it "removes" do
          expect(easy.response_body).to include('"HTTP_USER_AGENT":"Ethon"')
        end
      end
    end
  end

  describe "#compose_header" do
    it "has space in between" do
      expect(easy.compose_header('a', 'b')).to eq('a: b')
    end

    context "when value is a symbol" do
      it "works" do
        expect{ easy.compose_header('a', :b) }.to_not raise_error
      end
    end
  end

  describe "#header_list" do
    context "when no set_headers" do
      it "returns nil" do
        expect(easy.header_list).to eq(nil)
      end
    end

    context "when set_headers" do
      it "returns pointer to header list" do
        easy.headers = {'User-Agent' => 'Custom'}
        expect(easy.header_list).to be_a(FFI::Pointer)
      end
    end
  end
end

Version data entries

6,477 entries across 6,475 versions & 21 rubygems

Version Path
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_bank_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_organization_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_id_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_bank_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_organization_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_id_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_id_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_bank_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_organization_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_organization_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_id_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_bank_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
ory-client-1.15.12 vendor/bundle/ruby/3.1.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_bank_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_id_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_organization_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_bank_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_organization_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb
cybrid_api_id_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/spec/ethon/easy/header_spec.rb