about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--ext/http11/http11.c15
-rw-r--r--lib/mongrel.rb9
2 files changed, 13 insertions, 11 deletions
diff --git a/ext/http11/http11.c b/ext/http11/http11.c
index 9d7673b..1cdb525 100644
--- a/ext/http11/http11.c
+++ b/ext/http11/http11.c
@@ -9,6 +9,7 @@
 static VALUE mMongrel;
 static VALUE cHttpParser;
 static VALUE cURIClassifier;
+static int id_handler_map;
 
 
 void http_field(void *data, const char *field, size_t flen, const char *value, size_t vlen)
@@ -80,7 +81,7 @@ void HttpParser_free(void *data) {
 VALUE HttpParser_alloc(VALUE klass)
 {
     VALUE obj;
-    http_parser *hp = calloc(1, sizeof(http_parser));
+    http_parser *hp = ALLOC_N(http_parser, 1);
     TRACE();
     hp->http_field = http_field;
     hp->request_method = request_method;
@@ -281,7 +282,7 @@ VALUE URIClassifier_init(VALUE self)
 
   // we create an internal hash to protect stuff from the GC
   hash = rb_hash_new();
-  rb_iv_set(self, "handler_map", hash);
+  rb_ivar_set(self, id_handler_map, hash);
 }
 
 
@@ -317,7 +318,7 @@ VALUE URIClassifier_register(VALUE self, VALUE uri, VALUE handler)
     rb_raise(rb_eStandardError, "URI was empty");
   }
   
-  rb_hash_aset(rb_iv_get(self, "handler_map"), uri, handler);
+  rb_hash_aset(rb_ivar_get(self, id_handler_map), uri, handler);
 
   return Qnil;
 }
@@ -338,7 +339,7 @@ VALUE URIClassifier_unregister(VALUE self, VALUE uri)
   handler = tst_delete((unsigned char *)StringValueCStr(uri), tst);
 
   if(handler) {
-    rb_hash_delete(rb_iv_get(self, "handler_map"), uri);
+    rb_hash_delete(rb_ivar_get(self, id_handler_map), uri);
 
     return (VALUE)handler;
   } else {
@@ -408,13 +409,11 @@ VALUE URIClassifier_resolve(VALUE self, VALUE uri)
 }
 
 
-
 void Init_http11()
 {
-    
-  TRACE();
-  
+
   mMongrel = rb_define_module("Mongrel");
+  id_handler_map = rb_intern("@handler_map");
   
   cHttpParser = rb_define_class_under(mMongrel, "HttpParser", rb_cObject);
   rb_define_alloc_func(cHttpParser, HttpParser_alloc);
diff --git a/lib/mongrel.rb b/lib/mongrel.rb
index 28b88a2..4912b8a 100644
--- a/lib/mongrel.rb
+++ b/lib/mongrel.rb
@@ -189,6 +189,9 @@ module Mongrel
 
     # The basic max request size we'll try to read.
     CHUNK_SIZE=(16 * 1024)
+
+    PATH_INFO="PATH_INFO"
+    SCRIPT_NAME="SCRIPT_NAME"
     
     # Creates a working server on host:port (strange things happen if port isn't a Number).
     # Use HttpServer::run to start the server.
@@ -233,11 +236,11 @@ module Mongrel
         while true
           nread = parser.execute(params, data)
           if parser.finished?
-            script_name, path_info, handler = @classifier.resolve(params["PATH_INFO"])
+            script_name, path_info, handler = @classifier.resolve(params[PATH_INFO])
 
             if handler
-              params['PATH_INFO'] = path_info
-              params['SCRIPT_NAME'] = script_name
+              params[PATH_INFO] = path_info
+              params[SCRIPT_NAME] = script_name
 
               request = HttpRequest.new(params, data[nread ... data.length], client)
               response = HttpResponse.new(client)