mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add send_file helper variation for sending raw data (#188)
Add send_file helper variation for sending raw data * Use Response#content_type= * Fix docs
This commit is contained in:
parent
f6747be691
commit
31cc9fbff4
1 changed files with 16 additions and 0 deletions
|
@ -57,3 +57,19 @@ def send_file(env, path : String, mime_type : String? = nil)
|
|||
IO.copy(file, env.response)
|
||||
end
|
||||
end
|
||||
|
||||
# Send a file with given data and default `application/octet-stream` mime_type.
|
||||
#
|
||||
# send_file env, data_slice
|
||||
#
|
||||
# Optionally you can override the mime_type
|
||||
#
|
||||
# send_file env, data_slice, "image/jpeg"
|
||||
|
||||
def send_file(env, data : Slice(UInt8), mime_type : String? = nil)
|
||||
mime_type ||= "application/octet-stream"
|
||||
|
||||
env.response.content_type = mime_type
|
||||
env.response.content_length = data.bytesize
|
||||
env.response.write data
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue