从Firefox扩展中设置HTTP标头 [英] Setting HTTP headers from a Firefox extension

查看:177
本文介绍了从Firefox扩展中设置HTTP标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能在我的Firefox扩展中设置HTTP标头?

How can I set HTTP headers in my Firefox extension?

我将这样做,所以这些只是当我点击我的网站发送,所以我可以检测是否插件如果是这样的话,就不要推广这个插件了。

I'll make it so these are only sent while hitting my site so I can detect if the plugin is installed or not and not promote the plugin if it is.

推荐答案

这是我找到的最紧凑的方法:

Here's the most compact way I found to make this work:

Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService ).addObserver({
    observe : function(subject, topic, data) {
            var channel = subject.QueryInterface( Components.interfaces.nsIHttpChannel );
            if ( /mysite/.test( channel.originalURI.host ) ) {
                channel.setRequestHeader("x-mysite-extended", "true", false);
            }
    }
},"http-on-modify-request",false);

这篇关于从Firefox扩展中设置HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆