Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions src/java/nxt_jni_Request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
3 changes: 2 additions & 1 deletion src/nxt_php_sapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/perl/nxt_perl_psgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/python/nxt_python_asgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/python/nxt_python_wsgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 },
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down
6 changes: 2 additions & 4 deletions src/ruby/nxt_ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 },
Expand Down Expand Up @@ -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);

Expand Down
Loading