Remove Loader.loader and replace Loader.getResponseHeader() with Laoder.getCacheAge() #3707
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR removes
Loader.loader
replacesLoader.getResponseHeader()
withLoader.getCacheAge()
.Why is this Pull Request needed?
This is two small changes in one PR, but they're both related to the Loader API.
Loader.loader
First: The
Loader
interface has a property namedloader
of typeany
. This property is not read by any hls.js code. The two implementations of loader (xhr-loader and fetch-loader) set this to an XMLHttpRequest and a fetch Response, respectively.I'm writing a loader that loads data from a local cache - I don't even have an HTTP request involved in my loader, so I have nothing to put here. But, since no one reads from it anyways, easiest just to remove it, and then I don't have to set it to
undefined
. The existingMockXhr
loader is an example of a loader, used in fragment loading tests, is another example of a loader that never defines this.I'm not sure why this property was here in the first place - was it maybe intended to make it so third parties could read from the response when they instantiate a loader? We could leave it
public
in fetch-loader and xhr-loader I suppose, but again I'm not sure what it's for.Loader.getResponseHeader()
The second change: Loader has a function called
getResponseHeader()
(again, added in 1.0.0), which returns the value of a response header. It's used to find the "age" header to see if a request has been in a proxy for a while, when playing live.But, this API is way too broad - first it assumes the underlying transport is HTTP based. If the underlying transport is something else, like WebRTC or websocket, what should
getResponseHeader()
return? Or what if (as in my above case) you're caching playlists locally? You could argue it should just return undefined for WebRTC and websocket, and maybe in my local cache case I should construct an "age" based on how long I've cached it, but making such an argument implies thatgetResponseHeader()
will only ever be used to fetch the "age" header. But there's nothing about this API which restricts hls.js from calling it and asking for other headers.So, as an implementer, you're left trying to work out what possible HTTP headers hls.js might want in this or future versions, and trying to reconstruct them from whatever data you have available to you from your transport. I replaced this with
getCacheAge()
, which is a much nicer API to try to implement as someone writing a non-HTTP loader.Are there any points in the code the reviewer needs to double check?
No.
Resolves issues:
None.
Checklist