From c8b859e373089d3f347efb806c9926823de41bf6 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Fri, 4 Jul 2025 16:38:25 +0100 Subject: Set SERVER_PORT appropriately The Perl, PHP, Python, Ruby & Java language modules all hard code SERVER_PORT to "80". Adjust them to bring them in line with the wasm language module which uses r->local_port (I.e. the port unit accepted the connection on). Closes: https://github.com/nginx/unit/issues/761 Signed-off-by: Andrew Clayton --- src/java/nxt_jni_Request.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'src/java') diff --git a/src/java/nxt_jni_Request.c b/src/java/nxt_jni_Request.c index 980a26b6..bc0d56dc 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); } -- cgit