Module: Ethon::Easy::Header Private

Included in:
Ethon::Easy
Defined in:
lib/ethon/easy/header.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

This module contains the logic around adding headers to libcurl.

Instance Method Summary collapse

Instance Method Details

#compose_header(key, value) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compose libcurl header string from key and value. Also replaces null bytes, because libcurl will complain about otherwise.

Examples:

Compose header.

easy.compose_header('User-Agent', 'Ethon')

Parameters:

  • key (String)

    The header name.

  • value (String)

    The header value.

Returns:

  • (String)

    The composed header.



53
54
55
# File 'lib/ethon/easy/header.rb', line 53

def compose_header(key, value)
  Util.escape_zero_byte("#{key}: #{value}")
end

#header_listFFI::Pointer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return header_list.

Examples:

Return header_list.

easy.header_list

Returns:

  • (FFI::Pointer)

    The header list.



38
39
40
# File 'lib/ethon/easy/header.rb', line 38

def header_list
  @header_list ||= nil
end

#headersHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return headers, return empty hash if none.

Examples:

Return the headers.

easy.headers

Returns:

  • (Hash)

    The headers.



15
16
17
# File 'lib/ethon/easy/header.rb', line 15

def headers
  @headers ||= {}
end

#headers=(headers) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the headers.

Examples:

Set the headers.

easy.headers = {'User-Agent' => 'ethon'}

Parameters:

  • headers (Hash)

    The headers.



25
26
27
28
29
30
# File 'lib/ethon/easy/header.rb', line 25

def headers=(headers)
  headers ||= {}
  @header_list = nil
  headers.each {|k, v| @header_list = Curl.slist_append(@header_list, compose_header(k,v)) }
  Curl.set_option(:httpheader, @header_list, handle)
end