mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-11-03 04:17:17 -05:00
Feature: Added type="cors" to <header>.
This commit is contained in:
parent
ff0263b3a4
commit
ca83e6b44b
@ -518,6 +518,7 @@ static void config_clear_http_header(ice_config_http_header_t *header)
|
|||||||
|
|
||||||
while (header) {
|
while (header) {
|
||||||
xmlFree(header->name);
|
xmlFree(header->name);
|
||||||
|
if (header->value)
|
||||||
xmlFree(header->value);
|
xmlFree(header->value);
|
||||||
old = header;
|
old = header;
|
||||||
header = header->next;
|
header = header->next;
|
||||||
@ -1664,13 +1665,15 @@ static void _parse_http_headers(xmlDocPtr doc,
|
|||||||
continue;
|
continue;
|
||||||
if (!(name = (char *)xmlGetProp(node, XMLSTR("name"))))
|
if (!(name = (char *)xmlGetProp(node, XMLSTR("name"))))
|
||||||
break;
|
break;
|
||||||
if (!(value = (char *)xmlGetProp(node, XMLSTR("value"))))
|
|
||||||
break;
|
value = (char *)xmlGetProp(node, XMLSTR("value"));
|
||||||
|
|
||||||
type = HTTP_HEADER_TYPE_STATIC; /* default */
|
type = HTTP_HEADER_TYPE_STATIC; /* default */
|
||||||
if ((tmp = (char *)xmlGetProp(node, XMLSTR("type")))) {
|
if ((tmp = (char *)xmlGetProp(node, XMLSTR("type")))) {
|
||||||
if (strcmp(tmp, "static") == 0) {
|
if (strcmp(tmp, "static") == 0) {
|
||||||
type = HTTP_HEADER_TYPE_STATIC;
|
type = HTTP_HEADER_TYPE_STATIC;
|
||||||
|
} else if (strcmp(tmp, "cors") == 0 || strcmp(tmp, "corpse") == 0) {
|
||||||
|
type = HTTP_HEADER_TYPE_CORS;
|
||||||
} else {
|
} else {
|
||||||
ICECAST_LOG_WARN("Unknown type %s for "
|
ICECAST_LOG_WARN("Unknown type %s for "
|
||||||
"HTTP Header %s", tmp, name);
|
"HTTP Header %s", tmp, name);
|
||||||
|
@ -32,7 +32,9 @@
|
|||||||
|
|
||||||
typedef enum _http_header_type {
|
typedef enum _http_header_type {
|
||||||
/* static: headers are passed as is to the client. */
|
/* static: headers are passed as is to the client. */
|
||||||
HTTP_HEADER_TYPE_STATIC
|
HTTP_HEADER_TYPE_STATIC,
|
||||||
|
/* CORS: headers are only sent to the client if it's a CORS request. */
|
||||||
|
HTTP_HEADER_TYPE_CORS
|
||||||
} http_header_type;
|
} http_header_type;
|
||||||
|
|
||||||
typedef struct ice_config_http_header_tag {
|
typedef struct ice_config_http_header_tag {
|
||||||
|
26
src/util.c
26
src/util.c
@ -598,7 +598,7 @@ unsigned int util_str_to_unsigned_int(const char *str, const unsigned int defaul
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO, FIXME: handle memory allocation errors better. */
|
/* TODO, FIXME: handle memory allocation errors better. */
|
||||||
static inline void _build_headers_loop(char **ret, size_t *len, ice_config_http_header_t *header, int status) {
|
static inline void _build_headers_loop(char **ret, size_t *len, ice_config_http_header_t *header, int status, const char *allow, client_t *client) {
|
||||||
size_t headerlen;
|
size_t headerlen;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *value;
|
const char *value;
|
||||||
@ -621,6 +621,22 @@ static inline void _build_headers_loop(char **ret, size_t *len, ice_config_htt
|
|||||||
case HTTP_HEADER_TYPE_STATIC:
|
case HTTP_HEADER_TYPE_STATIC:
|
||||||
value = header->value;
|
value = header->value;
|
||||||
break;
|
break;
|
||||||
|
case HTTP_HEADER_TYPE_CORS:
|
||||||
|
if (name && client && client->parser) {
|
||||||
|
const char *origin = httpp_getvar(client->parser, "origin");
|
||||||
|
if (origin) {
|
||||||
|
value = header->value;
|
||||||
|
if (!value) {
|
||||||
|
ICECAST_LOG_ERROR("value='%s', name='%s', origin='%s', allow='%s'", value, name, origin, allow);
|
||||||
|
if (strcasecmp(name, "Access-Control-Allow-Origin") == 0) {
|
||||||
|
value = origin;
|
||||||
|
} else if (strcasecmp(name, "Access-Control-Allow-Methods") == 0) {
|
||||||
|
value = allow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check data */
|
/* check data */
|
||||||
@ -644,7 +660,7 @@ static inline void _build_headers_loop(char **ret, size_t *len, ice_config_htt
|
|||||||
} while ((header = header->next));
|
} while ((header = header->next));
|
||||||
*ret = r;
|
*ret = r;
|
||||||
}
|
}
|
||||||
static inline char * _build_headers(int status, ice_config_t *config, source_t *source) {
|
static inline char * _build_headers(int status, const char *allow, ice_config_t *config, source_t *source, client_t *client) {
|
||||||
mount_proxy *mountproxy = NULL;
|
mount_proxy *mountproxy = NULL;
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
size_t len = 1;
|
size_t len = 1;
|
||||||
@ -655,9 +671,9 @@ static inline char * _build_headers(int status, ice_config_t *config, source_t *
|
|||||||
ret = calloc(1, 1);
|
ret = calloc(1, 1);
|
||||||
*ret = 0;
|
*ret = 0;
|
||||||
|
|
||||||
_build_headers_loop(&ret, &len, config->http_headers, status);
|
_build_headers_loop(&ret, &len, config->http_headers, status, allow, client);
|
||||||
if (mountproxy && mountproxy->http_headers)
|
if (mountproxy && mountproxy->http_headers)
|
||||||
_build_headers_loop(&ret, &len, mountproxy->http_headers, status);
|
_build_headers_loop(&ret, &len, mountproxy->http_headers, status, allow, client);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -785,7 +801,7 @@ 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, allow_header, config, source, client);
|
||||||
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",
|
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,
|
status_buffer,
|
||||||
config->server_id,
|
config->server_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user