struct HTTP::Headers
Overview
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({String, Array(String)})
Defined in:
http/headers.crConstructors
Instance Method Summary
- #==(other : self)
Equality operator.
- #[](key) : String
- #[]=(key, value : String)
- #[]=(key, value : Array(String))
- #[]?(key) : String?
- #add(key, value : String) : self
- #add(key, value : Array(String)) : self
- #add?(key, value : String) : Bool
- #add?(key, value : Array(String)) : Bool
- #clone
- #delete(key) : String?
- #dup
Returns a shallow copy of this object.
- #each(&)
Must yield this collection's elements to the block.
- #empty? : Bool
Returns
true
ifself
is empty,false
otherwise. - #fetch(key, default) : String?
- #fetch(key, &)
- #get(key) : Array(String)
- #get?(key) : Array(String)?
- #has_key?(key) : Bool
- #hash(hasher)
- #includes_word?(key, word) : Bool
Returns if among the headers for key there is some that contains word as a value.
- #inspect(io : IO) : Nil
Appends this struct's name and instance variables names and values to the given IO.
- #merge!(other) : self
- #pretty_print(pp)
- #same?(other : HTTP::Headers) : Bool
- #to_s(io : IO) : Nil
Same as
#inspect(io)
. - #valid_value?(value) : Bool
Macro Summary
Instance methods inherited from module Enumerable({String, Array(String)})
accumulate(initial : U) : Array(U) forall Uaccumulate : Array({String, Array(String)})
accumulate(initial : U, &block : U, {String, Array(String)} -> U) : Array(U) forall U
accumulate(&block : {String, Array(String)}, {String, Array(String)} -> {String, Array(String)}) : Array({String, Array(String)}) accumulate, all?(& : {String, Array(String)} -> ) : Bool
all?(pattern) : Bool
all? : Bool all?, any?(& : {String, Array(String)} -> ) : Bool
any?(pattern) : Bool
any? : Bool any?, chunks(&block : {String, Array(String)} -> U) forall U chunks, compact_map(& : {String, Array(String)} -> _) compact_map, count(& : {String, Array(String)} -> ) : Int32
count(item) : Int32 count, cycle(n, & : {String, Array(String)} -> ) : Nil
cycle(& : {String, Array(String)} -> ) : Nil cycle, each(& : {String, Array(String)} -> ) each, each_cons(count : Int, reuse = false, &) each_cons, each_cons_pair(& : {String, Array(String)}, {String, Array(String)} -> ) : Nil each_cons_pair, each_slice(count : Int, reuse = false, &) each_slice, each_with_index(offset = 0, &) each_with_index, each_with_object(obj : U, & : {String, Array(String)}, U -> ) : U forall U each_with_object, empty? : Bool empty?, find(if_none = nil, & : {String, Array(String)} -> ) find, first(&)
first(count : Int) : Array({String, Array(String)})
first : {String, Array(String)} first, first? : {String, Array(String)}? first?, flat_map(& : {String, Array(String)} -> _) flat_map, group_by(& : {String, Array(String)} -> U) forall U group_by, in_groups_of(size : Int, filled_up_with : U = nil) forall U
in_groups_of(size : Int, filled_up_with : U = nil, reuse = false, &) forall U in_groups_of, includes?(obj) : Bool includes?, index(& : {String, Array(String)} -> ) : Int32?
index(obj) : Int32? index, index_by(& : {String, Array(String)} -> U) : Hash(U, {String, Array(String)}) forall U index_by, join(io : IO, separator = "") : Nil
join(separator, io : IO) : Nil
join(separator = "") : String
join(io : IO, separator = "", & : {String, Array(String)}, IO -> )
join(separator, io : IO, &)
join(separator = "", & : {String, Array(String)} -> ) join, map(& : {String, Array(String)} -> U) : Array(U) forall U map, map_with_index(offset = 0, & : {String, Array(String)}, Int32 -> U) : Array(U) forall U map_with_index, max : {String, Array(String)} max, max? : {String, Array(String)}? max?, max_by(& : {String, Array(String)} -> U) : {String, Array(String)} forall U max_by, max_by?(& : {String, Array(String)} -> U) : {String, Array(String)}? forall U max_by?, max_of(& : {String, Array(String)} -> U) : U forall U max_of, max_of?(& : {String, Array(String)} -> U) : U? forall U max_of?, min : {String, Array(String)} min, min? : {String, Array(String)}? min?, min_by(& : {String, Array(String)} -> U) : {String, Array(String)} forall U min_by, min_by?(& : {String, Array(String)} -> U) : {String, Array(String)}? forall U min_by?, min_of(& : {String, Array(String)} -> U) : U forall U min_of, min_of?(& : {String, Array(String)} -> U) : U? forall U min_of?, minmax : Tuple({String, Array(String)}, {String, Array(String)}) minmax, minmax? : Tuple({String, Array(String)}?, {String, Array(String)}?) minmax?, minmax_by(& : {String, Array(String)} -> U) : Tuple({String, Array(String)}, {String, Array(String)}) forall U minmax_by, minmax_by?(& : {String, Array(String)} -> U) : Tuple({String, Array(String)}, {String, Array(String)}) | Tuple(Nil, Nil) forall U minmax_by?, minmax_of(& : {String, Array(String)} -> U) : Tuple(U, U) forall U minmax_of, minmax_of?(& : {String, Array(String)} -> U) : Tuple(U, U) | Tuple(Nil, Nil) forall U minmax_of?, none?(& : {String, Array(String)} -> ) : Bool
none?(pattern) : Bool
none? : Bool none?, one?(& : {String, Array(String)} -> ) : Bool
one?(pattern) : Bool
one? : Bool one?, partition(& : {String, Array(String)} -> ) : Tuple(Array({String, Array(String)}), Array({String, Array(String)})) partition, product(initial : Number)
product
product(initial : Number, & : {String, Array(String)} -> )
product(& : {String, Array(String)} -> _) product, reduce(memo, &)
reduce(&) reduce, reduce?(&) reduce?, reject(& : {String, Array(String)} -> )
reject(type : U.class) forall U
reject(pattern) : Array({String, Array(String)}) reject, sample(n : Int, random = Random::DEFAULT) : Array({String, Array(String)})
sample(random = Random::DEFAULT) : {String, Array(String)} sample, select(& : {String, Array(String)} -> )
select(type : U.class) : Array(U) forall U
select(pattern) : Array({String, Array(String)}) select, size : Int32 size, skip(count : Int) skip, skip_while(& : {String, Array(String)} -> ) : Array({String, Array(String)}) skip_while, sum(initial)
sum
sum(initial, & : {String, Array(String)} -> )
sum(& : {String, Array(String)} -> ) sum, take_while(& : {String, Array(String)} -> ) : Array({String, Array(String)}) take_while, tally : Hash({String, Array(String)}, Int32) tally, tally_by(& : {String, Array(String)} -> U) : Hash(U, Int32) forall U tally_by, to_a to_a, to_h
to_h(& : {String, Array(String)} -> Tuple(K, V)) forall K, V to_h, to_set : Set({String, Array(String)}) to_set, zip(*others : Indexable | Iterable | Iterator, &)
zip(*others : Indexable | Iterable | Iterator) zip, zip?(*others : Indexable | Iterable | Iterator, &)
zip?(*others : Indexable | Iterable | Iterator) zip?
Class methods inherited from module Enumerable({String, Array(String)})
element_type(x) element_type Instance methods inherited from struct Struct
==(other) : Bool ==, hash(hasher) hash, inspect(io : IO) : Nil inspect, pretty_print(pp) : Nil pretty_print, to_s(io : IO) : Nil to_s Instance methods inherited from struct Value
==(other : JSON::Any)==(other : YAML::Any)
==(other) ==, dup dup
Instance methods inherited from class Object
! : Bool !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as
Class methods inherited from class Object
from_json(string_or_io, root : String)from_json(string_or_io) from_json, from_yaml(string_or_io : String | IO) from_yaml
Constructor Detail
def self.newSource
Instance Method Detail
def ==(other : self)Source
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
def cloneSource
def dupSource
def each(&)Source
Must yield this collection's elements to the block.
def empty? : BoolSource
Returns true
if self
is empty, false
otherwise.
([] of Int32).empty? # => true ([1]).empty? # => false
def fetch(key, &)Source
def hash(hasher)Source
def includes_word?(key, word) : BoolSource
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
def inspect(io : IO) : NilSource
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)"
def merge!(other) : selfSource
def pretty_print(pp)Source
def same?(other : HTTP::Headers) : BoolSource
def to_s(io : IO) : NilSource
Same as #inspect(io)
.
Macro Detail
macro method_missing(call)Source
© 2012–2021 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.2.1/HTTP/Headers.html