Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Provide a fallback to GET request when HEAD request fails #5986

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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() : '';
theodab marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down