Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Server#read_body #2531

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* Add `#string` method to `Puma::NullIO` ([#2520])
* Fix binding via Rack handler to IPv6 addresses (#2521)

* Refactor
* Remove `Server#read_body` ([#2531])

## 5.1.1 / 2020-12-10

* Bugfixes
Expand Down
56 changes: 0 additions & 56 deletions lib/puma/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,62 +495,6 @@ def with_force_shutdown(client, &block)

# :nocov:

# Given the request +env+ from +client+ and the partial body +body+
# plus a potential Content-Length value +cl+, finish reading
# the body and return it.
#
# If the body is larger than MAX_BODY, a Tempfile object is used
# for the body, otherwise a StringIO is used.
# @deprecated 6.0.0
#
def read_body(env, client, body, cl)
content_length = cl.to_i

remain = content_length - body.bytesize

return StringIO.new(body) if remain <= 0

# Use a Tempfile if there is a lot of data left
if remain > MAX_BODY
stream = Tempfile.new(Const::PUMA_TMP_BASE)
stream.binmode
else
# The body[0,0] trick is to get an empty string in the same
# encoding as body.
stream = StringIO.new body[0,0]
end

stream.write body

# Read an odd sized chunk so we can read even sized ones
# after this
chunk = client.readpartial(remain % CHUNK_SIZE)

# No chunk means a closed socket
unless chunk
stream.close
return nil
end

remain -= stream.write(chunk)

# Read the rest of the chunks
while remain > 0
chunk = client.readpartial(CHUNK_SIZE)
unless chunk
stream.close
return nil
end

remain -= stream.write(chunk)
end

stream.rewind

return stream
end
# :nocov:

# Handle various error types thrown by Client I/O operations.
def client_error(e, client)
# Swallow, do not log
Expand Down