Skip to content

Commit

Permalink
fix(HLS): Provide a fallback to GET request when HEAD request fails (#…
Browse files Browse the repository at this point in the history
…5964)

Fixes #5959
  • Loading branch information
avelad committed Dec 1, 2023
1 parent 4eba182 commit fb5a833
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/hls/hls_parser.js
Expand Up @@ -3753,14 +3753,26 @@ shaka.hls.HlsParser = class {

// If unable to guess mime type, request a segment and try getting it
// from the response.
let contentMimeType;
const type = shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT;
const headRequest = shaka.net.NetworkingEngine.makeRequest(
middleSegmentUris, this.config_.retryParameters);
headRequest.method = 'HEAD';
const type = shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT;
const response = await this.makeNetworkRequest_(
headRequest, requestType, {type});
try {
headRequest.method = 'HEAD';
const response = await this.makeNetworkRequest_(
headRequest, requestType, {type});

contentMimeType = response.headers['content-type'];
} catch (error) {
if (error && error.code == shaka.util.Error.Code.HTTP_ERROR) {
headRequest.method = 'GET';
const response = await this.makeNetworkRequest_(
headRequest, requestType, {type});

contentMimeType = response.headers['content-type'];
}
}

const contentMimeType = response.headers['content-type'];
if (contentMimeType) {
// Split the MIME type in case the server sent additional parameters.
return contentMimeType.split(';')[0];
Expand Down

0 comments on commit fb5a833

Please sign in to comment.