Skip to content

Commit

Permalink
Remove Server#read_body
Browse files Browse the repository at this point in the history
Unused method leftover from previous refactoring.
  • Loading branch information
wjordan committed Jan 19, 2021
1 parent 0bdfe29 commit 8893c2c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 56 deletions.
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

0 comments on commit 8893c2c

Please sign in to comment.