简体   繁体   English

NodeJS - 默认情况下,http请求和响应是否在NodeJS世界之外?

[英]NodeJS - Are http requests and response by default streams outside the NodeJS world?

I've been learning about Streams in NodeJS and specifically interested in the 'request' and 'response' stream that are provided as arguments from the NodeJS HTTP Server. 我一直在学习NodeJS中的Streams,特别感兴趣的是从NodeJS HTTP Server作为参数提供的'request'和'response'流。

Does node do something special to turn the incoming request and outgoing response into a NodeJS Stream? 节点是否会执行一些特殊操作来将传入请求和传出响应转换为NodeJS流? For example in a readable request stream, is Node like changing the way data is sent from the client to the HTTP Web Server to be able to expose the request to me as a NodeJS Stream where I can read data chunk by chunk using the 'readable' event? 例如,在可读请求流中,节点就像改变数据从客户端发送到HTTP Web服务器的方式,以便能够将请求作为NodeJS流暴露给我,在那里我可以使用“可读”来读取数据块。 '事件? Or are all http requests across the world by default streams of chunked data, and other web frameworks historically just did a really poor job of exposing me to the stream of data, and buffered it automatically so I would be presented with a full request object by default... often times blocking while the framework in the background waited for each chunk of the stream to come in without me knowing about it? 或者是默认的分块数据流在世界范围内的所有http请求,而其他网络框架在历史上只是做了很差的工作,让我暴露于数据流,并自动缓存它,所以我将通过以下方式呈现完整的请求对象默认...经常阻塞,而后台的框架在没有我知道的情况下等待流的每个块进来?

Basically I don't know much about HTTP. 基本上我对HTTP知之甚少。 I saw this article regarding chunked transfer encoding https://en.wikipedia.org/wiki/Chunked_transfer_encoding , but its still not clear to me whether that is what NodeJS takes advantage of. 我看到这篇关于分块传输编码的文章https://en.wikipedia.org/wiki/Chunked_transfer_encoding ,但我仍然不清楚这是否是NodeJS利用的。

Any explanations or pointing me in the direction to some tutorials would be much appreciated. 任何解释或指向我的一些教程的方向将非常感激。

Yes, NodeJS takes advantage of HTTP/1.1 Chunked transfer encoding mechanism for sending generally large files like media. 是的,NodeJS利用HTTP / 1.1 Chunked传输编码机制来发送一般大型文件,如媒体。

NodeJS is asynchronous in nature and hence it wouldn't wait for the transfer to be finished. NodeJS本质上是异步的,因此它不会等待传输完成。 Hence callback functions are used to execute what you want after the request is complete. 因此,回调函数用于在请求完成后执行您想要的操作。

Is there anything specific you are trying to do? 你有什么具体的想法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM