diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-02-23 19:35:40 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-02-23 19:35:40 -0800 |
commit | 8b5bed299a194ec4dfcd2afa84c5a1875994004a (patch) | |
tree | e23e251001c4ee1a2935ff1badf941c257d8b634 | |
parent | e3ffeac0dc04bb8d5994b7923bf12e55d549a279 (diff) | |
download | rack-8b5bed299a194ec4dfcd2afa84c5a1875994004a.tar.gz |
conditionalget: garbage reduction and speedup
No need to create an array and do a lookup on it every time when case/when can be done more efficiently be the runtime.
-rw-r--r-- | lib/rack/conditionalget.rb | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/rack/conditionalget.rb b/lib/rack/conditionalget.rb index b8f097a3..ceab3347 100644 --- a/lib/rack/conditionalget.rb +++ b/lib/rack/conditionalget.rb @@ -20,17 +20,20 @@ module Rack end def call(env) - return @app.call(env) unless %w[GET HEAD].include?(env['REQUEST_METHOD']) - - status, headers, body = @app.call(env) - headers = Utils::HeaderHash.new(headers) - if status == 200 && fresh?(env, headers) - status = 304 - headers.delete('Content-Type') - headers.delete('Content-Length') - body = [] + case env['REQUEST_METHOD'] + when "GET", "HEAD" + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + if status == 200 && fresh?(env, headers) + status = 304 + headers.delete('Content-Type') + headers.delete('Content-Length') + body = [] + end + [status, headers, body] + else + @app.call(env) end - [status, headers, body] end private |