-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply a monkey patch to the server responseto
to not raise an error on unbuffered close
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class HTTP::Server | ||
class Response < IO | ||
private def unbuffered_write(slice : Bytes) : Nil | ||
return if slice.empty? | ||
|
||
if response.headers["Transfer-Encoding"]? == "chunked" | ||
@chunked = true | ||
elsif !response.wrote_headers? | ||
if response.version != "HTTP/1.0" && !response.headers.has_key?("Content-Length") | ||
response.headers["Transfer-Encoding"] = "chunked" | ||
@chunked = true | ||
end | ||
end | ||
|
||
ensure_headers_written | ||
|
||
if @chunked | ||
slice.size.to_s(@io, 16) | ||
@io << "\r\n" | ||
@io.write(slice) | ||
@io << "\r\n" | ||
else | ||
@io.write(slice) | ||
end | ||
rescue ex : IO::Error | ||
unbuffered_close | ||
# raise ClientError.new("Error while writing data to the client", ex) | ||
end | ||
end | ||
end |