From e929d08201aae949db25ae8c1051a91e96ba3011 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 27 Feb 2019 17:25:07 +0300 Subject: Fixed processing of SERVER_NAME after 77aad2c142a0. Previously, the nxt_router_prepare_msg() function expected server host among other headers unmodified. It's not true anymore since normalization of the Host header has been introduced in 77aad2c142a0. The nxt_unit_split_host() function was removed. It didn't work correctly with IPv6 literals. Anyway, after 77aad2c142a0 the port splitting is done in router while Host header processing. --- src/nxt_python_wsgi.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src/nxt_python_wsgi.c') diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c index bd3a2cb2..871c8e91 100644 --- a/src/nxt_python_wsgi.c +++ b/src/nxt_python_wsgi.c @@ -72,7 +72,7 @@ static PyObject *nxt_python_get_environ(nxt_python_run_ctx_t *ctx); static int nxt_python_add_sptr(nxt_python_run_ctx_t *ctx, const char *name, nxt_unit_sptr_t *sptr, uint32_t size); static int nxt_python_add_str(nxt_python_run_ctx_t *ctx, const char *name, - char *str, uint32_t size); + const char *str, uint32_t size); static PyObject *nxt_py_start_resp(PyObject *self, PyObject *args); static int nxt_python_response_add_field(nxt_python_run_ctx_t *ctx, @@ -690,8 +690,8 @@ static PyObject * nxt_python_get_environ(nxt_python_run_ctx_t *ctx) { int rc; - char *name, *host_start, *port_start; - uint32_t i, host_length, port_length; + char *name; + uint32_t i; PyObject *environ; nxt_unit_field_t *f; nxt_unit_request_t *r; @@ -732,6 +732,10 @@ nxt_python_get_environ(nxt_python_run_ctx_t *ctx) RC(nxt_python_add_sptr(ctx, "SERVER_PROTOCOL", &r->version, r->version_length)); + RC(nxt_python_add_sptr(ctx, "SERVER_NAME", &r->server_name, + r->server_name_length)); + RC(nxt_python_add_str(ctx, "SERVER_PORT", "80", 2)); + for (i = 0; i < r->fields_count; i++) { f = r->fields + i; name = nxt_unit_sptr_get(&f->name); @@ -753,23 +757,6 @@ nxt_python_get_environ(nxt_python_run_ctx_t *ctx) f->value_length)); } - if (r->host_field != NXT_UNIT_NONE_FIELD) { - f = r->fields + r->host_field; - - host_start = nxt_unit_sptr_get(&f->value); - host_length = f->value_length; - - } else { - host_start = NULL; - host_length = 0; - } - - nxt_unit_split_host(host_start, host_length, &host_start, &host_length, - &port_start, &port_length); - - RC(nxt_python_add_str(ctx, "SERVER_NAME", host_start, host_length)); - RC(nxt_python_add_str(ctx, "SERVER_PORT", port_start, port_length)); - #undef RC return environ; @@ -818,7 +805,7 @@ nxt_python_add_sptr(nxt_python_run_ctx_t *ctx, const char *name, static int nxt_python_add_str(nxt_python_run_ctx_t *ctx, const char *name, - char *str, uint32_t size) + const char *str, uint32_t size) { PyObject *value; -- cgit From 5bfdebb9e4161a689113d73775498949a09d7fb5 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 28 Feb 2019 18:02:42 +0300 Subject: Introducing Java Servlet Container beta. --- src/nxt_python_wsgi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nxt_python_wsgi.c') diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c index 871c8e91..80ffb0f7 100644 --- a/src/nxt_python_wsgi.c +++ b/src/nxt_python_wsgi.c @@ -105,6 +105,7 @@ NXT_EXPORT nxt_app_module_t nxt_app_module = { compat, nxt_string("python"), PY_VERSION, + NULL, nxt_python_init, }; -- cgit From a5dd0f8aa9b81921ff28c486a39fd46607dbdbd9 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Thu, 28 Feb 2019 20:20:41 +0300 Subject: Made QUERY_STRING mandatory. According to CGI/1.1 RFC 3875: The server MUST set this variable; if the Script-URI does not include a query component, the QUERY_STRING MUST be defined as an empty string (""). Python's PEP 333(3) allows omitting it in WSGI interface; PHP docs force no requirements; PSGI and Rack specifications require it even if empty. When nginx proxies requests over FastCGI, it always provides QUERY_STRING. and some PHP apps have been observed to fail if it is missing (see issue #201 on GitHub). A drawback of this change (besides a small overhead) is that there will be no easy way to tell a missing query string from an empty one (i.e. requests with or without the "?" character); yet, it's negligible compared to the possible benefits of wider application compatibility. This closes #226 issue on GitHub. --- src/nxt_python_wsgi.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/nxt_python_wsgi.c') diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c index 80ffb0f7..6478f38c 100644 --- a/src/nxt_python_wsgi.c +++ b/src/nxt_python_wsgi.c @@ -720,11 +720,7 @@ nxt_python_get_environ(nxt_python_run_ctx_t *ctx) RC(nxt_python_add_sptr(ctx, "REQUEST_METHOD", &r->method, r->method_length)); RC(nxt_python_add_sptr(ctx, "REQUEST_URI", &r->target, r->target_length)); - - if (r->query.offset) { - RC(nxt_python_add_sptr(ctx, "QUERY_STRING", &r->query, - r->query_length)); - } + RC(nxt_python_add_sptr(ctx, "QUERY_STRING", &r->query, r->query_length)); RC(nxt_python_add_sptr(ctx, "PATH_INFO", &r->path, r->path_length)); RC(nxt_python_add_sptr(ctx, "REMOTE_ADDR", &r->remote, r->remote_length)); -- cgit