[英]How can I turn a Node.js http.IncomingMessage into a Fetch Request object?
[英]How can I manually create http.IncomingMessage stream?
我想手动创建 http.IncomingMessage stream 和一些 header 和正文。 由于它是可读的 stream,因此我无法将数据写入/管道。 延长它是否安全?
另外,当它是不在 ObjectMode 上运行的 stream 时,我不确定如何存储标头。
编辑:
根据Node.js 文档,扩展 http.IncomingMessage 是可能的。
IncomingMessage <http.IncomingMessage> 指定要使用的 IncomingMessage class。 对于扩展原始 IncomingMessage 很有用。 默认值:传入消息。
我该如何扩展它? 它的构造函数请求Socket
object。
我在测试中这样嘲笑它:
import { IncomingMessage } from "http";
import { Socket } from "net";
const msg = new IncomingMessage(new Socket());
msg.method = 'POST';
msg.url = "whateverurl"
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.