From 1af93e63ffa6d1e585524e66d05072579a3cd299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Tue, 5 Dec 2023 08:19:25 +0100 Subject: [PATCH] fix: Provide a fallback to GET request when HEAD request fails (#5986) Fixes https://github.com/shaka-project/shaka-player/issues/5959 --- lib/net/networking_utils.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/net/networking_utils.js b/lib/net/networking_utils.js index 0481b025cd..f76b2ad630 100644 --- a/lib/net/networking_utils.js +++ b/lib/net/networking_utils.js @@ -8,6 +8,7 @@ goog.provide('shaka.net.NetworkingUtils'); goog.require('goog.Uri'); goog.require('shaka.net.NetworkingEngine'); +goog.require('shaka.util.Error'); /** @@ -30,13 +31,21 @@ shaka.net.NetworkingUtils = class { const type = shaka.net.NetworkingEngine.RequestType.MANIFEST; const request = shaka.net.NetworkingEngine.makeRequest([uri], retryParams); - request.method = 'HEAD'; - const response = await netEngine.request(type, request).promise; + try { + request.method = 'HEAD'; + const response = await netEngine.request(type, request).promise; + mimeType = response.headers['content-type']; + } catch (error) { + if (error && error.code == shaka.util.Error.Code.HTTP_ERROR) { + request.method = 'GET'; + const response = await netEngine.request(type, request).promise; + mimeType = response.headers['content-type']; + } + } // https://bit.ly/2K9s9kf says this header should always be available, // but just to be safe: - mimeType = response.headers['content-type']; return mimeType ? mimeType.toLowerCase().split(';').shift() : ''; }