From 6cc3faf14d54ec135036d83897d6eedca919c7cd Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 24 Nov 2012 11:14:44 +0100 Subject: [PATCH] improved QUERY_STRING management in router_rewrite --- plugins/http/http.c | 4 ++-- plugins/php/php_plugin.c | 11 ++++++++++- plugins/router_rewrite/router_rewrite.c | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/plugins/http/http.c b/plugins/http/http.c index fe805d66..aa57b583 100644 --- a/plugins/http/http.c +++ b/plugins/http/http.c @@ -399,9 +399,9 @@ int http_parse(struct http_session *h_session, size_t http_req_len) { while (ptr < watermark) { if (*ptr == '\r') { if (ptr + 1 >= watermark) - return 0; + break; if (*(ptr + 1) != '\n') - return 0; + break; // multiline header ? if (ptr + 2 < watermark) { if (*(ptr + 2) == ' ' || *(ptr + 2) == '\t') { diff --git a/plugins/php/php_plugin.c b/plugins/php/php_plugin.c index 1d746e9c..37916dc4 100644 --- a/plugins/php/php_plugin.c +++ b/plugins/php/php_plugin.c @@ -663,6 +663,16 @@ int uwsgi_php_init(void) { uwsgi_log("--- end of PHP custom config ---\n"); } + // fix docroot + if (uphp.docroot) { + char *orig_docroot = uphp.docroot; + uphp.docroot = uwsgi_expand_path(uphp.docroot, strlen(uphp.docroot), NULL); + if (!uphp.docroot) { + uwsgi_log("unable to set php docroot to %s\n", orig_docroot); + exit(1); + } + } + uwsgi_sapi_module.startup(&uwsgi_sapi_module); // filling http status codes @@ -917,7 +927,6 @@ secure2: secure3: - if (wsgi_req->document_root[wsgi_req->document_root_len-1] == '/') { wsgi_req->script_name = real_filename + (wsgi_req->document_root_len-1); } diff --git a/plugins/router_rewrite/router_rewrite.c b/plugins/router_rewrite/router_rewrite.c index 46230e94..e068293d 100644 --- a/plugins/router_rewrite/router_rewrite.c +++ b/plugins/router_rewrite/router_rewrite.c @@ -5,6 +5,8 @@ extern struct uwsgi_server uwsgi; int uwsgi_routing_func_rewrite(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) { + char *tmp_qs = NULL; + char **subject = (char **) (((char *)(wsgi_req))+ur->subject); uint16_t *subject_len = (uint16_t *) (((char *)(wsgi_req))+ur->subject_len); @@ -18,10 +20,21 @@ int uwsgi_routing_func_rewrite(struct wsgi_request *wsgi_req, struct uwsgi_route path_info_len = query_string - path_info; query_string++; query_string_len = strlen(query_string); - + if (wsgi_req->query_string_len > 0) { + tmp_qs = uwsgi_concat4n(query_string, query_string_len, "&", 1, wsgi_req->query_string, wsgi_req->query_string_len, "", 0); + query_string = tmp_qs; + query_string_len = strlen(query_string); + } } + // over engineering, could be requiredin the future... else { - query_string = ""; + if (wsgi_req->query_string_len > 0) { + query_string = wsgi_req->query_string; + query_string_len = wsgi_req->query_string_len; + } + else { + query_string = ""; + } } char *ptr = uwsgi_req_append(wsgi_req, "PATH_INFO", 9, path_info, path_info_len); @@ -39,12 +52,14 @@ int uwsgi_routing_func_rewrite(struct wsgi_request *wsgi_req, struct uwsgi_route wsgi_req->query_string_len = query_string_len; free(path_info); + if (tmp_qs) free(tmp_qs); if (ur->custom) return UWSGI_ROUTE_CONTINUE; return UWSGI_ROUTE_NEXT; clear: free(path_info); + if (tmp_qs) free(tmp_qs); return UWSGI_ROUTE_BREAK; }