diff --git a/src/java/nxt_jni_Request.c b/src/java/nxt_jni_Request.c index 980a26b68..bc0d56dc0 100644 --- a/src/java/nxt_jni_Request.c +++ b/src/java/nxt_jni_Request.c @@ -624,36 +624,14 @@ nxt_java_Request_getServerName(JNIEnv *env, jclass cls, jlong req_ptr) static jint JNICALL nxt_java_Request_getServerPort(JNIEnv *env, jclass cls, jlong req_ptr) { - jint res; - char *host, *colon, tmp; - nxt_unit_field_t *f; + char *p; nxt_unit_request_t *r; r = nxt_jlong2ptr(req_ptr); - f = nxt_java_findHeader(r->fields, r->fields + r->fields_count, - "Host", 4); - if (f != NULL) { - host = nxt_unit_sptr_get(&f->value); - - colon = memchr(host, ':', f->value_length); - - if (colon == NULL) { - return 80; - } - - tmp = host[f->value_length]; - - host[f->value_length] = '\0'; - - res = strtol(colon + 1, NULL, 10); - - host[f->value_length] = tmp; - - return res; - } + p = nxt_unit_sptr_get(&r->local_port); - return nxt_java_Request_getLocalPort(env, cls, req_ptr); + return strtol(p, NULL, 10); } diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c index da667b660..c20e074cf 100644 --- a/src/nxt_php_sapi.c +++ b/src/nxt_php_sapi.c @@ -1500,7 +1500,8 @@ nxt_php_register_variables(zval *track_vars_array TSRMLS_DC) nxt_php_set_sptr(req, "SERVER_NAME", &r->server_name, r->server_name_length, track_vars_array TSRMLS_CC); - nxt_php_set_cstr(req, "SERVER_PORT", "80", 2, track_vars_array TSRMLS_CC); + nxt_php_set_sptr(req, "SERVER_PORT", &r->local_port, r->local_port_length, + track_vars_array TSRMLS_CC); if (r->tls) { nxt_php_set_cstr(req, "HTTPS", "on", 2, track_vars_array TSRMLS_CC); diff --git a/src/perl/nxt_perl_psgi.c b/src/perl/nxt_perl_psgi.c index 587656cd4..c16b21737 100644 --- a/src/perl/nxt_perl_psgi.c +++ b/src/perl/nxt_perl_psgi.c @@ -673,7 +673,8 @@ nxt_perl_psgi_env_create(PerlInterpreter *my_perl, RC(nxt_perl_psgi_add_sptr(my_perl, hash_env, NL("SERVER_NAME"), &r->server_name, r->server_name_length)); - RC(nxt_perl_psgi_add_str(my_perl, hash_env, NL("SERVER_PORT"), "80", 2)); + RC(nxt_perl_psgi_add_sptr(my_perl, hash_env, NL("SERVER_PORT"), + &r->local_port, r->local_port_length)); for (i = 0; i < r->fields_count; i++) { f = r->fields + i; diff --git a/src/python/nxt_python_asgi.c b/src/python/nxt_python_asgi.c index 702f4d8d0..a123e9411 100644 --- a/src/python/nxt_python_asgi.c +++ b/src/python/nxt_python_asgi.c @@ -644,6 +644,7 @@ nxt_py_asgi_create_http_scope(nxt_unit_request_info_t *req, PyObject *scope, *v, *type, *scheme; PyObject *headers, *header; nxt_str_t prefix; + unsigned long port; nxt_unit_field_t *f; nxt_unit_request_t *r; @@ -752,7 +753,10 @@ nxt_py_asgi_create_http_scope(nxt_unit_request_info_t *req, SET_ITEM(scope, client, v) Py_DECREF(v); - v = nxt_py_asgi_create_address(&r->local_addr, r->local_addr_length, 80); + p = nxt_unit_sptr_get(&r->local_port); + port = strtoul(p, NULL, 10); + + v = nxt_py_asgi_create_address(&r->local_addr, r->local_addr_length, port); if (nxt_slow_path(v == NULL)) { nxt_unit_req_alert(req, "Python failed to create 'server' pair"); goto fail; diff --git a/src/python/nxt_python_wsgi.c b/src/python/nxt_python_wsgi.c index ec9fefcab..6bbf9e397 100644 --- a/src/python/nxt_python_wsgi.c +++ b/src/python/nxt_python_wsgi.c @@ -131,7 +131,6 @@ static PyTypeObject nxt_py_input_type = { static PyObject *nxt_py_environ_ptyp; -static PyObject *nxt_py_80_str; static PyObject *nxt_py_close_str; static PyObject *nxt_py_content_length_str; static PyObject *nxt_py_content_type_str; @@ -151,7 +150,6 @@ static PyObject *nxt_py_wsgi_input_str; static PyObject *nxt_py_wsgi_uri_scheme_str; static nxt_python_string_t nxt_python_strings[] = { - { nxt_string("80"), &nxt_py_80_str }, { nxt_string("close"), &nxt_py_close_str }, { nxt_string("CONTENT_LENGTH"), &nxt_py_content_length_str }, { nxt_string("CONTENT_TYPE"), &nxt_py_content_type_str }, @@ -638,6 +636,8 @@ nxt_python_get_environ(nxt_python_ctx_t *pctx, r->remote_length)); RC(nxt_python_add_sptr(pctx, nxt_py_server_addr_str, &r->local_addr, r->local_addr_length)); + RC(nxt_python_add_sptr(pctx, nxt_py_server_port_str, &r->local_port, + r->local_port_length)); if (r->tls) { RC(nxt_python_add_obj(pctx, nxt_py_wsgi_uri_scheme_str, @@ -652,7 +652,6 @@ nxt_python_get_environ(nxt_python_ctx_t *pctx, RC(nxt_python_add_sptr(pctx, nxt_py_server_name_str, &r->server_name, r->server_name_length)); - RC(nxt_python_add_obj(pctx, nxt_py_server_port_str, nxt_py_80_str)); nxt_unit_request_group_dup_fields(pctx->req); diff --git a/src/ruby/nxt_ruby.c b/src/ruby/nxt_ruby.c index 717816df8..c0befdb3b 100644 --- a/src/ruby/nxt_ruby.c +++ b/src/ruby/nxt_ruby.c @@ -106,7 +106,6 @@ typedef struct { VALUE *v; } nxt_ruby_string_t; -static VALUE nxt_rb_80_str; static VALUE nxt_rb_content_length_str; static VALUE nxt_rb_content_type_str; static VALUE nxt_rb_http_str; @@ -127,7 +126,6 @@ static VALUE nxt_rb_on_thread_boot; static VALUE nxt_rb_on_thread_shutdown; static nxt_ruby_string_t nxt_rb_strings[] = { - { nxt_string("80"), &nxt_rb_80_str }, { nxt_string("CONTENT_LENGTH"), &nxt_rb_content_length_str }, { nxt_string("CONTENT_TYPE"), &nxt_rb_content_type_str }, { nxt_string("http"), &nxt_rb_http_str }, @@ -754,11 +752,11 @@ nxt_ruby_read_request(nxt_unit_request_info_t *req, VALUE hash_env) r->remote_length); nxt_ruby_add_sptr(hash_env, nxt_rb_server_addr_str, &r->local_addr, r->local_addr_length); + nxt_ruby_add_sptr(hash_env, nxt_rb_server_port_str, &r->local_port, + r->local_port_length); nxt_ruby_add_sptr(hash_env, nxt_rb_server_name_str, &r->server_name, r->server_name_length); - rb_hash_aset(hash_env, nxt_rb_server_port_str, nxt_rb_80_str); - rb_hash_aset(hash_env, nxt_rb_rack_url_scheme_str, r->tls ? nxt_rb_https_str : nxt_rb_http_str);