Skip to content

Commit

Permalink
Safely read playlist response "age" header
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Walch committed Mar 26, 2021
1 parent c45c4ec commit b9c427c
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/loader/playlist-loader.ts
Expand Up @@ -70,8 +70,6 @@ class PlaylistLoader {
[key: string]: Loader<LoaderContext>;
} = Object.create(null);

private checkAgeHeader: boolean = true;

constructor(hls: Hls) {
this.hls = hls;
this.registerListeners();
Expand Down Expand Up @@ -148,7 +146,6 @@ class PlaylistLoader {
data: ManifestLoadingData
) {
const { url } = data;
this.checkAgeHeader = true;
this.load({
id: null,
groupId: null,
Expand Down Expand Up @@ -686,12 +683,9 @@ class PlaylistLoader {
return;
}

if (this.checkAgeHeader && levelDetails.live) {
if (levelDetails.live) {
const ageHeader = loader.getResponseHeader('age');
levelDetails.ageHeader = ageHeader ? parseFloat(ageHeader) : 0;
// Avoid repeated browser error log `Refused to get unsafe header "age"` when unnecessary or past attempts failed
// Add an "Access-Control-Expose-Headers: age" header to playlist responses to prevent this CORS error
this.checkAgeHeader = ageHeader !== null;
}

switch (type) {
Expand Down

0 comments on commit b9c427c

Please sign in to comment.