Skip to content

Commit

Permalink
http server: add "HTTP_SRV_REQ_P_F_HOST_ANY_PORT" flag to "Request pr…
Browse files Browse the repository at this point in the history
…ocessing flags" to allow match host even if port number not eququal
  • Loading branch information
rozhuk-im committed Feb 16, 2025
1 parent f4e0e6f commit 3d8681e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/proto/http_server.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2011 - 2018 Rozhuk Ivan <[email protected]>
* Copyright (c) 2011-2025 Rozhuk Ivan <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Light Code Base

Rozhuk Ivan <[email protected]> 2011-2024
Rozhuk Ivan <[email protected]> 2011-2025

Statically linked code library.
Compile and include only things that you need.
Expand Down
11 changes: 7 additions & 4 deletions src/proto/http_server.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2011-2024 Rozhuk Ivan <[email protected]>
* Copyright (c) 2011-2025 Rozhuk Ivan <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -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;
Expand All @@ -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 [::]. */
Expand Down Expand Up @@ -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))) {
Expand Down

0 comments on commit 3d8681e

Please sign in to comment.