class Athena::Routing::BinaryFileResponse
- Athena::Routing::BinaryFileResponse
- Athena::Routing::Response
- Reference
- Object
Overview
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 ART::HeaderUtils.make_disposition
for an example of handling dynamic files.
Defined in:
binary_file_response.crConstructors
-
.new(file_path : String | Path, status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers = HTTP::Headers.new, public : Bool = true, content_disposition : ART::BinaryFileResponse::ContentDisposition | Nil = nil, auto_etag : Bool = false, auto_last_modified : Bool = true)
Instantiates
self
wrapping the file at the provided file_path, optionally with the provided status, and headers.
Instance Method Summary
-
#auto_last_modified : Nil
Sets the
last-modified
header onself
based on the modification time of the file. -
#content : String
!!!caution Cannot get the response content via this method on
self
. -
#content=(data) : Nil
!!!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_path : Path
Returns a
Path
instance representing the file that will be sent to the client. -
#set_auto_etag : Nil
Sets the
etag
header onself
based on aSHA256
hash of the file. -
#set_content_disposition(disposition : ART::BinaryFileResponse::ContentDisposition, filename : String | Nil = nil, fallback_filename : String | Nil = nil)
Sets the
content-disposition
header onself
to the provided disposition.
Instance methods inherited from class Athena::Routing::Response
content : String
content,
content=(content : String | Nil)
content=,
etag : String | Nil
etag,
headers : HTTP::Headers
headers,
last_modified : Time | Nil
last_modified,
last_modified=(time : Time | Nil = nil) : Nil
last_modified=,
send(context : HTTP::Server::Context) : Nil
send,
set_etag(etag : String | Nil = nil, weak : Bool = false) : Nil
set_etag,
set_public : Nil
set_public,
status : HTTP::Status
status,
status=(code : HTTP::Status | Int32) : Nil
status=,
writer=(writer : ART::Response::Writer)
writer=
Constructor methods inherited from class Athena::Routing::Response
new(content : String | Nil = nil, status : HTTP::Status | Int32 = HTTP::Status::OK, headers : HTTP::Headers = HTTP::Headers.new)
new
Constructor Detail
Instantiates self
wrapping the file at the provided file_path, optionally with the provided status, and headers.
By default the response is ART::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.
Instance Method Detail
Sets the last-modified
header on self
based on the modification time of the file.
Determines if the file should be deleted after being sent to the client.
Returns a Path
instance representing the file that will be sent to the client.
Sets the content-disposition
header on self
to the provided disposition.
filename defaults to the basename of #file_path
.