struct HTTP::Headers

Overview

This is extension apply in Halite.

Included Modules

Defined in:

halite/ext/http_headers_encode.cr

Class Method Summary

Instance Method Summary

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"}"

[View source]
def self.encode(**data) #

Same as #encode


[View source]

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"

[View source]