diff --git a/spec/context_spec.cr b/spec/context_spec.cr index c3a41af..87c755b 100644 --- a/spec/context_spec.cr +++ b/spec/context_spec.cr @@ -1,7 +1,7 @@ require "./spec_helper" describe "Context" do - it "sets content type" do + it "has a default content type" do kemal = Kemal::Handler.new kemal.add_route "GET", "/" do |env| "Hello" diff --git a/src/kemal.cr b/src/kemal.cr index 0a5e347..d084d6d 100644 --- a/src/kemal.cr +++ b/src/kemal.cr @@ -28,8 +28,13 @@ at_exit do get "/__kemal__/:image" do |env| image = env.params["image"] file_path = File.expand_path("libs/kemal/images/#{image}", Dir.current) - env.response.headers.add "Content-Type", "application/octet-stream" - File.read(file_path) if File.exists? file_path + if File.exists? file_path + env.response.headers.add "Content-Type", "application/octet-stream" + env.response.content_length = File.size(file_path) + File.open(file_path) do |file| + IO.copy(file, env.response) + end + end end server.listen