From 70c976bdd85bb8515fea01d6ad6074ef472fc2e0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 14 Nov 2015 02:47:24 +0000 Subject: reduce constant lookup dependencies Unicorn 5 removes some constants we were using, and constant lookups + inline caching are waste of time anyways on newer Rubies with the opt_str_freeze bytecode instruction. This may reduce performance for folks on older Rubies (probably not noticeable); but improves performance for folks on newer Rubies. --- lib/rainbows/max_body.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'lib/rainbows/max_body.rb') diff --git a/lib/rainbows/max_body.rb b/lib/rainbows/max_body.rb index a8abbf7..56a77ab 100644 --- a/lib/rainbows/max_body.rb +++ b/lib/rainbows/max_body.rb @@ -48,19 +48,14 @@ class Rainbows::MaxBody @app, @limit = app, limit end - # :stopdoc: - RACK_INPUT = "rack.input".freeze - CONTENT_LENGTH = "CONTENT_LENGTH" - HTTP_TRANSFER_ENCODING = "HTTP_TRANSFER_ENCODING" - # our main Rack middleware endpoint def call(env) @limit = Rainbows.server.client_max_body_size if nil == @limit catch(:rainbows_EFBIG) do - len = env[CONTENT_LENGTH] + len = env['CONTENT_LENGTH'] if len && len.to_i > @limit return err - elsif /\Achunked\z/i =~ env[HTTP_TRANSFER_ENCODING] + elsif /\Achunked\z/i =~ env['HTTP_TRANSFER_ENCODING'] limit_input!(env) end @app.call(env) @@ -89,9 +84,9 @@ class Rainbows::MaxBody end def limit_input!(env) - input = env[RACK_INPUT] + input = env['rack.input'] klass = input.respond_to?(:rewind) ? RewindableWrapper : Wrapper - env[RACK_INPUT] = klass.new(input, @limit) + env['rack.input'] = klass.new(input, @limit) end # :startdoc: -- cgit v1.2.3-24-ge0c7