public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Use frozen constants on the 'hot path' if possible.
Sun Oct 12 09:23:39 -0700 2008
commit  11d19c269a029403039b16866aaa8d6bb1a366ff
tree    1cd2a6b3302990b1ec00d57e4becbf4db36b8422
parent  ee43bd5f870bb9ad822bdade58cd970fc088b975
...
48
49
50
 
 
51
52
53
54
55
 
56
57
58
59
60
61
 
62
63
...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
0
@@ -48,16 +48,20 @@ module Merb
0
     HTTP_X_FORWARDED_FOR     = "HTTP_X_FORWARDED_FOR".freeze
0
     HTTP_IF_MODIFIED_SINCE   = "HTTP_IF_MODIFIED_SINCE".freeze
0
     HTTP_IF_NONE_MATCH       = "HTTP_IF_NONE_MATCH".freeze
0
+    HTTP_CONTENT_TYPE        = "HTTP_CONTENT_TYPE".freeze
0
+    HTTP_CONTENT_LENGTH      = "HTTP_CONTENT_LENGTH".freeze
0
     UPLOAD_ID                = "upload_id".freeze
0
     PATH_INFO                = "PATH_INFO".freeze
0
     SCRIPT_NAME              = "SCRIPT_NAME".freeze
0
     REQUEST_URI              = "REQUEST_URI".freeze
0
     REQUEST_PATH             = "REQUEST_PATH".freeze
0
+    REQUEST_METHOD           = "REQUEST_METHOD".freeze
0
     REMOTE_ADDR              = "REMOTE_ADDR".freeze
0
     BREAK_TAG                = "<br/>".freeze
0
     EMPTY_STRING             = "".freeze
0
     NEWLINE                  = "\n".freeze
0
     DOUBLE_NEWLINE           = "\n\n".freeze
0
     LOCATION                 = "Location".freeze
0
+    TEXT_SLASH_HTML          = "text/html".freeze
0
   end
0
 end
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@ module Merb
0
         begin
0
           rack_response = ::Merb::Dispatcher.handle(Merb::Request.new(env))
0
         rescue Object => e
0
-          return [500, {Merb::Const::CONTENT_TYPE => "text/html"}, e.message + Merb::Const::BREAK_TAG + e.backtrace.join(Merb::Const::BREAK_TAG)]
0
+          return [500, {Merb::Const::CONTENT_TYPE => Merb::Const::TEXT_SLASH_HTML}, e.message + Merb::Const::BREAK_TAG + e.backtrace.join(Merb::Const::BREAK_TAG)]
0
         end
0
         Merb.logger.info Merb::Const::DOUBLE_NEWLINE
0
         Merb.logger.flush
...
54
55
56
57
58
 
 
59
60
 
61
62
63
...
69
70
71
72
73
 
 
74
75
76
...
93
94
95
96
97
 
...
54
55
56
 
 
57
58
59
 
60
61
62
63
...
69
70
71
 
 
72
73
74
75
76
...
93
94
95
 
96
97
0
@@ -54,10 +54,10 @@ module Merb
0
         # response<HTTPResponse>:: The response object to write response to.
0
         def process(request, response)
0
           env = {}.replace(request.params)
0
-          env.delete "HTTP_CONTENT_TYPE"
0
-          env.delete "HTTP_CONTENT_LENGTH"
0
+          env.delete Merb::Const::HTTP_CONTENT_TYPE
0
+          env.delete Merb::Const::HTTP_CONTENT_LENGTH
0
   
0
-          env["SCRIPT_NAME"] = ""  if env["SCRIPT_NAME"] == "/"
0
+          env[Merb::Const::SCRIPT_NAME] = Merb::Const::EMPTY_STRING if env[Merb::Const::SCRIPT_NAME] == Merb::Const::SLASH
0
   
0
           env.update({"rack.version" => [0,1],
0
                        "rack.input" => request.body || StringIO.new(""),
0
@@ -69,8 +69,8 @@ module Merb
0
   
0
                        "rack.url_scheme" => "http"
0
                      })
0
-          env["QUERY_STRING"] ||= ""
0
-          env.delete "PATH_INFO"  if env["PATH_INFO"] == ""
0
+          env[Merb::Const::QUERY_STRING] ||= ""
0
+          env.delete Merb::Const::PATH_INFO  if env[Merb::Const::PATH_INFO] == Merb::Const::EMPTY_STRING
0
   
0
           status, headers, body = @app.call(env)
0
   
0
@@ -93,4 +93,4 @@ module Merb
0
       end
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
7
8
9
10
 
11
12
13
...
7
8
9
 
10
11
12
13
0
@@ -7,7 +7,7 @@ module Merb
0
 
0
         if document_not_modified?(env, headers)
0
           status = 304
0
-          body = ""
0
+          body = Merb::Const::EMPTY_STRING
0
           # set Date header using RFC1123 date format as specified by HTTP
0
           # RFC2616 section 3.3.1.
0
         end
...
20
21
22
23
24
 
 
25
26
27
28
29
30
31
32
 
...
20
21
22
 
 
23
24
25
26
27
28
29
30
 
31
32
0
@@ -20,12 +20,12 @@ module Merb
0
       def strip_path_prefix(env)
0
         ['PATH_INFO', 'REQUEST_URI'].each do |path_key|
0
           if env[path_key] =~ @path_prefix
0
-            env[path_key].sub!(@path_prefix, '')
0
-            env[path_key] = '/' if env[path_key].empty?
0
+            env[path_key].sub!(@path_prefix, Merb::Const::EMPTY_STRING)
0
+            env[path_key] = Merb::Const::SLASH if env[path_key].empty?
0
           end
0
         end
0
       end
0
       
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
8
9
10
11
 
 
 
 
 
12
13
14
 
15
16
17
 
 
18
19
20
 
21
22
23
...
36
37
38
39
 
40
41
42
43
44
45
46
 
...
8
9
10
 
11
12
13
14
15
16
17
 
18
19
 
 
20
21
22
23
 
24
25
26
27
...
40
41
42
 
43
44
45
46
47
48
 
49
50
0
@@ -8,16 +8,20 @@ module Merb
0
       end
0
       
0
       def call(env)        
0
-        path = env['PATH_INFO'] ? env['PATH_INFO'].chomp('/') : ""
0
+        path = if env[Merb::Const::PATH_INFO]
0
+                 env[Merb::Const::PATH_INFO].chomp(Merb::Const::SLASH)
0
+               else
0
+                 Merb::Const::EMPTY_STRING
0
+               end
0
         cached_path = (path.empty? ? 'index' : path) + '.html'
0
         
0
-        if file_exist?(path) && env['REQUEST_METHOD'] =~ /GET|HEAD/ # Serve the file if it's there and the request method is GET or HEAD
0
+        if file_exist?(path) && env[Merb::Const::REQUEST_METHOD] =~ /GET|HEAD/ # Serve the file if it's there and the request method is GET or HEAD
0
           serve_static(env)
0
-        elsif file_exist?(cached_path) && env['REQUEST_METHOD'] =~ /GET|HEAD/ # Serve the page cache if it's there and the request method is GET or HEAD
0
-          env['PATH_INFO'] = cached_path
0
+        elsif file_exist?(cached_path) && env[Merb::Const::REQUEST_METHOD] =~ /GET|HEAD/ # Serve the page cache if it's there and the request method is GET or HEAD
0
+          env[Merb::Const::PATH_INFO] = cached_path
0
           serve_static(env)
0
         elsif path =~ /favicon\.ico/
0
-          return [404, {"Content-Type"=>"text/html"}, "404 Not Found."]
0
+          return [404, { Merb::Const::CONTENT_TYPE => Merb::Const::TEXT_SLASH_HTML }, "404 Not Found."]
0
         else
0
           @app.call(env)
0
         end
0
@@ -36,10 +40,10 @@ module Merb
0
         # ==== Parameters
0
         # env<Hash>:: Environment variables to pass on to the server.
0
         def serve_static(env)
0
-          env["PATH_INFO"] = ::Merb::Request.unescape(env["PATH_INFO"])        
0
+          env[Merb::Const::PATH_INFO] = ::Merb::Request.unescape(env[Merb::Const::PATH_INFO])
0
           @static_server.call(env)
0
         end
0
       
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+end

Comments