Merge 1c749fbed7
into 3b58ebc5f3
This commit is contained in:
commit
4e71c547b2
|
@ -2787,8 +2787,12 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
|
||||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||||
time_t now = switch_epoch_time_now(NULL);
|
time_t now = switch_epoch_time_now(NULL);
|
||||||
char *metadata;
|
char *metadata;
|
||||||
|
const char *cache_file_temp;
|
||||||
const char *ext = NULL;
|
const char *ext = NULL;
|
||||||
const char *err_msg = NULL;
|
const char *err_msg = NULL;
|
||||||
|
const char *ct = NULL;
|
||||||
|
const char *newext = NULL;
|
||||||
|
|
||||||
|
|
||||||
load_cache_data(context, url);
|
load_cache_data(context, url);
|
||||||
|
|
||||||
|
@ -2805,9 +2809,6 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context->url_params || !switch_true(switch_event_get_header(context->url_params, "nohead"))) {
|
if (!context->url_params || !switch_true(switch_event_get_header(context->url_params, "nohead"))) {
|
||||||
const char *ct = NULL;
|
|
||||||
const char *newext = NULL;
|
|
||||||
|
|
||||||
if ((status = fetch_cache_data(context, url, &headers, NULL, NULL)) != SWITCH_STATUS_SUCCESS) {
|
if ((status = fetch_cache_data(context, url, &headers, NULL, NULL)) != SWITCH_STATUS_SUCCESS) {
|
||||||
if (status == SWITCH_STATUS_NOTFOUND) {
|
if (status == SWITCH_STATUS_NOTFOUND) {
|
||||||
unreachable = 2;
|
unreachable = 2;
|
||||||
|
@ -2819,13 +2820,17 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zstr(ext) && headers && (ct = switch_event_get_header(headers, "content-type"))) {
|
if (headers && (ct = switch_event_get_header(headers, "content-type"))) {
|
||||||
newext = switch_core_mime_type2ext(ct);
|
newext = switch_core_mime_type2ext(ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newext) {
|
if (newext && (zstr(ext) || strcmp(ext, newext) != 0)) {
|
||||||
|
/*
|
||||||
|
* HTTP Request has returned the file with a different extension
|
||||||
|
* Update the cache_file path
|
||||||
|
*/
|
||||||
ext = newext;
|
ext = newext;
|
||||||
context->cache_file = switch_core_sprintf(context->pool, "%s.%s", context->cache_file, newext);
|
context->cache_file = switch_core_sprintf(context->pool, "%s.%s", context->cache_file_base, newext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2854,10 +2859,30 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((status = fetch_cache_data(context, url, &headers, context->cache_file, &err_msg)) != SWITCH_STATUS_SUCCESS) {
|
/*
|
||||||
|
* Save to a temp file first, then rename
|
||||||
|
* Just in case the extension changes
|
||||||
|
*/
|
||||||
|
cache_file_temp = switch_core_sprintf(context->pool, "%s.tmp", context->cache_file_base);
|
||||||
|
if ((status = fetch_cache_data(context, url, &headers, cache_file_temp, &err_msg)) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error fetching file at URL \"%s\" (%s)\n", url, err_msg ? err_msg : "");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error fetching file at URL \"%s\" (%s)\n", url, err_msg ? err_msg : "");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (headers && (ct = switch_event_get_header(headers, "content-type"))) {
|
||||||
|
newext = switch_core_mime_type2ext(ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newext && (zstr(ext) || strcmp(ext, newext) != 0)) {
|
||||||
|
/*
|
||||||
|
* HTTP Request has returned the file with a different extension
|
||||||
|
* Update the cache_file path for when the rename happens
|
||||||
|
*/
|
||||||
|
ext = newext;
|
||||||
|
context->cache_file = switch_core_sprintf(context->pool, "%s.%s", context->cache_file_base, newext);
|
||||||
|
}
|
||||||
|
|
||||||
|
rename(cache_file_temp, context->cache_file);
|
||||||
|
|
||||||
|
|
||||||
metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s",
|
metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s",
|
||||||
|
|
Loading…
Reference in New Issue