fix(cgi): match pages host via SERVER_NAME fallback

CGI servers are not required to set HTTP_HOST. Fall back to SERVER_NAME:SERVER_PORT, omitting 80 and 443, and document the pages host contract. Also omit the redundant Status header on 200 file responses.

Assisted-by: OpenCode:DeepSeek-V4.1-Flash
This commit is contained in:
lotherk committed 2026-11-22 12:29:28 +00:00
1 parent 802572bae9
commit a5bc30bfaa
2 files changed
+28 -7

No files matched your search

+20 -1
View File
@@ -1862,6 +1862,24 @@ done:
return 0;
}
static const char *
request_host(char *buf, size_t len)
{
const char *host = getenv("HTTP_HOST");
const char *name, *port;
if (host != NULL && *host != '\0')
return host;
name = env_or("SERVER_NAME", "");
port = getenv("SERVER_PORT");
if (port != NULL && *port != '\0' && strcmp(port, "80") != 0 &&
strcmp(port, "443") != 0 && strchr(name, ':') == NULL) {
snprintf(buf, len, "%s:%s", name, port);
return buf;
}
return name;
}
static int
is_action(const char *s)
{
@@ -1907,6 +1925,7 @@ main(void)
{
const char *method, *decoded_env, *palette_file;
const char *pages_host, *http_host;
char hostbuf[PATHBUF];
char *decoded = NULL, *repo_path = NULL, *repo_name = NULL;
char *path = NULL;
struct path p;
@@ -1936,7 +1955,7 @@ main(void)
pages_host = getenv("GOTEA_PAGES_HOST");
if (pages_host != NULL && *pages_host != '\0') {
http_host = env_or("HTTP_HOST", env_or("SERVER_NAME", ""));
http_host = request_host(hostbuf, sizeof(hostbuf));
if (strcasecmp(http_host, pages_host) != 0) {
b_init(&body);
g_pages_mode = 1;