Commit dbbd22f7 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Cleanup: Set Connection:-Header via client->reuse

parent 68248d15
...@@ -201,6 +201,8 @@ void client_send_error(client_t *client, int status, int plain, const char *mess ...@@ -201,6 +201,8 @@ void client_send_error(client_t *client, int status, int plain, const char *mess
return; return;
} }
client->reuse = ICECAST_REUSE_KEEPALIVE;
ret = util_http_build_header(client->refbuf->data, PER_CLIENT_REFBUF_SIZE, 0, ret = util_http_build_header(client->refbuf->data, PER_CLIENT_REFBUF_SIZE, 0,
0, status, NULL, 0, status, NULL,
plain ? "text/plain" : "text/html", "utf-8", plain ? "text/plain" : "text/html", "utf-8",
...@@ -223,15 +225,13 @@ void client_send_error(client_t *client, int status, int plain, const char *mess ...@@ -223,15 +225,13 @@ void client_send_error(client_t *client, int status, int plain, const char *mess
data->len = strlen(data->data); data->len = strlen(data->data);
snprintf(client->refbuf->data + ret, PER_CLIENT_REFBUF_SIZE - ret, snprintf(client->refbuf->data + ret, PER_CLIENT_REFBUF_SIZE - ret,
"Content-Length: %llu\r\nConnection: Keep-Alive\r\n\r\n", "Content-Length: %llu\r\n\r\n",
(long long unsigned int)data->len); (long long unsigned int)data->len);
client->respcode = status; client->respcode = status;
client->refbuf->len = strlen (client->refbuf->data); client->refbuf->len = strlen (client->refbuf->data);
client->refbuf->next = data; client->refbuf->next = data;
client->reuse = ICECAST_REUSE_KEEPALIVE;
fserve_add_client (client, NULL); fserve_add_client (client, NULL);
} }
...@@ -253,19 +253,19 @@ void client_send_101(client_t *client, reuse_t reuse) ...@@ -253,19 +253,19 @@ void client_send_101(client_t *client, reuse_t reuse)
return; return;
} }
client->reuse = reuse;
ret = util_http_build_header(client->refbuf->data, PER_CLIENT_REFBUF_SIZE, 0, ret = util_http_build_header(client->refbuf->data, PER_CLIENT_REFBUF_SIZE, 0,
0, 101, NULL, 0, 101, NULL,
"text/plain", "utf-8", "text/plain", "utf-8",
NULL, NULL, client); NULL, NULL, client);
snprintf(client->refbuf->data + ret, PER_CLIENT_REFBUF_SIZE - ret, snprintf(client->refbuf->data + ret, PER_CLIENT_REFBUF_SIZE - ret,
"Content-Length: 0\r\nUpgrade: TLS/1.0, HTTP/1.0\r\nConnection: Upgrade\r\n\r\n"); "Content-Length: 0\r\nUpgrade: TLS/1.0, HTTP/1.0\r\n\r\n");
client->respcode = 101; client->respcode = 101;
client->refbuf->len = strlen(client->refbuf->data); client->refbuf->len = strlen(client->refbuf->data);
client->reuse = reuse;
fserve_add_client(client, NULL); fserve_add_client(client, NULL);
} }
...@@ -281,13 +281,15 @@ void client_send_426(client_t *client, reuse_t reuse) ...@@ -281,13 +281,15 @@ void client_send_426(client_t *client, reuse_t reuse)
return; return;
} }
client->reuse = reuse;
ret = util_http_build_header(client->refbuf->data, PER_CLIENT_REFBUF_SIZE, 0, ret = util_http_build_header(client->refbuf->data, PER_CLIENT_REFBUF_SIZE, 0,
0, 426, NULL, 0, 426, NULL,
"text/plain", "utf-8", "text/plain", "utf-8",
NULL, NULL, client); NULL, NULL, client);
snprintf(client->refbuf->data + ret, PER_CLIENT_REFBUF_SIZE - ret, snprintf(client->refbuf->data + ret, PER_CLIENT_REFBUF_SIZE - ret,
"Content-Length: 0\r\nUpgrade: TLS/1.0, HTTP/1.0\r\nConnection: Upgrade\r\n\r\n"); "Content-Length: 0\r\nUpgrade: TLS/1.0, HTTP/1.0\r\n\r\n");
client->respcode = 426; client->respcode = 426;
client->refbuf->len = strlen(client->refbuf->data); client->refbuf->len = strlen(client->refbuf->data);
......
...@@ -632,10 +632,19 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset, ...@@ -632,10 +632,19 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset,
char contenttype_buffer[80]; char contenttype_buffer[80];
ssize_t ret; ssize_t ret;
char * extra_headers; char * extra_headers;
const char *connection_header = "Close";
if (!out) if (!out)
return -1; return -1;
if (client) {
switch (client->reuse) {
case ICECAST_REUSE_CLOSE: connection_header = "Close"; break;
case ICECAST_REUSE_KEEPALIVE: connection_header = "Keep-Alive"; break;
case ICECAST_REUSE_UPGRADETLS: connection_header = "Upgrade"; break;
}
}
if (offset == -1) if (offset == -1)
offset = strlen (out); offset = strlen (out);
...@@ -698,9 +707,10 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset, ...@@ -698,9 +707,10 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset,
config = config_get_config(); config = config_get_config();
extra_headers = _build_headers(status, config, source); extra_headers = _build_headers(status, config, source);
ret = snprintf (out, len, "%sServer: %s\r\nAccept-Encoding: identity\r\nAllow: %s\r\n%s%s%s%s%s%s%s", ret = snprintf (out, len, "%sServer: %s\r\nConnection: %s\r\nAccept-Encoding: identity\r\nAllow: %s\r\n%s%s%s%s%s%s%s",
status_buffer, status_buffer,
config->server_id, config->server_id,
connection_header,
(client->admin_command == ADMIN_COMMAND_ERROR ? (client->admin_command == ADMIN_COMMAND_ERROR ?
"GET, SOURCE" : "GET"), "GET, SOURCE" : "GET"),
currenttime_buffer, currenttime_buffer,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment