class Athena::Framework::BinaryFileResponse
inherits Athena::Framework::Response
#
Represents a static file that should be returned the client; includes various options to enhance the response headers. See .new
for details.
This response supports Range requests and Conditional requests via the If-None-Match, If-Modified-Since, and If-Range headers.
See ATH::HeaderUtils.make_disposition
for an example of handling dynamic files.
Constructors#
.new(file : String | Path | ATH::AbstractFile | ::File, status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers | ATH::Response::Headers = ATH::Response::Headers.new, public : Bool = true, content_disposition : ATH::BinaryFileResponse::ContentDisposition | Nil = nil, auto_etag : Bool = false, auto_last_modified : Bool = true)
#
Instantiates self
wrapping the provided file, optionally with the provided status, and headers.
By default the response is ATH::Response#set_public
and includes a last-modified
header,
but these can be controlled via the public and auto_last_modified arguments respectively.
The content_disposition argument can be used to set the content-disposition
header on self
if it should be downloadable.
The auto_etag argument can be used to automatically set ETag
header based on a SHA256
hash of the file.
Methods#
#auto_last_modified : self
#
Sets the last-modified
header on self
based on the modification time of the file.
#content=(data) : self
#
Caution
Cannot set the response content via this method on self
.
#delete_file_after_send=(delete_file_after_send : Bool)
#
Determines if the file should be deleted after being sent to the client.
#file : ATH::AbstractFile
#
Returns a ATH::AbstractFile
instance representing the file that will be sent to the client.
#set_content_disposition(disposition : ATH::BinaryFileResponse::ContentDisposition, filename : String | Nil = nil, fallback_filename : String | Nil = nil) : self
#
Sets the content-disposition
header on self
to the provided disposition.
filename defaults to the basename of #file_path
.
#set_file(file : String | Path | ATH::AbstractFile | ::File, content_disposition : ATH::BinaryFileResponse::ContentDisposition | Nil = nil, auto_etag : Bool = false, auto_last_modified : Bool = false) : self
#
Sets the file that will be streamed to the client.
Includes the same optional parameters as .new
.