Add http_match_host and update 060_virtual_hosts_over_https.c
This commit is contained in:
+18
-1
@@ -1,3 +1,4 @@
|
||||
#include <stdio.h> // snprintf
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@@ -1298,4 +1299,20 @@ int http_get_param_i(HTTP_String body, HTTP_String str)
|
||||
} while (cur < out.len && is_digit(out.ptr[cur]));
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
bool http_match_host(HTTP_Request *req, HTTP_String domain, int port)
|
||||
{
|
||||
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
|
||||
|
||||
char tmp[1<<8];
|
||||
if (port > -1 && port != 80) {
|
||||
int ret = snprintf(tmp, sizeof(tmp), "%.*s:%d", domain.len, domain.ptr, port);
|
||||
HTTP_ASSERT(ret > 0);
|
||||
domain = (HTTP_String) { tmp, ret };
|
||||
}
|
||||
|
||||
HTTP_String host = req->headers[idx].value;
|
||||
return http_streq(host, domain);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user