Skip to content

Commit

Permalink
HTTP::Server: don't override content-lenght if already set (#9726)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Sep 4, 2020
1 parent dfbd6af commit 634af9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions spec/std/http/server/response_spec.cr
Expand Up @@ -91,6 +91,14 @@ describe HTTP::Server::Response do
io.to_s.should eq("HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\n1234567890")
end

it "doesn't override content-length when there's no body" do
io = IO::Memory.new
response = Response.new(io)
response.content_length = 10
response.close
io.to_s.should eq("HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\n")
end

it "adds header" do
io = IO::Memory.new
response = Response.new(io)
Expand Down
2 changes: 1 addition & 1 deletion src/http/server/response.cr
Expand Up @@ -223,7 +223,7 @@ class HTTP::Server
def close
return if closed?

unless response.wrote_headers?
if !response.wrote_headers? && !response.headers.has_key?("Content-Length")
response.content_length = @out_count
end

Expand Down

0 comments on commit 634af9f

Please sign in to comment.