hls.js icon indicating copy to clipboard operation
hls.js copied to clipboard

Fix for #1021 breaks hls.js if the custom xhrSetup callback sets headers on the xhr request.

Open thedomi opened this issue 9 years ago • 1 comments

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
  1. Please provide clear steps to reproduce your problem:

Start hls.js with the following config options:

xhrSetup: (xhr, url) => {
  xhr.setRequestHeader("Content-Language", "test");
}
  1. 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

thedomi avatar Mar 30 '17 15:03 thedomi

Looks resolved

johnBartos avatar Apr 20 '17 19:04 johnBartos