<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16215">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_http_media_cache: Cleanup audio format lookup in HTTP requests<br><br>Asterisk first looks at the end of the URL to determine the file<br>extension of the returned audio, which in many cases will not work<br>because the URL may end with a query string or a URL fragment. If that<br>fails, Asterisk then looks at the Content-Type header and then finally<br>parses the URL to get the extension.<br><br>The order has been changed such that we look at the Content-Type<br>header first, followed by looking for the extension of the parsed<br>URL. We no longer look at the end of the URL, which was error prone.<br><br>ASTERISK-29527 #close<br><br>Change-Id: I1e3f83b339ef2b80661704717c23568536511032<br>---<br>A doc/UPGRADE-staging/http-media-cache-lookup-order.txt<br>M res/res_http_media_cache.c<br>2 files changed, 13 insertions(+), 14 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/15/16215/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/UPGRADE-staging/http-media-cache-lookup-order.txt b/doc/UPGRADE-staging/http-media-cache-lookup-order.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..83c31dc</span><br><span>--- /dev/null</span><br><span>+++ b/doc/UPGRADE-staging/http-media-cache-lookup-order.txt</span><br><span>@@ -0,0 +1,9 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_http_media_cache</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+When fetching a file for playback from a URL, Asterisk will now first</span><br><span style="color: hsl(120, 100%, 40%);">+use the value of the Content-Type header in the HTTP response to</span><br><span style="color: hsl(120, 100%, 40%);">+determine the format of the audio data, and only if it is unable to do</span><br><span style="color: hsl(120, 100%, 40%);">+that will it attempt to parse the URL and extract the extension from</span><br><span style="color: hsl(120, 100%, 40%);">+the path portion. Previously Asterisk would first look at the end of</span><br><span style="color: hsl(120, 100%, 40%);">+the URL, which may have included query string parameters or a URL</span><br><span style="color: hsl(120, 100%, 40%);">+fragment, which was error prone.</span><br><span>diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c</span><br><span>index 5410566..9f560c7 100644</span><br><span>--- a/res/res_http_media_cache.c</span><br><span>+++ b/res/res_http_media_cache.c</span><br><span>@@ -171,11 +171,6 @@</span><br><span>  return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static char *file_extension_from_url(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-  return file_extension_from_string(ast_sorcery_object_get_id(bucket_file), buffer, capacity);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /*!</span><br><span>  * \internal</span><br><span>  * \brief Normalize the value of a Content-Type header</span><br><span>@@ -249,18 +244,13 @@</span><br><span> </span><br><span> static void bucket_file_set_extension(struct ast_bucket_file *bucket_file)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-   /* We will attempt to determine an extension in the following order for backwards</span><br><span style="color: hsl(0, 100%, 40%);">-        * compatibility:</span><br><span style="color: hsl(0, 100%, 40%);">-        *</span><br><span style="color: hsl(0, 100%, 40%);">-       * 1. Look at tail end of URL for extension</span><br><span style="color: hsl(0, 100%, 40%);">-      * 2. Use the Content-Type header if present</span><br><span style="color: hsl(0, 100%, 40%);">-     * 3. Parse the URL (assuming we can) and look at the tail of the path</span><br><span style="color: hsl(0, 100%, 40%);">-   */</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Using Content-Type first allows for the most flexibility for whomever</span><br><span style="color: hsl(120, 100%, 40%);">+       * is serving up the audio file. If that doesn't turn up anything useful</span><br><span style="color: hsl(120, 100%, 40%);">+   * we'll try to parse the URL and use the extension */</span><br><span> </span><br><span>       char buffer[64];</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    if (file_extension_from_url(bucket_file, buffer, sizeof(buffer))</span><br><span style="color: hsl(0, 100%, 40%);">-           || file_extension_from_content_type(bucket_file, buffer, sizeof(buffer))</span><br><span style="color: hsl(120, 100%, 40%);">+   if (file_extension_from_content_type(bucket_file, buffer, sizeof(buffer))</span><br><span>       || file_extension_from_url_path(bucket_file, buffer, sizeof(buffer))) {</span><br><span>           ast_bucket_file_metadata_set(bucket_file, "ext", buffer);</span><br><span>  }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16215">change 16215</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16215"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I1e3f83b339ef2b80661704717c23568536511032 </div>
<div style="display:none"> Gerrit-Change-Number: 16215 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>