1

I am very interested to learn the HTTP protocol in depth as well as understand the working of NodeJS streams up-close. I figured out that the best way to do this would be to develop an HTTP server in Node.

My question is, as the HTTP protocol itself is based on TCP, would it be possible to use the Node's net module and consider TCP protocol fully implemented and ready at disposal, and then use it to write an HTTP server that aims at becoming something like Node's http module? How should I go about it?

Some guidelines would be greatly appreciated. PS. I have the RFC2616 printed and ready for reference :)

2

Yes, it is entirely possible. All you need at the core is the ability to have TCP server accepting inbound TCP connections in order to then implement your own HTTP server on top of that. The Net module in nodejs can certainly provide the core TCP server.

At first glance at the http server code in the http module of nodejs, it is itself written in Javascript on top of the Net module so you can go look at any of that code if you want (it's all available on Github in the previous link). I didn't do an exhaustive search to see if it might be including any native code modules (perhaps for performance reasons), but such would not be required in order to implement the HTTP protocol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.