Skip to content

Commit

Permalink
Refactor request body encoding for perf and compat w/ previous Rubies.
Browse files Browse the repository at this point in the history
  • Loading branch information
macournoyer committed Oct 29, 2009
1 parent ad10c3a commit b502271
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/thin/request.rb
Expand Up @@ -13,7 +13,11 @@ class Request
MAX_BODY = 1024 * (80 + 32)
BODY_TMPFILE = 'thin-body'.freeze
MAX_HEADER = 1024 * (80 + 32)


INITIAL_BODY = ''
# Force external_encoding of request's body to ASCII_8BIT
INITIAL_BODY.encode(Encoding::ASCII_8BIT) if INITIAL_BODY.respond_to?(:encode)

# Freeze some HTTP header names & values
SERVER_SOFTWARE = 'SERVER_SOFTWARE'.freeze
SERVER_NAME = 'SERVER_NAME'.freeze
Expand Down Expand Up @@ -49,7 +53,7 @@ def initialize
@parser = Thin::HttpParser.new
@data = ''
@nparsed = 0
@body = StringIO.new ''.encode(Encoding::ASCII_8BIT)
@body = StringIO.new(INITIAL_BODY.dup)
@env = {
SERVER_SOFTWARE => SERVER,
SERVER_NAME => LOCALHOST,
Expand Down

0 comments on commit b502271

Please sign in to comment.