mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Use 'previous_def' instead of code copy/pasta
This commit is contained in:
parent
1955241d58
commit
79b4e1badb
1 changed files with 12 additions and 27 deletions
|
@ -53,38 +53,23 @@ end
|
||||||
#
|
#
|
||||||
class HTTP::Server::Response
|
class HTTP::Server::Response
|
||||||
class Output
|
class Output
|
||||||
# Copy-paste of https://github.com/crystal-lang/crystal/blob/1.2.2/src/http/server/response.cr#L205-L228
|
# Run unbuffered_write() from stdlib but catch IO::Error
|
||||||
# but without the "raise" statement in `rescue ex`
|
# HTTP::Server::ClientError exceptions.
|
||||||
private def unbuffered_write(slice : Bytes)
|
private def unbuffered_write(slice : Bytes)
|
||||||
return if slice.empty?
|
begin
|
||||||
|
previous_def
|
||||||
unless 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
|
rescue ex : IO::Error
|
||||||
unbuffered_close
|
rescue ex : HTTP::Server::ClientError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Copy-paste of https://github.com/crystal-lang/crystal/blob/1.2.2/src/http/server/response.cr#L274-L280
|
# Same for unbuffered_flush()
|
||||||
# but without the "raise" statement in `rescue ex`
|
|
||||||
private def unbuffered_flush
|
private def unbuffered_flush
|
||||||
@io.flush
|
begin
|
||||||
|
previous_def
|
||||||
rescue ex : IO::Error
|
rescue ex : IO::Error
|
||||||
unbuffered_close
|
rescue ex : HTTP::Server::ClientError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue