diff --git a/include/proto/http_server.h b/include/proto/http_server.h index 83302e4..e0e3b3c 100644 --- a/include/proto/http_server.h +++ b/include/proto/http_server.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2011 - 2018 Rozhuk Ivan + * Copyright (c) 2011-2025 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -141,6 +141,7 @@ typedef struct http_srv_settings_s { /* Settings */ /* Request processing flags. */ #define HTTP_SRV_REQ_P_F_CONNECTION (((uint32_t)1) << 0) /* process 'connection' header value. */ #define HTTP_SRV_REQ_P_F_HOST (((uint32_t)1) << 1) /* process 'host' header value. */ +#define HTTP_SRV_REQ_P_F_HOST_ANY_PORT (((uint32_t)1) << 2) /* process 'host' header value, ignore port match. */ /* Responce processing flags. */ #define HTTP_SRV_RESP_P_F_CONN_CLOSE (((uint32_t)1) << 0) /* force 'Connection: close', use single IO_BUF for send and recv. */ #define HTTP_SRV_RESP_P_F_SERVER (((uint32_t)1) << 1) /* add 'Server' in answer. */ diff --git a/readme.md b/readme.md index 1a4d2e9..a40fe4d 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ Light Code Base -Rozhuk Ivan 2011-2024 +Rozhuk Ivan 2011-2025 Statically linked code library. Compile and include only things that you need. diff --git a/src/proto/http_server.c b/src/proto/http_server.c index bc8c13e..71f5b9c 100644 --- a/src/proto/http_server.c +++ b/src/proto/http_server.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2011-2024 Rozhuk Ivan + * Copyright (c) 2011-2025 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -1324,7 +1324,8 @@ http_srv_recv_done_cb(tp_task_p tptask, int error, io_buf_p buf, if (0 == host_port) { /* Def http port. */ host_port = HTTP_PORT; } - if (sa_port_get(&bnd->s.addr) == host_port && + if ((0 != (HTTP_SRV_REQ_P_F_HOST_ANY_PORT & srv->s.req_p_flags) || + sa_port_get(&bnd->s.addr) == host_port) && (0 == hostname_list_check_any(&bnd->hst_name_lst) || 0 == hostname_list_check_any(&srv->hst_name_lst))) { cli->req.flags |= HTTP_SRV_RD_F_HOST_IS_LOCAL; @@ -1333,7 +1334,8 @@ http_srv_recv_done_cb(tp_task_p tptask, int error, io_buf_p buf, arg = NULL; /* Addr info cache. */ for (i = 0; i < srv->bind_count; i ++) { if (srv->bnd[i]->s.addr.ss_family != addr.ss_family || - sa_port_get(&srv->bnd[i]->s.addr) != host_port) /* not equal port! */ + (0 == (HTTP_SRV_REQ_P_F_HOST_ANY_PORT & srv->s.req_p_flags) && + sa_port_get(&srv->bnd[i]->s.addr) != host_port)) /* not equal port! */ continue; if (0 == sa_addr_is_specified(&srv->bnd[i]->s.addr)) { /* Binded to: 0.0.0.0 or [::]. */ @@ -1368,7 +1370,8 @@ http_srv_recv_done_cb(tp_task_p tptask, int error, io_buf_p buf, 0 == sa_addr_is_loopback(&cli->addr)) /* from ext host? */ goto conn_from_net_to_loopback; /* Is hostname point to this host? */ - if (sa_port_get(&bnd->s.addr) == host_port && + if ((0 != (HTTP_SRV_REQ_P_F_HOST_ANY_PORT & srv->s.req_p_flags) || + sa_port_get(&bnd->s.addr) == host_port) && (0 != action || 0 == hostname_list_check(&bnd->hst_name_lst, cli->req.host, tm) || 0 == hostname_list_check(&srv->hst_name_lst, cli->req.host, tm))) {