- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在将 Node.js http 流发送到解析器之前对其进行编辑。我已经实现了以下代码
//catch any connection event to this server
server.on('secureConnection', function (stream) {
//create a new buffer to hold what we are receiving in this stream
var receiveBuffer = new Buffer(0);
//store a link to the original ondata function so we can call it and restore it
originalOnDataFunction = stream.ondata;
//declare a new ondata function for this stream
stream.ondata = function (d, start, end) {
//record what we have received
receiveBuffer = Buffer.concat([receiveBuffer, d.slice(start, end)]);
//if what we have received is greater than 4 (i.e. we have at least got a GET request)
//then make changes
if (receiveBuffer.length >= 4) {
//reset the streams ondata function to the original
//this is all we want to edit for this connection
stream.ondata = originalOnDataFunction;
//if the first 11 characters of the buffer are 'MKCALENDAR ' then make a change
if (receiveBuffer.toString('ascii', 0, 11) === 'MKCALENDAR ') {
//I change this to MKCOL /MKCALENDAR<rest of buffer> as this will work with the node.js http parser
//and then I can check on the other side for a MKCOL method with /MKCALENDAR as the start of the url and
//know that it was a MKCALENDAR method
var rewrittenBuffer = Buffer.concat([new Buffer('MKCOL /MKCALENDAR', 'ascii'), receiveBuffer.slice(11)]);
//now call the original ondata function with this new buffer
stream.ondata.apply(this, [rewrittenBuffer, 0, rewrittenBuffer.length]);
} else {
//no change needed just call the original ondata function with this buffer
stream.ondata.apply(this, [receiveBuffer, 0, receiveBuffer.length]);
}
}
}
});
这是我从这里的答案中得到的Overriding Node.js HTTP parser
上面的代码似乎在 95% 的情况下都能工作。然而,它不断丢弃请求,然后超时。我看不到它们是如何或在哪里掉落的。谁能帮忙。
谢谢
标记
请注意,secureConnection 来自node.js https.createServer( 调用
最佳答案
你确定要
if (receiveBuffer.length >= 4)
如果第一个缓冲区是至少具有前四个字节的部分 MKCALENDAR,则上面的代码将不会转换为 MKCOL。
关于node.js - 在 ondata 事件中更改 node.js 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15969748/
我有一个 Gridview,其适配器基于我的 MineSweeper 游戏的 Tile 类型的 pojo 列表,我正在做一些单元测试,我想做的就是单击所有没有地雷的 gridview 项目,然后长按所
我有一个 Activity 与 ListView (id: android.R.id.list)。 ListView 显示来自自定义适配器的信息,我想使用 Espresso 单击特定项目中的特定 Vi
我现在有点不知所措。我有一些代码可以在数据可用时从套接字读取数据,但目前它在一个单独的线程上的 while 循环中,并且由于没有可用数据而在函数返回时消耗 50% 的 CPU。我真正想要的是 Sock
我正在尝试验证 ListView 不包含特定项目。这是我正在使用的代码: onData(allOf(is(instanceOf(Contact.class)), is(withContactItemN
我制作了一个简单的 NodeJS TCP 服务器,Java 客户端发送图像: encodedImage = out.write("IMG;" + encodedImage); out.flush()
我正在尝试访问一个 View 的 subview 。这是我目前正在尝试开始工作的路线。 onData(withDesc("Description")).onChildView(withId(R.id.
在nodejs应用程序中,我需要生成一个子进程,并将stdio设置为“继承”模式,所以基本上: var child = spawn('some/command', [], { stdio: [pr
我一直在开发一种使用 WebRTC 在浏览器和 native 客户端之间交换音频的产品, native 端是用 C++ 实现的。目前我已经构建了 webRtc 的最新稳定版本(分支:branch-he
在使用 Facebook graph api 时,我使用 https.get 来请求 facebook 用户数据。 var optionsP = { host: 'graph.face
我在使用 http.request 发出客户端请求时遇到了一些错误( Node v0.6.18,v0.6.3),以下代码产生了错误,我有一些疑问。 var http = require('http')
我正在尝试在将 Node.js http 流发送到解析器之前对其进行编辑。我已经实现了以下代码 //catch any connection event to this server server.o
我有一个命令行 Dart 脚本客户端通过 [dart:io] websocket 与 Jetty 服务器进行交互。我已经实现了一个自定义消息子协议(protocol),它使用反射(双方)使用二进制编码
我有一个app,有ListView,我想找LinearLayout,id=order_untake_jijia_listview_jia 代码是: onData(withClassName(endsW
我是一名优秀的程序员,十分优秀!