struct HTTP::Headers
- HTTP::Headers
- Struct
- Value
- Object
Overview
This is extension apply in Halite.
Included Modules
- Enumerable({String, Array(String)})
Defined in:
halite/ext/http_headers_encode.crClass Method Summary
-
.encode(data : Hash(String, _) | NamedTuple) : HTTP::Headers
Returns the given key value pairs as HTTP Headers
-
.encode(**data)
Same as
#encode
Instance Method Summary
-
#to_flat_h
Similar as
Hahs#to_h
but returnString
if it has one value of the key.
Class Method Detail
def self.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"}"
Instance Method Detail
def 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"