hls.js
hls.js copied to clipboard
Fix for #1021 breaks hls.js if the custom xhrSetup callback sets headers on the xhr request.
Environment
- [x] The stream has correct Access-Control-Allow-Origin headers (CORS)
- [x] There are no network errors such as 404s in the browser console when trying to play the stream
- [x] The issue observed is not already reported by searching on Github under https://github.com/video-dev/hls.js/issues
- [ ] The issue occurs in the latest reference client on http://video-dev.github.io/hls.js/demo and not just on my page
- Hls.js version: v0.7.4+
The fix for issue #1021 in v0.7.4 changed XhrLoader#loadInternal() (see https://github.com/video-dev/hls.js/blob/v0.7.4/src/utils/xhr-loader.js#L42-L70), breaking hls.js if the xhrSetup config option is set and the callback is setting a request header.
According to https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader, setRequestHeader() must be called after open() but before send().
Steps to reproduce
- Please provide clear steps to reproduce your problem:
Start hls.js with the following config options:
xhrSetup: (xhr, url) => {
xhr.setRequestHeader("Content-Language", "test");
}
- Example which reproduces the problem you are having with the least amount of code possible: index.txt. This example uses a custom loader (which is a copy of the v0.7.4 XhrLoader) because the v0.7.4 release build uses the 0.7.3 version of XhrLoader.
Expected behavior
The "Content-Language" header to be set with the "test" value.
Actual behavior
Playback does not start, and hls.js logs an error.
Console output
[log] > loadSource:http://www.streambox.fr/playlists/test_001/stream.m3u8
logger.js:39[error] > internal error happened while processing hlsManifestLoading:Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.
(anonymous) @ logger.js:39
onEventGeneric @ event-handler.js:67
onEvent @ event-handler.js:53
EventEmitter.emit @ events.js:96
trigger @ hls.js:82
loadSource @ hls.js:165
init @ (index):177
logger.js:39[log] > trigger BUFFER_RESET
logger.js:39[log] > attachMedia
logger.js:39[log] > media source opened
Looks resolved