Skip to content

struct HTTP::Headers
inherits Struct

A Hash-like object that holds HTTP headers.

Two headers are considered the same if their downcase representation is the same (in which _ is the downcase version of -).

Included modules

Enumerable

Class methods

Methods

#==(other : self)

Equality operator.

Returns true if other is equal to self.

Keys are matched case-insensitive. String values are treated equal to an array values with the same string as single element.

HTTP::Headers{"Foo" => "bar"} == HTTP::Headers{"Foo" => "bar"}   # => true
HTTP::Headers{"Foo" => "bar"} == HTTP::Headers{"foo" => "bar"}   # => true
HTTP::Headers{"Foo" => "bar"} == HTTP::Headers{"Foo" => ["bar"]} # => true
HTTP::Headers{"Foo" => "bar"} == HTTP::Headers{"Foo" => "baz"}   # => false
View source

#[](key)

View source

#[]=(key, value : String)

View source

#[]=(key, value : Array(String))

View source

#[]?(key)

View source

#add(key, value : String)

View source

#add(key, value : Array(String))

View source

#add?(key, value : String)

View source

#add?(key, value : Array(String))

View source

#clone

View source

#delete(key)

View source

#dup

Returns a shallow copy of this object.

Because Value is a value type, this method returns self, which already involves a shallow copy of this object because value types are passed by value.

View source

#each

Must yield this collection's elements to the block.

View source

#empty?

Returns true if self is empty, false otherwise.

([] of Int32).empty? # => true
([1]).empty?         # => false
View source

#fetch

View source

#fetch(key, default)

View source

#get(key)

View source

#get?(key)

View source

#has_key?(key)

View source

#hash(hasher)

View source

#includes_word?(key, word)

Returns if among the headers for key there is some that contains word as a value. The word is expected to match between word boundaries (i.e. non-alphanumeric chars).

require "http/headers"

headers = HTTP::Headers{"Connection" => "keep-alive, Upgrade"}
headers.includes_word?("Connection", "Upgrade") # => true
View source

#inspect(io : IO) : Nil

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
View source

#merge!(other)

View source

#pretty_print(pp)

View source

#same?(other : HTTP::Headers)

View source

#to_s(io : IO) : Nil

Same as #inspect(io).

View source

#valid_value?(value)

View source

Macros

method_missing(call)

View source