Add http_match_host and update 060_virtual_hosts_over_https.c

This commit is contained in:
2025-10-17 12:10:35 +02:00
parent e26042e2e7
commit 17ad7ad383
7 changed files with 47 additions and 14 deletions
@@ -92,17 +92,15 @@ int main(void)
if (ret < 0)
break;
int idx = http_find_header(req->headers, req->num_headers, HTTP_STR("Host"));
HTTP_ASSERT(idx != -1); // Requests without the host header are always rejected
HTTP_String host = req->headers[idx].value;
if (http_streq(host, HTTP_STR("websiteB.com"))) {
if (http_match_host(req, HTTP_STR("websiteB.com"), 8080) ||
http_match_host(req, HTTP_STR("websiteB.com"), 8443)) {
http_response_builder_status(builder, 200);
http_response_builder_body(builder, HTTP_STR("Hello from websiteB.com!"));
http_response_builder_done(builder);
} else if (http_streq(host, HTTP_STR("websiteC.com"))) {
} else if (http_match_host(req, HTTP_STR("websiteC.com"), 8080) ||
http_match_host(req, HTTP_STR("websiteC.com"), 8443)) {
http_response_builder_status(builder, 200);
http_response_builder_body(builder, HTTP_STR("Hello from websiteC.com!"));