2016-04-27 31 views
3

我试图我怎样才能让hls.js在请求头中发送cookie在请求加密密钥

var config = { 
     xhrSetup: function (xhr) { 
      xhr.withCredentials = true; // do send cookies 
     } 
    }; 

但这不起作用。 无论我是否在xhrSetup中启用证书或不在密钥请求中,Cookie都会在播放列表请求和段请求上发送。 为了确保内容的安全,我需要在发放密钥之前识别用户。 可以设置一个“X-Cookie”,就像我在答案中写的一样,但是我将如何发送会话cookie?

回答

2

我设置一个 “X-曲奇” 是这样的:

var config = { 
     debug: true, 
     xhrSetup: function (xhr,url) { 
      xhr.withCredentials = true; // do send cookie 
      xhr.setRequestHeader("X-Cookie", read_cookie('SESSIONID')); 
     } 
    }; 

在另一边,它需要

Header set Access-Control-Allow-Headers "X-Cookie" 

的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] 
} 

是有办法发送Cookie值?

+0

在“read_cookie(key)”函数中只返回这个: return key +'='+ result [1] – Matt

相关问题