about summary refs log tree commit homepage
path: root/ext
diff options
context:
space:
mode:
authorzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-02-10 02:38:18 +0000
committerzedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9>2006-02-10 02:38:18 +0000
commitbce8665853fd1ef66771e462247c9712cf18f0b1 (patch)
tree566ebed98b6c8c94292894771c21fb799013481f /ext
parent3c343cca6b736e43c6145ebdf60aed2cd61b912c (diff)
downloadunicorn-bce8665853fd1ef66771e462247c9712cf18f0b1.tar.gz
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@24 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'ext')
-rw-r--r--ext/http11/http11.c22
-rw-r--r--ext/http11/tst_search.c5
2 files changed, 21 insertions, 6 deletions
diff --git a/ext/http11/http11.c b/ext/http11/http11.c
index c2659c4..5dc5e09 100644
--- a/ext/http11/http11.c
+++ b/ext/http11/http11.c
@@ -341,7 +341,9 @@ VALUE URIClassifier_unregister(VALUE self, VALUE uri)
  *    uc.resolve("/someuri") -> "/someuri", "", handler
  *    uc.resolve("/someuri/pathinfo") -> "/someuri", "/pathinfo", handler
  *    uc.resolve("/notfound/orhere") -> nil, nil, nil
- *
+ *    uc.resolve("/") -> "/", "/", handler  # if uc.register("/", handler)
+ *    uc.resolve("/path/from/root") -> "/", "/path/from/root", handler  # if uc.register("/", handler)
+ *
  * Attempts to resolve either the whole URI or at the longest prefix, returning
  * the prefix (as script_info), path (as path_info), and registered handler
  * (usually an HttpHandler).  If it doesn't find a handler registered at the longest
@@ -358,7 +360,13 @@ VALUE URIClassifier_unregister(VALUE self, VALUE uri)
  * It also means that it's very efficient to do this only taking as long as the URI has
  * characters.
  *
- * It expects strings with no embedded '\0' characters.  Don't try other string-line stuff yet.
+ * A slight modification to the CGI 1.2 standard is given for handlers registered to "/".
+ * CGI expects all CGI scripts to be at some script path, so it doesn't really say anything
+ * about a script that handles the root.  To make this work, the resolver will detect that
+ * the requested handler is at "/", and return that for script_name, and then simply return
+ * the full URI back as path_info.
+ *
+ * It expects strings with no embedded '\0' characters.  Don't try other string-like stuff yet.
  */
 VALUE URIClassifier_resolve(VALUE self, VALUE uri)
 {
@@ -379,7 +387,15 @@ VALUE URIClassifier_resolve(VALUE self, VALUE uri)
 
   if(handler) {
     rb_ary_push(result, rb_str_substr (uri, 0, pref_len));
-    rb_ary_push(result, rb_str_substr(uri, pref_len, RSTRING(uri)->len));
+    // compensate for a script_name="/" where we need to add the "/" to path_info to keep it consistent
+    if(pref_len == 1 && uri_str[0] == '/') {
+      // matches the root URI so we have to use the whole URI as the path_info
+      rb_ary_push(result, uri);
+    } else {
+      // matches a script so process like normal
+      rb_ary_push(result, rb_str_substr(uri, pref_len, RSTRING(uri)->len));
+    }
+      
     rb_ary_push(result, (VALUE)handler);
   } else {
     // not found so push back nothing
diff --git a/ext/http11/tst_search.c b/ext/http11/tst_search.c
index 4cfe6ff..44aee7a 100644
--- a/ext/http11/tst_search.c
+++ b/ext/http11/tst_search.c
@@ -32,7 +32,6 @@ void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len)
             if(prefix_len) *prefix_len = key_index;
             return current_node->middle;
           } else {
-
             current_node = current_node->middle;
             if(current_node && current_node->value == 0) {
               if(prefix_len) *prefix_len = key_index+1;
@@ -47,7 +46,7 @@ void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len)
                ((current_node->value != 0) && (key[key_index] <
                                                current_node->value)) )
         {
-          if(current_node->left && current_node->value == 0) {
+          if(current_node->value == 0) {
             if(prefix_len) *prefix_len = key_index;
             longest_match = current_node->middle;
           }
@@ -56,7 +55,7 @@ void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len)
         }
       else
         {
-          if(current_node->right && current_node->value == 0) {
+          if(current_node->value == 0) {
             if(prefix_len) *prefix_len = key_index;
             longest_match = current_node->middle;
           }