小编xfx*_*xfx的帖子

在http-on-examine-response之前返回响应

我正在开发一个Firefox插件,它需要拦截HTTP请求进程并返回某些URL的虚假响应.这是我正在使用的代码:

function TracingListener() {
    this.originalListener = null;
}

TracingListener.prototype = {
    onDataAvailable: function(request, context, inputStream, offset, count) {
        LOG("onDataAvailable");
        this.originalListener.onDataAvailable(request, context, inputStream, offset, count);
    },

    onStartRequest: function(request, context) {
        LOG("onStartRequest");
        this.originalListener.onStartRequest(request, context);
    },


    onStopRequest: function(request, context, statusCode) {
        LOG("onStopRequest");
        this.originalListener.onStopRequest(request, context, statusCode);
        var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
        stream.setData("Test", -1);
        this.originalListener.onStopRequest(request, context, Components.results.NS_OK);

    },

    QueryInterface: function (aIID) {
        if (aIID.equals(Ci.nsIStreamListener) ||
        aIID.equals(Ci.nsISupports)) {
            return this;
        }
        throw Components.results.NS_NOINTERFACE;
    }
};

var observer = {
    observe: function(subject, topic, data) {
        LOG(topic);
        var httpChannel …
Run Code Online (Sandbox Code Playgroud)

javascript xpcom firefox-addon

8
推荐指数
1
解决办法
1163
查看次数

cron git push 与 ssh 密钥

我为github账号设置了ssh key,所以不用每次都输入密码,效果很好。这是我使用的脚本:

#!/bin/bash
git push origin master
Run Code Online (Sandbox Code Playgroud)

但是当我使用 cron 运行它时,它不会使用我的 ssh 密钥。这是输出:

Permission denied (publickey)
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)

我四处搜索并找到了一些文章,但没有一篇能解决我的问题。以下是我找到的文章(以及更多):

https://askubuntu.com/questions/110565/why-is-git-not-using-my-pubkey-with-crontab

https://unix.stackexchange.com/questions/35466/how-to-perform-git-push-using-crontab

通过 cron git push

任何人都可以给我一步一步的说明来解决这个问题吗?

git ssh cron

7
推荐指数
2
解决办法
7502
查看次数

Swift中的self class alloc

我有一个用Objective-C编写的Model类,它假设是由子类继承的.有一种方法:

- (id)deepcopy {
    id newModel = [[[self class] alloc] init];
    newModel.id = self.id;
    // do something
    return newModel;
}
Run Code Online (Sandbox Code Playgroud)

子类应该用以下内容覆盖它:

- (id)deepcopy {
    id newModel = [super deepcopy];
    // something else
    return newModel;
}
Run Code Online (Sandbox Code Playgroud)

关键是[[[self class] alloc] init],它将基于实际的类来实例化一个对象.最近我尝试将这个项目升级到Swift,但是找不到在Swift中做同样事情的方法.

我怎样才能做到这一点?

objective-c ios swift

4
推荐指数
1
解决办法
3523
查看次数

标签 统计

cron ×1

firefox-addon ×1

git ×1

ios ×1

javascript ×1

objective-c ×1

ssh ×1

swift ×1

xpcom ×1