Alvaro Lopez Ortega wrote:
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.
Please, ignore the previous patch, it was not right; test this new patch
instead.
Thanks!
--
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)
@@ -532,17 +532,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 +594,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 +623,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, "/");
+ if (conn->web_directory.len > 1) {
+ len += conn->web_directory.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);
+ while (len < conn->request.len) {
+ if (conn->request.buf[len] == '/') {
+ if (slashes == 1)
+ break;
+ slashes = 1;
+ }
+ len ++;
}
+
+ cherokee_buffer_add (&conn->pathinfo,
+ conn->request.buf + len,
+ conn->request.len - len);
+
return ret_ok;
}
Index: qa/153-SCGI-vars-root.py
===================================================================
--- qa/153-SCGI-vars-root.py (revision 1900)
+++ qa/153-SCGI-vars-root.py (working copy)
@@ -1,8 +1,10 @@
import os
from base import *
-PORT = get_free_port()
-REQUEST = "/dir1/dir2/file.ext"
+PORT = get_free_port()
+FILE = "/FakeFile"
+PATHINFO = "/dir1/dir2/file.ext"
+REQUEST = FILE + PATHINFO
SCRIPT = """
from pyscgi import *
@@ -33,8 +35,8 @@
"""
EXPECTED = [
- 'PATH_INFO: "%s"' % (REQUEST),
- 'SCRIPT_NAME: ""'
+ 'PATH_INFO: "%s"' % (PATHINFO),
+ 'SCRIPT_NAME: "%s"' % (FILE)
]
class Test (TestBase):
Index: qa/151-SCGI-vars.py
===================================================================
--- qa/151-SCGI-vars.py (revision 1900)
+++ qa/151-SCGI-vars.py (working copy)
@@ -30,8 +30,8 @@
"""
EXPECTED = [
- 'PATH_INFO: "/"',
- 'SCRIPT_NAME: "%s"' % (DIR)
+ 'PATH_INFO: ""',
+ 'SCRIPT_NAME: "%s/"' % (DIR)
]
class Test (TestBase):
Index: qa/152-SCGI-vars2.py
===================================================================
--- qa/152-SCGI-vars2.py (revision 1900)
+++ qa/152-SCGI-vars2.py (working copy)
@@ -2,8 +2,9 @@
from base import *
DIR = "/SCGI6"
+FILE = "virtual_file"
PATHINFO = "/dir1/dir2/dir3/looongfile.ext"
-REQUEST = "%s%s"%(DIR, PATHINFO)
+REQUEST = "%s/%s%s"%(DIR, FILE, PATHINFO)
PORT = get_free_port()
SCRIPT = """
@@ -33,7 +34,7 @@
EXPECTED = [
'PATH_INFO: "%s"' %(PATHINFO),
- 'SCRIPT_NAME: "%s"' % (DIR)
+ 'SCRIPT_NAME: "%s/%s"' % (DIR, FILE)
]
class Test (TestBase):
_______________________________________________
Cherokee mailing list
[email protected]
http://lists.octality.com/listinfo/cherokee