struct

HTTP::Headers

Inherits Enumerable / Struct / Value / Object

This is extension apply in Halite.

Class methods

encode(data : Hash(String, _) | NamedTuple) : HTTP::Headers

Returns the given key value pairs as HTTP Headers

Every parameter added is directly written to an IO, where keys are properly escaped.

HTTP::Headers.encode({
  content_type: "application/json",
})
# => "HTTP::Headers{"Content-Type" => "application/json"}"

HTTP::Headers.encode({
  "conTENT-type": "application/json",
})
# => "HTTP::Headers{"Content-Type" => "application/json"}"
Source
encode

Same as #encode

Source

Instance methods

to_flat_h

Similar as Hahs#to_h but return String if it has one value of the key.

headers = HTTP::Headers{"Accepts" => ["application/json", "text/html"], "Content-Type" => ["text/html"]}
headers["Accepts"]      # => ["application/json", "text/html"]
headers["Content-Type"] # => "text/html"
Source