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.
Constant Summary collapse
- EMPTY_STRING_VALUE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"".freeze
Instance Method Summary collapse
-
#compose_header(key, value) ⇒ String
private
Compose libcurl header string from key and value.
-
#header_list ⇒ FFI::Pointer
private
Return header_list.
-
#headers ⇒ Hash
private
Return headers, return empty hash if none.
-
#headers=(headers) ⇒ Object
private
Set the headers.
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 otherwise.
57 58 59 60 61 62 63 |
# File 'lib/ethon/easy/header.rb', line 57 def compose_header(key, value) if(value == EMPTY_STRING_VALUE) Util.escape_zero_byte("#{key};") else Util.escape_zero_byte("#{key}: #{value}") end end |
#header_list ⇒ FFI::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.
42 43 44 |
# File 'lib/ethon/easy/header.rb', line 42 def header_list @header_list end |
#headers ⇒ Hash
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.
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.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ethon/easy/header.rb', line 25 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 |