Sat, 07 Mar 2026 16:05:41 +0100
add host-header parameter for the reverse-proxy saf
| src/server/safs/proxy.c | file | annotate | diff | comparison | revisions |
--- a/src/server/safs/proxy.c Sat Mar 07 15:29:11 2026 +0100 +++ b/src/server/safs/proxy.c Sat Mar 07 16:05:41 2026 +0100 @@ -316,6 +316,8 @@ const char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); const char *query = pblock_findkeyval(pb_key_query, rq->reqpb); + char *host_header = pblock_findval("host-header", param); + const char *location = pblock_findval("location", param); if(location) { cxstring loc = cx_str(location); @@ -414,7 +416,9 @@ // Some request/response headers should be removed or altered // An empty string means, the header should be removed - pblock_nvinsert("host", "", proxy->request_header_rewrite); + if(!host_header) { + pblock_nvinsert("host", "", proxy->request_header_rewrite); + } //pblock_nvinsert("connection", "", proxy->request_header_rewrite); pblock_nvinsert("transfer-encoding", "", proxy->request_header_rewrite); pblock_nvinsert("content-length", "", proxy->request_header_rewrite); @@ -467,15 +471,20 @@ return REQ_ABORTED; } + // prepare host header + if(!host_header) { + if(!((srv_url.scheme_num == WS_URI_HTTP && srv_url.port == 80) || + (srv_url.scheme_num == WS_URI_HTTPS && srv_url.port == 443))) + { + // we have reserved enough space for the port + srvhost[srv_url.hostlen] = ':'; + snprintf(srvhost + srv_url.hostlen + 1, 8, "%d", (int)srv_url.port); + } + host_header = srvhost; + } + // add host header - if(!((srv_url.scheme_num == WS_URI_HTTP && srv_url.port == 80) || - (srv_url.scheme_num == WS_URI_HTTPS && srv_url.port == 443))) - { - // we have reserved enough space for the port - srvhost[srv_url.hostlen] = ':'; - snprintf(srvhost + srv_url.hostlen, 8, "%d", (int)srv_url.port); - } - if(http_client_add_request_header(client, cx_mutstr("host"), cx_mutstr(srvhost))) { + if(http_client_add_request_header(client, cx_mutstr("host"), cx_mutstr(host_header))) { http_client_free(client); return REQ_ABORTED; }