Skip to content

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.

View source

.new(headers : HTTP::Headers = HTTP::Headers.new)#

Creates a new self, including the data from the provided headers.

View source

Methods#

#<<(cookie : HTTP::Cookie) : Nil#

Adds the provided cookie to the #cookies container.

View source

#==(other : HTTP::Headers) : Bool#

Returns true if self is equal to the provided HTTP::Headers instance. Otherwise returns false.

View source

#[]=(key : String, value : HTTP::Cookie) : Nil#

Sets a cookie with the provided key and value.

Note

The key and cookie name must match.

View source

#[]=(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.

View source

#[]=(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.

View source

#[]=(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.

View source

#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.

View source

#add_cache_control_directive(directive : String, value : String | Bool = true)#

Adds the provided directive; updating the cache-control header.

View source

#cookies : HTTP::Cookies#

Returns an HTTP::Cookies instance that stores cookies related to self.

View source

#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
View source

#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.

Reinitializes the date header if key is date.

View source

#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.

View source

#has_cache_control_directive?(directive : String) : Bool#

Returns true if the current cache-control header has the provided directive. Otherwise returns false.

View source

#remove_cache_control_directive(directive : String) : Nil#

Removes the provided directive from the cache-control header.

View source