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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 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,25 @@ 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;

// https://bit.ly/2K9s9kf says this header should always be available,
// but just to be safe:
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;

// https://bit.ly/2K9s9kf says this header should always be available,
// but just to be safe:
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
Loading