简体   繁体   中英

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.

Does node do something special to turn the incoming request and outgoing response into a NodeJS Stream? 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? 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?

Basically I don't know much about 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.

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 is asynchronous in nature and hence it wouldn't wait for the transfer to be finished. Hence callback functions are used to execute what you want after the request is complete.

Is there anything specific you are trying to do?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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