Sha256: 68f35cfc72d2ed31c91f539be4e77e63346d667a8d85bb0b49b3d2acacc43955

Contents?: true

Size: 1.58 KB

Versions: 51

Compression:

Stored size: 1.58 KB

Contents

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

51 entries across 50 versions & 8 rubygems

Version Path
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/lib/ethon/easy/header.rb
cloudsmith-api-0.49.21 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/lib/ethon/easy/header.rb
cloudsmith-api-0.49.15 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/lib/ethon/easy/header.rb
cloudsmith-api-0.49.13 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/lib/ethon/easy/header.rb
cloudsmith-api-0.49.9 vendor/bundle/ruby/2.3.0/gems/ethon-0.12.0/lib/ethon/easy/header.rb
cloudsmith-api-0.44.4 vendor/bundle/ruby/2.3.0/gems/ethon-0.12.0/lib/ethon/easy/header.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/lib/ethon/easy/header.rb
approveapi-1.0.8 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/lib/ethon/easy/header.rb
approveapi-1.0.5 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/lib/ethon/easy/header.rb
ethon-0.12.0 lib/ethon/easy/header.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/lib/ethon/easy/header.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/ethon-0.11.0/lib/ethon/easy/header.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/lib/ethon/easy/header.rb
ethon-0.11.0 lib/ethon/easy/header.rb
ethon-0.10.1 lib/ethon/easy/header.rb
ethon-0.9.1 lib/ethon/easy/header.rb
ethon-0.9.0 lib/ethon/easy/header.rb
ethon-0.8.1 lib/ethon/easy/header.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/ethon-0.8.0/lib/ethon/easy/header.rb
ethon-0.8.0 lib/ethon/easy/header.rb