Sha256: 78e4f7e9cdd172e7f1c59e2a3dc59e87d3fa07358ba72e6df0e8707e5a5b58b2

Contents?: true

Size: 1.61 KB

Versions: 6479

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true
module Ethon
  class Easy
    # This module contains the logic around adding headers to libcurl.
    #
    # @api private
    module Header
      # Return headers, return empty hash if none.
      #
      # @example Return the headers.
      #   easy.headers
      #
      # @return [ Hash ] The headers.
      def headers
        @headers ||= {}
      end

      # Set the headers.
      #
      # @example Set the headers.
      #   easy.headers = {'User-Agent' => 'ethon'}
      #
      # @param [ Hash ] headers The headers.
      def headers=(headers)
        headers ||= {}
        header_list = nil
        headers.each do |k, v|
          header_list = Curl.slist_append(header_list, compose_header(k,v))
        end
        Curl.set_option(:httpheader, header_list, handle)

        @header_list = header_list && FFI::AutoPointer.new(header_list, Curl.method(:slist_free_all))
      end

      # Return header_list.
      #
      # @example Return header_list.
      #   easy.header_list
      #
      # @return [ FFI::Pointer ] The header list.
      def header_list
        @header_list
      end

      # Compose libcurl header string from key and value.
      # Also replaces null bytes, because libcurl will complain
      # otherwise.
      #
      # @example Compose header.
      #   easy.compose_header('User-Agent', 'Ethon')
      #
      # @param [ String ] key The header name.
      # @param [ String ] value The header value.
      #
      # @return [ String ] The composed header.
      def compose_header(key, value)
        Util.escape_zero_byte("#{key}: #{value}")
      end
    end
  end
end

Version data entries

6,479 entries across 6,477 versions & 22 rubygems

Version Path
cybrid_api_organization_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_id_ruby-0.122.67 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_bank_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_organization_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_id_ruby-0.122.66 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_id_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_bank_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_organization_ruby-0.122.65 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_bank_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_id_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_organization_ruby-0.122.64 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_id_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_bank_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_organization_ruby-0.122.60 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_organization_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_bank_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_id_ruby-0.122.59 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_bank_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_organization_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb
cybrid_api_id_ruby-0.122.58 vendor/bundle/ruby/3.3.0/gems/ethon-0.16.0/lib/ethon/easy/header.rb