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:
Sijawusz Pur Rahnama 2016-08-08 20:15:43 +02:00 committed by Serdar Dogruyol
parent f6747be691
commit 31cc9fbff4
1 changed files with 16 additions and 0 deletions

View File

@ -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