class Athena::Framework::Response::Headers
inherits Reference
#
Wraps an HTTP::Headers instance to provide additional functionality.
Forwards all additional methods to the wrapped HTTP::Headers
instance.
Constructors#
.new(headers : self) : self
#
Utility constructor to allow calling .new
with a union of self
and HTTP::Headers
.
Returns the provided headers object.
.new(headers : HTTP::Headers = HTTP::Headers.new)
#
Creates a new self
, including the data from the provided headers.
Methods#
#==(other : HTTP::Headers) : Bool
#
Returns true
if self
is equal to the provided HTTP::Headers
instance.
Otherwise returns false
.
#[]=(key : String, value : HTTP::Cookie) : Nil
#
Sets a cookie with the provided key and value.
Note
The key and cookie name must match.
#[]=(key : String, value : Array(String)) : Nil
#
Sets a header with the provided key to the provided value.
Note
This method will override the value of the provided key.
#[]=(key : String, value : String) : Nil
#
Sets a header with the provided key to the provided value.
Note
This method will override the value of the provided key.
#[]=(key : String, value : _) : Nil
#
Sets a header with the provided key to the provided value.
Note
This method will override the value of the provided key.
#add(key : String, value : String) : Nil
#
Adds the provided value to the the provided key.
Note
This method will concatenate the value to the provided key.
#add_cache_control_directive(directive : String, value : String | Bool = true)
#
Adds the provided directive; updating the cache-control
header.
#cookies : HTTP::Cookies
#
Returns an HTTP::Cookies instance that stores cookies related to self
.
#date(key : String = "date", default : Time | Nil = nil) : Time | Nil
#
Returns a Time
instance by parsing the datetime string from the header with the provided key.
Returns the provided default if no value with the provided key exists, or if parsing its value fails.
time = HTTP.format_time Time.utc 2021, 4, 7, 12, 0, 0
headers = ATH::Response::Headers{"date" => time}
headers.date # => 2021-04-07 12:00:00.0 UTC
headers.date "foo" # => nil
headers.date "foo", Time.utc # => 2021-05-02 14:32:35.257505806 UTC
#delete(key : String) : Nil
#
Deletes the header with the provided key.
Clears the #cookies
instance if key is set-cookie
.
Clears the cache-control
header if key is cache-control
.
#get_cache_control_directive(directive : String) : String | Bool | Nil
#
Returns the provided directive from the cache-control
header, or nil
if it is not set.
#has_cache_control_directive?(directive : String) : Bool
#
Returns true
if the current cache-control
header has the provided directive.
Otherwise returns false
.
#remove_cache_control_directive(directive : String) : Nil
#
Removes the provided directive from the cache-control
header.