我开始使用我的第一个javascript GTK应用程序,我想下载一个文件并使用Gtk.ProgressBar跟踪它的进度.我能找到的关于http请求的唯一文档是这里的一些示例代码:
http://developer.gnome.org/gnome-devel-demos/unstable/weatherGeonames.js.html.en
这里有一些令人困惑的汤参考:
http://www.roojs.org/seed/gir-1.2-gtk-3.0/gjs/Soup.SessionAsync.html
从我可以收集到的,我可以做这样的事情:
const Soup = imports.gi.Soup;
var _httpSession = new Soup.SessionAsync();
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault());
var request = Soup.Message.new('GET', url);
_httpSession.queue_message(request, function(_httpSession, message) {
print('download is done');
}
Run Code Online (Sandbox Code Playgroud)
下载完成时似乎只有一个回调,我找不到任何方法为任何数据事件设置回调函数.我怎样才能做到这一点?
这在node.js中非常简单:
var req = http.request(url, function(res){
console.log('download starting');
res.on('data', function(chunk) {
console.log('got a chunk of '+chunk.length+' bytes');
});
});
req.end();
Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,其中几个路径只能从localhost访问.看起来这可以通过新的路由系统实现.
http://www.railsdispatch.com/posts/rails-3-makes-life-better
这有一些基于IP地址限制路由,并为您的路由设置IP地址黑名单的示例,但我对只有一个IP地址的白名单感兴趣.
如果像这样的东西工作会很酷:
get "/posts" => "posts#show", :constraints => {:ip => '127.0.0.1'}
Run Code Online (Sandbox Code Playgroud)
但事实并非如此.我只是错过了正确的语法吗?