about summary refs log tree commit
path: root/lib/metropolis/common.rb
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2011-01-17 03:17:28 +0000
committerEric Wong <normalperson@yhbt.net>2011-01-17 09:18:31 +0000
commit2c913347a6e5cc8be776b14e1a177adec0fbd5b6 (patch)
tree8d001fa557ef23c66bc56aa6c2fba943e428382e /lib/metropolis/common.rb
parent34a18520286313a05edc9a927ac4bed95b05191c (diff)
downloadmetropolis-2c913347a6e5cc8be776b14e1a177adec0fbd5b6.tar.gz
use constants everywhere to reduce GC thrashing
This makes it easier to notice a typo, too.
Diffstat (limited to 'lib/metropolis/common.rb')
-rw-r--r--lib/metropolis/common.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/metropolis/common.rb b/lib/metropolis/common.rb
index a6688f3..383ebe9 100644
--- a/lib/metropolis/common.rb
+++ b/lib/metropolis/common.rb
@@ -1,10 +1,13 @@
 # -*- encoding: binary -*-
 module Metropolis::Common
   include Rack::Utils # unescape
+  include Metropolis::Constants
+  HTTP_STATUS_BODIES = {}
+
   autoload :RO, 'metropolis/common/ro'
 
   def setup(opts)
-    @headers = { 'Content-Type' => 'application/octet-stream' }
+    @headers = { Content_Type => 'application/octet-stream' }
     @headers.merge!(opts[:response_headers] || {})
     @nr_slots = opts[:nr_slots]
 
@@ -39,16 +42,16 @@ module Metropolis::Common
   end
 
   def r(code, body = nil)
-    body ||= "#{HTTP_STATUS_CODES[code]}\n"
+    body ||= HTTP_STATUS_BODIES[code] ||= "#{HTTP_STATUS_CODES[code]}\n"
     [ code,
-      { 'Content-Length' => body.size.to_s, 'Content-Type' => 'text/plain' },
+      { Content_Length => body.size.to_s, Content_Type => Text_Plain },
       [ body ] ]
   end
 
   def call(env)
-    if %r{\A/(.*)\z} =~ env["PATH_INFO"]
+    if %r{\A/(.*)\z} =~ env[PATH_INFO]
       key = unescape($1)
-      case env["REQUEST_METHOD"]
+      case env[REQUEST_METHOD]
       when "GET"
         get(key, env)
       when "HEAD"