[英]How can I make hls.js send the cookie in request header upon requesting encryption key
I tried 我试过了
var config = {
xhrSetup: function (xhr) {
xhr.withCredentials = true; // do send cookies
}
};
but this doesn't work. 但这不起作用。 The Cookie is sent on playlist request and on segment request no matter if I enable credentials in the xhrSetup or not... but not on key request.
无论我是否在xhrSetup中启用凭据而不是在密钥请求上启用凭据,都会根据播放列表请求和段请求发送Cookie。 For securing the content I need to identify the user before handing out the key.
为了保护内容,我需要在分发密钥之前识别用户。 It's possible to set an "X-Cookie" as i wrote in the answer, but how would I send the session cookie?
我可以在答案中设置“X-Cookie”,但是如何发送会话cookie?
I set an "X-Cookie" like this: 我像这样设置了一个“X-Cookie”:
var config = {
debug: true,
xhrSetup: function (xhr,url) {
xhr.withCredentials = true; // do send cookie
xhr.setRequestHeader("X-Cookie", read_cookie('SESSIONID'));
}
};
on the other side it needs 在另一方面它需要
Header set Access-Control-Allow-Headers "X-Cookie"
the read_cookie function: read_cookie函数:
function read_cookie(key) {
var result;
(result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? (result[1]) : null;
console.log('result : ' + result[1]);
return result[1]
}
is there a way to send a Cookie value though? 有没有办法发送Cookie值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.