[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.
This commit is contained in:
Joshua Gigg 2020-08-27 13:27:40 +01:00 committed by GitHub
parent 850b10a864
commit 1b70a706ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -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);
}