commit 24fadaef13e377e8dda3bec95b3d9b8a6f4438e1
parent e4f891c69bf1a9f695a90c1efce1fcac0d7c950c
Author: Joris Vink <joris@sanctorum.se>
Date: Tue, 18 Aug 2026 14:13:50 +0200
Add "http_header" config option for domains.
This configuration option allows you to specify HTTP headers
that are to be sent for each request in that domain.
One HTTP header per http_header configuration.
Example:
domain foo.bar {
http_header Access-Control-Allow-Origin https://bar.foo.bar
}
Diffstat:
4 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/include/kore/kore.h b/include/kore/kore.h
@@ -135,6 +135,7 @@ typedef void KORE_PRIVATE_KEY;
/* XXX hackish. */
#if !defined(KORE_NO_HTTP)
+struct http_header;
struct http_request;
struct http_redirect;
#endif
@@ -342,6 +343,12 @@ struct kore_route {
#endif
+struct kore_headers {
+ char *name;
+ char *value;
+ TAILQ_ENTRY(kore_headers) list;
+};
+
struct kore_domain {
u_int16_t id;
int logerr;
@@ -366,6 +373,7 @@ struct kore_domain {
int x509_verify_depth;
#if !defined(KORE_NO_HTTP)
TAILQ_HEAD(, kore_route) routes;
+ TAILQ_HEAD(, http_header) headers;
TAILQ_HEAD(, http_redirect) redirects;
#endif
TAILQ_ENTRY(kore_domain) list;
diff --git a/src/config.c b/src/config.c
@@ -129,6 +129,7 @@ static int configure_http_body_max(char *);
static int configure_http_body_timeout(char *);
static int configure_filemap_ext(char *);
static int configure_filemap_index(char *);
+static int configure_http_header(char *);
static int configure_http_media_type(char *);
static int configure_http_hsts_enable(char *);
static int configure_http_keepalive_time(char *);
@@ -256,6 +257,7 @@ static struct {
#if !defined(KORE_NO_HTTP)
{ "filemap_ext", configure_filemap_ext },
{ "filemap_index", configure_filemap_index },
+ { "http_header", configure_http_header },
{ "http_media_type", configure_http_media_type },
{ "http_header_max", configure_http_header_max },
{ "http_header_timeout", configure_http_header_timeout },
@@ -1403,6 +1405,31 @@ configure_filemap_index(char *index)
}
static int
+configure_http_header(char *options)
+{
+ struct http_header *hdr;
+ char *argv[4];
+
+ if (current_domain == NULL) {
+ kore_log(LOG_ERR, "add_header keyword not in domain context");
+ return (KORE_RESULT_ERROR);
+ }
+
+ if (kore_split_string(options, " ", argv, 3) != 2) {
+ kore_log(LOG_ERR, "missing parameters for add_header");
+ return (KORE_RESULT_ERROR);
+ }
+
+ hdr = kore_calloc(1, sizeof(*hdr));
+ hdr->header = kore_strdup(argv[0]);
+ hdr->value = kore_strdup(argv[1]);
+
+ TAILQ_INSERT_TAIL(&(current_domain->headers), hdr, list);
+
+ return (KORE_RESULT_OK);
+}
+
+static int
configure_http_media_type(char *type)
{
int i;
diff --git a/src/domain.c b/src/domain.c
@@ -64,6 +64,7 @@ kore_domain_new(const char *domain)
#if !defined(KORE_NO_HTTP)
TAILQ_INIT(&dom->routes);
+ TAILQ_INIT(&dom->headers);
TAILQ_INIT(&dom->redirects);
#endif
diff --git a/src/http.c b/src/http.c
@@ -682,10 +682,10 @@ void
http_response_fileref(struct http_request *req, int status,
struct kore_fileref *ref)
{
- struct tm *tm;
- time_t mtime;
- char tbuf[128];
- const char *media_type, *modified;
+ struct tm *tm;
+ time_t mtime;
+ char tbuf[128];
+ const char *media_type, *modified;
if (req->owner == NULL)
return;
@@ -2499,6 +2499,11 @@ http_response_normal(struct http_request *req, struct connection *c,
hdr->header, hdr->value);
}
+ TAILQ_FOREACH(hdr, &(req->rt->dom->headers), list) {
+ kore_buf_appendf(header_buf, "%s: %s\r\n",
+ hdr->header, hdr->value);
+ }
+
if (status != 204 && status >= 200 &&
!(req->flags & HTTP_REQUEST_NO_CONTENT_LENGTH)) {
kore_buf_appendf(header_buf,