Skip to content

Commit

Permalink
fix: Provide a fallback to GET request when HEAD request fails (#5986)
Browse files Browse the repository at this point in the history
Fixes #5959
  • Loading branch information
avelad authored Dec 5, 2023
1 parent 00c918f commit 1af93e6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/net/networking_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ goog.provide('shaka.net.NetworkingUtils');

goog.require('goog.Uri');
goog.require('shaka.net.NetworkingEngine');
goog.require('shaka.util.Error');


/**
Expand All @@ -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() : '';
}

Expand Down

0 comments on commit 1af93e6

Please sign in to comment.