Skip to content

Commit

Permalink
Use String#bytesize instead of String#length
Browse files Browse the repository at this point in the history
The result of String#length can vary depending on a language, a character-encoding.
For HTTP headers, #bytesize is safer
  • Loading branch information
tomykaira committed Jul 10, 2012
1 parent ca21111 commit 8efc32c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/puma/server.rb
Expand Up @@ -279,7 +279,7 @@ def process_client(client, proto_env)
# a problem with the read operation on the client socket.
# Effect is to stop processing when the socket can't fill the buffer
# for further parsing.
while nparsed < data.length
while nparsed < data.bytesize
nparsed = parser.execute(env, data, nparsed)

if parser.finished?
Expand Down Expand Up @@ -313,7 +313,7 @@ def process_client(client, proto_env)
return if !chunk or chunk.length == 0 # read failed, stop processing

data << chunk
if data.length >= MAX_HEADER
if data.bytesize >= MAX_HEADER
raise HttpParserError,
"HEADER is longer than allowed, aborting client early."
end
Expand Down

0 comments on commit 8efc32c

Please sign in to comment.