Http 响应标头在火狐扩展中总是不会被修改

Http response header not getting modified in firefox extension always

本文关键字:修改 扩展 响应 火狐 Http      更新时间:2023-09-26

我正在修改Firefox的内联处置扩展。以下是实际修改标头的代码片段:

_httpResponse: function( chan )
{
    var disp = "";

    try {
        chan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
        disp = chan.getResponseHeader("Content-Disposition");
    } catch (e) { }
    if (chan.loadFlags & Components.interfaces.nsIChannel.LOAD_DOCUMENT_URI && this._re.test(disp))
    {
        chan.setResponseHeader("Content-Disposition", disp.replace(this._re, "inline"), false);
        chan.setResponseHeader("Content-Type", "application/fgdownload", false);  //not working
        }
}

我为修改内容类型而添加的行不起作用。但是,内容处置工作正常。

Content-Type

无法修改的响应标头之一。其他分别是Content-LenghtContent-EncodingTrailerTransfer-Encoding

但是,您可以更改 nsIHttpChannel 的继承contentType属性(存在一些限制)。