Permalink
Browse files

git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…

…7f1-0310-9951-d761b3857238
  • Loading branch information...
1 parent a5f3614 commit 0d3a69e0d3710206bd4a2b1329634f888e5788c4 @alobbs alobbs committed Feb 17, 2009
View
@@ -1,3 +1,24 @@
+2009-02-17 Alvaro Lopez Ortega <alvaro@octality.com>
+
+ * cherokee/handler_scgi.c, cherokee/handler_fcgi.c: These handlers
+ used to accept only the GET, POST and HEAD methods. REST services
+ are supposed to support more methods, so it's been a problem for
+ some people. I'm removing the check, and all methods will be
+ accepted from now on. Thanks to Jacob Wright <jacwright@gmail.com>
+ for reporting the problem. It fixes bug #364:
+ http://code.google.com/p/cherokee/issues/detail?id=364
+
+ * cherokee/connection-protected.h, cherokee/handler_error_redir.c,
+ cherokee/handler_cgi_base.c, cherokee/connection.c: Adds
+ REDIRECT_QUERY_STRING support.
+
+ * qa/195-ServerAddr.py (Test.CustomTest): Replaces the
+ 'expected_one_of_these' property by a CustomTest method. It's a
+ much cleaner solution.
+
+ * qa/base.py: Removes the ancient and no longer used
+ 'expected_content_length' and 'expected_one_of_these' properties.
+
2009-02-17 Antonio Perez <aperez@skarcha.com>
* cherokee/source_interpreter.c: We need a better check for
@@ -130,6 +130,7 @@ struct cherokee_connection {
cherokee_connection_phase_t phase;
cherokee_http_t error_code;
cherokee_buffer_t error_internal_url;
+ cherokee_buffer_t error_internal_qs;
/* Headers
*/
View
@@ -139,7 +139,9 @@ cherokee_connection_new (cherokee_connection_t **conn)
cherokee_buffer_init (&n->redirect);
cherokee_buffer_init (&n->host);
cherokee_buffer_init (&n->self_trace);
+
cherokee_buffer_init (&n->error_internal_url);
+ cherokee_buffer_init (&n->error_internal_qs);
cherokee_buffer_init (&n->query_string);
cherokee_buffer_init (&n->request_original);
@@ -197,7 +199,9 @@ cherokee_connection_free (cherokee_connection_t *conn)
cherokee_buffer_mrproper (&conn->host);
cherokee_buffer_mrproper (&conn->self_trace);
cherokee_buffer_mrproper (&conn->chunked_len);
+
cherokee_buffer_mrproper (&conn->error_internal_url);
+ cherokee_buffer_mrproper (&conn->error_internal_qs);
if (conn->validator != NULL) {
cherokee_validator_free (conn->validator);
@@ -304,7 +308,9 @@ cherokee_connection_clean (cherokee_connection_t *conn)
cherokee_buffer_clean (&conn->query_string);
cherokee_buffer_clean (&conn->self_trace);
cherokee_buffer_clean (&conn->chunked_len);
+
cherokee_buffer_clean (&conn->error_internal_url);
+ cherokee_buffer_clean (&conn->error_internal_qs);
if (conn->validator != NULL) {
cherokee_validator_free (conn->validator);
@@ -436,12 +436,17 @@ cherokee_handler_cgi_base_build_basic_env (
bind->server_address.len);
}
- /* Internal error redirection
+ /* Internal error redirection:
+ * It is okay if the QS is empty.
*/
if (! cherokee_buffer_is_empty (&conn->error_internal_url)) {
set_env (cgi, "REDIRECT_URL",
conn->error_internal_url.buf,
conn->error_internal_url.len);
+
+ set_env (cgi, "REDIRECT_QUERY_STRING",
+ conn->error_internal_qs.buf,
+ conn->error_internal_qs.len);
}
/* HTTP variables
@@ -143,11 +143,16 @@ static ret_t
do_redir_internal (cherokee_connection_t *conn,
error_entry_t *entry)
{
- /* REDIRECT_URL
+ /* Set REDIRECT_URL
*/
cherokee_buffer_clean (&conn->error_internal_url);
cherokee_buffer_add_buffer (&conn->error_internal_url, &conn->request);
+ /* Set REDIRECT_QUERY_STRING
+ */
+ cherokee_buffer_clean (&conn->error_internal_qs);
+ cherokee_buffer_add_buffer (&conn->error_internal_qs, &conn->query_string);
+
/* Clean up the connection
*/
cherokee_buffer_clean (&conn->pathinfo);
View
@@ -50,7 +50,7 @@ static void set_env_pair (cherokee_handler_cgi_base_t *cgi_base,
/* Plug-in initialization
*/
-CGI_LIB_INIT (fcgi, http_get | http_post | http_head);
+CGI_LIB_INIT (fcgi, http_all_methods);
/* Methods implementation
View
@@ -39,7 +39,7 @@
/* Plug-in initialization
*/
-CGI_LIB_INIT (scgi, http_get | http_post | http_head);
+CGI_LIB_INIT (scgi, http_all_methods);
/* Methods implementation
*/
@@ -100,15 +100,76 @@ interpreter_free (void *ptr)
CHEROKEE_MUTEX_DESTROY (&src->launching_mutex);
}
+static char *
+find_next_stop (char *p)
+{
+ char *s;
+ char *w;
+
+ s = strchr (p, '/');
+ w = strchr (p, ' ');
+
+ if ((s == NULL) && (w == NULL))
+ return NULL;
+
+ if (w == NULL)
+ return s;
+ if (s == NULL)
+ return w;
+
+ return (w > s) ? s : w;
+}
+
+static ret_t
+check_interpreter (cherokee_source_interpreter_t *src)
+{
+ int re;
+ struct stat inter;
+ char *p;
+ char tmp;
+ const char *end = src->interpreter.buf + src->interpreter.len;
+
+ p = find_next_stop (src->interpreter.buf + 1);
+ if (p == NULL)
+ return ret_error;
+
+ while (p <= end) {
+ /* Set a temporal end */
+ tmp = *p;
+ *p = '\0';
+
+ /* Does the file exist? */
+ re = cherokee_stat (src->interpreter.buf, &inter);
+ if ((re == 0) &&
+ (! S_ISDIR(inter.st_mode)))
+ {
+ *p = tmp;
+ return ret_ok;
+ }
+
+ *p = tmp;
+
+ /* Exit if already reached the end */
+ if (p >= end)
+ break;
+
+ /* Find the next position */
+ p = find_next_stop (p+1);
+ if (p == NULL)
+ p = (char *)end;
+ }
+
+ PRINT_ERROR ("ERROR: Could find interpreter '%s'\n", src->interpreter.buf);
+ return ret_error;
+}
+
ret_t
cherokee_source_interpreter_configure (cherokee_source_interpreter_t *src, cherokee_config_node_t *conf)
{
- int re;
ret_t ret;
cherokee_list_t *i, *j;
cherokee_config_node_t *child;
- struct stat inter;
/* Configure the base class
*/
@@ -160,8 +221,9 @@ cherokee_source_interpreter_configure (cherokee_source_interpreter_t *src, chero
return ret_error;
}
- /* TODO: Check if interpreter exists
- */
+ ret = check_interpreter (src);
+ if (ret != ret_ok)
+ return ret_error;
return ret_ok;
}
@@ -4,7 +4,6 @@
from util import *
MAGIC = str_random (100)
-LENGTH = 100
OFFSET1 = 15
OFFSET2 = 40
@@ -18,7 +17,12 @@ def __init__ (self):
"Range: bytes=%d-%d\r\n" % (OFFSET1, OFFSET2)
self.expected_error = 206
self.expected_content = [MAGIC[OFFSET1:OFFSET2], "Content-Length: %d" % (OFFSET2-OFFSET1 + 1)]
- self.forbidden_content = [MAGIC[OFFSET1:], MAGIC[:OFFSET2]]
+ self.forbidden_content = [MAGIC[:OFFSET1], MAGIC[:OFFSET2]]
+
+ def CustomTest (self):
+ body = self.reply.split ("\r\n\r\n")[1]
+ if len(body) != OFFSET2-OFFSET1 + 1:
+ return -1
def Prepare (self, www):
self.WriteFile (www, "Range100Both", 0444, MAGIC)
View
@@ -19,12 +19,22 @@ def __init__ (self):
TestBase.__init__ (self, __file__)
self.name = "CGI: SERVER_ADDR"
- self.request = "GET /%s/test HTTP/1.0\r\n" % (DIR)
- self.conf = CONF
- self.expected_one_of_these = ["127.0.0.1", "::1"]
- self.expected_error = 200
- self.proxy_suitable = False
+ self.request = "GET /%s/test HTTP/1.0\r\n" % (DIR)
+ self.conf = CONF
+ self.expected_error = 200
+ self.proxy_suitable = False
+
+ def CustomTest (self):
+ body = self.reply.split ("\r\n\r\n")[1]
+
+ if "127.0.0.1" in body:
+ return 0
+ if "::1" in body:
+ return 0
+
+ return -1
def Prepare (self, www):
self.Mkdir (www, DIR)
self.WriteFile (www, "%s/test"%(DIR), 0755, CGI_BASE)
+
View
@@ -39,8 +39,6 @@ def __init__ (self, file):
self.post = None
self.expected_error = None
self.expected_content = None
- self.expected_content_length = None
- self.expected_one_of_these = None
self.forbidden_content = None
self._initialize()
@@ -145,12 +143,6 @@ def _check_result_expected_item (self, item):
if not item in self.reply:
return -1
- def _check_result_expected_one_of_these (self, items):
- for item in items:
- r = self._check_result_expected_item (item)
- if r != -1: return r
- return -1
-
def _check_result_forbidden_item (self, item):
if item.startswith("file:"):
f = open (item[5:])
@@ -166,38 +158,35 @@ def _check_result (self):
if self.reply_err != self.expected_error:
return -1
- if self.expected_content_length != None:
- if len(self.reply) != self.expected_content_length:
- return -1
-
if self.expected_content != None:
if type(self.expected_content) == types.StringType:
r = self._check_result_expected_item (self.expected_content)
- if r == -1: return -1
+ if r == -1:
+ return -1
elif type(self.expected_content) == types.ListType:
for entry in self.expected_content:
r = self._check_result_expected_item (entry)
- if r == -1: return -1
+ if r == -1:
+ return -1
else:
raise Exception("Syntax error")
- if self.expected_one_of_these != None:
- r = self._check_result_expected_one_of_these (self.expected_one_of_these)
- if r == -1: return -1
-
if self.forbidden_content != None:
if type(self.forbidden_content) == types.StringType:
r = self._check_result_forbidden_item (self.forbidden_content)
- if r == -1: return -1
+ if r == -1:
+ return -1
elif type(self.forbidden_content) == types.ListType:
for entry in self.forbidden_content:
r = self._check_result_forbidden_item (entry)
- if r == -1: return -1
+ if r == -1:
+ return -1
else:
raise Exception("Syntax error")
r = self.CustomTest()
- if r == -1: return -1
+ if r == -1:
+ return -1
return 0
@@ -254,15 +243,9 @@ def __str__ (self):
else:
src += "\tExpected = Code: UNSET!\n"
- if self.expected_content_length is not None:
- src += "\tExpected = Content length: %d\n" % (self.expected_content_length)
-
if self.expected_content is not None:
src += "\tExpected = Content: %s\n" % (self.expected_content)
- if self.expected_one_of_these is not None:
- src += "\tExpected = one: %s\n" % (str(self.expected_one_of_these))
-
if self.forbidden_content is not None:
src += "\tForbidden= Content: %s\n" % (self.forbidden_content)

0 comments on commit 0d3a69e

Please sign in to comment.