From 1b70a706ff7744eb23f167fa3114e83f5c54c426 Mon Sep 17 00:00:00 2001 From: Joshua Gigg Date: Thu, 27 Aug 2020 13:27:40 +0100 Subject: [PATCH] [mod_httapi] Update cache file if the extension changes If a HTTP request changes the extension (by using Content-Type header) of the existing cached file, remove the existing cached file, and allow the new one to save with the correct extension. --- src/mod/applications/mod_httapi/mod_httapi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_httapi/mod_httapi.c b/src/mod/applications/mod_httapi/mod_httapi.c index abc9bb37d2..985d85aca9 100644 --- a/src/mod/applications/mod_httapi/mod_httapi.c +++ b/src/mod/applications/mod_httapi/mod_httapi.c @@ -2813,13 +2813,18 @@ 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); } - 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 and delete the original file + */ ext = newext; - context->cache_file = switch_core_sprintf(context->pool, "%s.%s", context->cache_file, newext); + unlink(context->cache_file); + context->cache_file = switch_core_sprintf(context->pool, "%s.%s", context->cache_file_base, newext); }