Rui Lopes wrote:
Alvaro Lopez Ortega wrote:
Hi there Rui!

My original cherokee setup was:

vserver!1!rule!10000!match = directory
vserver!1!rule!10000!match!directory = /demo

but if I change it to:

vserver!1!rule!10000!match = directory
vserver!1!rule!10000!match!directory = /

it to works without changing django, though, I would like to have several django scgi apps mounted on different places, eg:

/demo1   -->  scgi_app1
/demo2   -->  scgi_app2

Do you have an example of what would be the expected PATH_INFO and SCRIPT_NAME in a case like those? (I don't think 'runserver' allows that, does it?).

Please note that I'm not sure what should appear in those variables. All
I known is what I've observed and written in the original email,

Could you please check whether this patch fixes your problem?

This part of the code is quite tricky, so we must be extra careful when modifying it. If it works for you, I will commit the change in trunk. Additionally, I will also add a new QA test to cover the case and ensure there will not be any regression.

Cheers!

--
Greetings, alo
http://www.alobbs.com/
Index: cherokee/handler_cgi_base.c
===================================================================
--- cherokee/handler_cgi_base.c	(revision 1910)
+++ cherokee/handler_cgi_base.c	(working copy)
@@ -503,6 +503,7 @@
 	ret_t                               ret;
 	cherokee_list_t                    *i;
 	cherokee_buffer_t                  *name;
+	cuint_t                             slashes  = 0;
 	cuint_t                             len      = 0;
 	char                               *p        = "";
 	cherokee_buffer_t                  tmp       = CHEROKEE_BUF_INIT;
@@ -532,17 +533,24 @@
 	if (unlikely (ret != ret_ok)) return ret;
 
 	/* SCRIPT_NAME:
-	 * It is the request without the pathinfo if it exists
+	 * RFC 3875: "URI path identifying the CGI script".
+	 *
+	 * For a CGI, it is the request without the PATHINFO, if any
+	 *
+	 * For a SCGI and FCGI, it is the request minus the pathinfo,
+	 * which is request until the second slash character beginning
+	 * at webdir length.
+	 * 
 	 */
 	cherokee_buffer_clean (&tmp);
 
 	if (! cgi_props->check_file) {
-		/* SCGI or FastCGI */
+		/* SCGI or FastCGI
+		 */
+		cherokee_buffer_add (&tmp,
+				     conn->request.buf,
+				     conn->request.len - conn->pathinfo.len);
 
-		if (conn->web_directory.len > 1) {
-			cherokee_buffer_add_buffer (&tmp, &conn->web_directory);
-		}
-		
 		cgi->add_env_pair (cgi, "SCRIPT_NAME", 11, tmp.buf, tmp.len);
 
 	} else {
@@ -587,6 +595,8 @@
 	cint_t                             req_len;
 	cint_t                             local_len;
 	struct stat                        st;
+	cuint_t                            len          = 0;
+	cuint_t                            slashes      = 0;
 	cint_t                             pathinfo_len = 0;
 	cherokee_connection_t             *conn         = HANDLER_CONN(cgi);
 	cherokee_handler_cgi_base_props_t *props        = HANDLER_CGI_BASE_PROPS(cgi);
@@ -614,21 +624,43 @@
 	}
 
 	/* No file checking: mainly for FastCGI and SCGI
+	 * Examples:
+	 *
+	 * Webdir:         /demo/subdirectory
+	 * Request:        http://localhost/demo/subdirectory/
+	 * SCRIPT_NAME':   /demo/subdirectory/
+	 * PATH_INFO:      <empty>
+	 * 
+	 * Webdir:         /
+	 * Request         http://localhost/another/large/one/foo
+	 * SCRIPT_NAME:    /another
+	 * PATH_INFO:      /large/one/foo
+	 *
+	 * Webdir:         /
+	 * Request:        http://localhost/
+	 * SCRIPT_NAME:    /
+	 * PATH_INFO:      <empty>
 	 */
 	if ((! props->check_file) &&
-	    (! cherokee_buffer_is_empty(&conn->web_directory))) 
+	    (! cherokee_buffer_is_empty (&conn->web_directory))) 
 	{
-		if (conn->request.len == 1) {
-			cherokee_buffer_add_str (&conn->pathinfo, "/");
+		while (len < conn->request.len) {
+			if (conn->request.buf[len] == '/') {
+				if (slashes == 1) 
+					break;
+				slashes = 1;
+			}
+			len ++;
+		}
 
-		} else if (conn->web_directory.len == 1) {
-			cherokee_buffer_add_buffer (&conn->pathinfo, &conn->request);
-						    
-		} else {
-			cherokee_buffer_add (&conn->pathinfo,
-					     conn->request.buf + conn->web_directory.len,
-					     conn->request.len - conn->web_directory.len);
+		if (conn->web_directory.len > 1) {
+			len += conn->web_directory.len;
 		}
+
+		cherokee_buffer_add (&conn->pathinfo, 
+				     conn->request.buf + len,
+				     conn->request.len - len);
+
 		return ret_ok;
 	}
 
_______________________________________________
Cherokee mailing list
[email protected]
http://lists.octality.com/listinfo/cherokee

Reply via email to