diff --git a/src/client.c b/src/client.c index b6bd149a..d2cfcb8d 100644 --- a/src/client.c +++ b/src/client.c @@ -43,6 +43,7 @@ #include "reportxml.h" #include "refobject.h" #include "xslt.h" +#include "source.h" #include "client.h" #include "auth.h" @@ -385,6 +386,7 @@ void client_send_101(client_t *client, reuse_t reuse) void client_send_204(client_t *client) { + source_t *source; ssize_t ret; if (!client) @@ -392,10 +394,16 @@ void client_send_204(client_t *client) client->reuse = ICECAST_REUSE_KEEPALIVE; + /* We get a source_t* here as this is likely a reply to OPTIONS and we want + * to have as much infos as possible in that case. + */ + avl_tree_rlock(global.source_tree); + source = source_find_mount_raw(client->uri); ret = util_http_build_header(client->refbuf->data, PER_CLIENT_REFBUF_SIZE, 0, 0, 204, NULL, NULL, NULL, - NULL, NULL, client); + NULL, source, client); + avl_tree_unlock(global.source_tree); snprintf(client->refbuf->data + ret, PER_CLIENT_REFBUF_SIZE - ret, "Content-Length: 0\r\n\r\n"); diff --git a/src/util.c b/src/util.c index f13b443e..be1b4458 100644 --- a/src/util.c +++ b/src/util.c @@ -680,6 +680,7 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset, char * extra_headers; const char *connection_header = "Close"; const char *upgrade_header = ""; + const char *allow_header; if (!out) return -1; @@ -771,14 +772,25 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset, else currenttime_buffer[0] = '\0'; + if (client) { + if (client->admin_command != ADMIN_COMMAND_ERROR) { + allow_header = "GET, POST, OPTIONS"; + } else if (source) { + allow_header = "GET, DELETE, OPTIONS"; + } else { + allow_header = "GET, PUT, OPTIONS, SOURCE"; + } + } else { + allow_header = "GET, OPTIONS"; + } + config = config_get_config(); extra_headers = _build_headers(status, config, source); 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%s", status_buffer, config->server_id, connection_header, - (client && client->admin_command == ADMIN_COMMAND_ERROR ? - "GET, SOURCE, OPTIONS" : "GET, OPTIONS"), + allow_header, upgrade_header, currenttime_buffer, contenttype_buffer,