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)


108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/redsnow/blueprint.rb', line 108

def initialize(sc_header_collection_handle_payload)
  sc_header_collection_size = RedSnow::Binding.sc_header_collection_size(sc_header_collection_handle_payload)

  if sc_header_collection_size > 0
    headers_size = sc_header_collection_size - 1
    @collection = Array.new

    for index in 0..headers_size do
      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
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



102
103
104
105
# File 'lib/redsnow/blueprint.rb', line 102

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