Class: RedSnow::Headers

Inherits:
KeyValueCollection show all
Defined in:
lib/redsnow/blueprint.rb

Overview

Headers collection Blueprint AST node

represents 'headers section'

Constant Summary collapse

CONTENT_TYPE_HEADER_KEY =

HTTP ‘Content-Type’ header

:'Content-Type'

Instance Attribute Summary

Attributes inherited from KeyValueCollection

#collection

Instance Method Summary collapse

Methods inherited from KeyValueCollection

#[], #filter_collection

Constructor Details

#initialize(sc_header_collection_handle_payload) ⇒ Headers

Returns a new instance of Headers.

Parameters:

  • sc_header_collection_handle_payload (FFI::Pointer)


120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/redsnow/blueprint.rb', line 120

def initialize(sc_header_collection_handle_payload)
  sc_header_collection_size = RedSnow::Binding.sc_header_collection_size(sc_header_collection_handle_payload)
  @collection = []

  return if sc_header_collection_size == 0

  headers_size = sc_header_collection_size - 1

  (0..headers_size).each do |index|
    sc_header_handle = RedSnow::Binding.sc_header_handle(sc_header_collection_handle_payload, index)
    @collection << Hash[name: RedSnow::Binding.sc_header_key(sc_header_handle), value: RedSnow::Binding.sc_header_value(sc_header_handle)]
  end
end

Instance Method Details

#content_typeString

Returns the value of ‘Content-type’ header if present or nil.

Returns:

  • (String)

    the value of ‘Content-type’ header if present or nil



114
115
116
117
# File 'lib/redsnow/blueprint.rb', line 114

def content_type
  content_type_header = @collection.find { |header| header.key?(CONTENT_TYPE_HEADER_KEY) }
  (content_type_header.nil?) ? nil : content_type_header[CONTENT_TYPE_HEADER_KEY]
end