UWSGI_MODIFIER_MANAGE_PATH_INFO implementation

This commit is contained in:
roberto@sirius
2009-11-24 18:03:47 +01:00
parent de0681bea0
commit e12cdfeb81
3 changed files with 80 additions and 2 deletions
+61 -2
View File
@@ -22,6 +22,9 @@ typedef struct {
ngx_array_t *uwsgi_lengths;
ngx_array_t *uwsgi_values;
u_char modifier1;
u_char modifier2;
} ngx_http_uwsgi_loc_conf_t;
typedef struct {
@@ -47,6 +50,12 @@ static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r);
static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r,
ngx_int_t rc);
static char *
ngx_http_uwsgi_modifier1(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *
ngx_http_uwsgi_modifier2(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_int_t ngx_http_uwsgi_add_variables(ngx_conf_t *cf);
static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf,
@@ -90,6 +99,20 @@ static ngx_command_t ngx_http_uwsgi_commands[] = {
0,
NULL },
{ ngx_string("uwsgi_modifier1"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_http_uwsgi_modifier1,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("uwsgi_modifier2"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_http_uwsgi_modifier2,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("uwsgi_ignore_client_abort"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
@@ -478,9 +501,9 @@ ngx_http_uwsgi_create_request(ngx_http_request_t *r)
cl->buf = b;
*b->pos = 0;
*b->pos = uwcf->modifier1;
b->last = ngx_cpymem(b->pos+1, &uwsgi_pkt_size, 2);
*(b->pos+3) = 0;
*(b->pos+3) = uwcf->modifier2;
b->last++;
if (uwcf->params_len) {
@@ -1297,6 +1320,14 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->uwsgi_values = prev->uwsgi_values;
}
if (conf->modifier1 == 0) {
conf->modifier1 = prev->modifier1;
}
if (conf->modifier2 == 0) {
conf->modifier2 = prev->modifier2;
}
if (conf->params_source == NULL) {
conf->flushes = prev->flushes;
conf->params_len = prev->params_len;
@@ -1489,3 +1520,31 @@ ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_OK;
}
static char *
ngx_http_uwsgi_modifier1(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_uwsgi_loc_conf_t *uwcf = conf;
ngx_str_t *value;
value = cf->args->elts;
uwcf->modifier1 = (u_char) ngx_atoi(value[1].data,value[1].len);
return NGX_CONF_OK;
}
static char *
ngx_http_uwsgi_modifier2(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_uwsgi_loc_conf_t *uwcf = conf;
ngx_str_t *value;
value = cf->args->elts;
uwcf->modifier2 = (u_char) ngx_atoi(value[1].data,value[1].len);
return NGX_CONF_OK;
}
+17
View File
@@ -599,6 +599,8 @@ int main(int argc, char *argv[], char *envp[]) {
setlinebuf(stdout);
char *path_info;
cwd = uwsgi_get_cwd();
binary_path = malloc(strlen(argv[0])+1) ;
if (binary_path == NULL) {
@@ -1501,6 +1503,21 @@ int main(int argc, char *argv[], char *envp[]) {
Py_DECREF(pydictvalue);
}
if (wsgi_req.modifier == UWSGI_MODIFIER_MANAGE_PATH_INFO) {
pydictkey = PyDict_GetItemString(wi->wsgi_environ,"SCRIPT_NAME");
if (pydictkey) {
if (PyString_Check(pydictkey)) {
pydictvalue = PyDict_GetItemString(wi->wsgi_environ,"PATH_INFO");
if (pydictvalue) {
if (PyString_Check(pydictvalue)) {
path_info = PyString_AsString(pydictvalue);
PyDict_SetItemString(wi->wsgi_environ, "PATH_INFO", PyString_FromString(path_info + PyString_Size(pydictkey)));
}
}
}
}
}
// set wsgi vars
+2
View File
@@ -46,6 +46,8 @@
#undef _XOPEN_SOURCE
#endif
#define UWSGI_MODIFIER_MANAGE_PATH_INFO 30
#ifdef PYTHREE
#define PyInt_FromLong PyLong_FromLong
#define PyInt_AsLong PyLong_AsLong