Add support for custom response headers

This commit is contained in:
Lauri Kasanen
2022-11-08 18:16:16 +02:00
parent 6b9f28760c
commit 17947d5f44
3 changed files with 118 additions and 30 deletions

View File

@@ -110,6 +110,11 @@ Run a mini-HTTP server which serves files from the given directory. Normally
the directory will contain the kasmweb client. It will use the websocket port.
.
.TP
.B \-H \fIheader=val\fP
Append this header to all HTTP responses (file and API). May be given multiple
times.
.
.TP
.B \-rfbauth \fIpasswd-file\fP, \-PasswordFile \fIpasswd-file\fP
Password file for VNC authentication. There is no default, you should
specify the password file explicitly. Password file should be created with

View File

@@ -155,6 +155,49 @@ static char displayNumStr[16];
static int vncVerbose = DEFAULT_LOG_VERBOSITY;
char *extra_headers = NULL;
unsigned extra_headers_len = 0;
static unsigned
add_extra_headers(const char * const arg)
{
unsigned i, found = 0;
const char *sep;
for (i = 0; arg[i]; i++) {
if (arg[i] == '=') {
found++;
sep = &arg[i];
}
}
if (found != 1)
return 0;
const unsigned len = strlen(arg);
if (len < 3)
return 0;
if (arg[0] == '=' || arg[len - 1] == '=')
return 0;
extra_headers = realloc(extra_headers, extra_headers_len + 4 + len);
extra_headers[extra_headers_len] = '\0';
char tmp[len + 3];
const unsigned firstlen = sep - arg;
memcpy(tmp, arg, firstlen);
tmp[firstlen] = ':';
tmp[firstlen + 1] = ' ';
memcpy(&tmp[firstlen + 2], sep + 1, len - firstlen - 1);
tmp[len + 1] = '\r';
tmp[len + 2] = '\n';
memcpy(&extra_headers[extra_headers_len], tmp, len + 3);
extra_headers_len += len + 3;
extra_headers[extra_headers_len] = '\0';
return 1;
}
static void
vncPrintBanner(void)
@@ -319,6 +362,7 @@ void ddxUseMsg(void)
ErrorF("-depth D set screen 0's depth\n");
ErrorF("-pixelformat fmt set pixel format (rgbNNN or bgrNNN)\n");
ErrorF("-inetd has been launched from inetd\n");
ErrorF("-H header=val append this header to all HTTP responses\n");
ErrorF("-noclipboard disable clipboard settings modification via vncconfig utility\n");
ErrorF("-verbose [n] verbose startup messages\n");
ErrorF("-quiet minimal startup messages\n");
@@ -530,6 +574,17 @@ ddxProcessArgument(int argc, char *argv[], int i)
return 2;
}
if (strcmp(argv[i], "-H") == 0)
{
fail_unless_args(argc, i, 1);
++i;
if (!add_extra_headers(argv[i])) {
ErrorF("Invalid argument\n");
return 0;
}
return 2;
}
if (strcmp(argv[i], "-pixelformat") == 0)
{
char rgbbgr[4];