This is a HTTP1.1 server listening on the given port , it keeps the conection in single way , any incoming request leads to TCP connecion establishment .
How it funcions:- When request is sent, it responses back with few data and metadata via the client (browser/curl) , now on making multiple request it do not establish new TCP connection ,rather it reuses the same TCP for transmission. Now the problem is when one of the request is slow and few are faster then they have to wait for the response of slower one , which creates head-on blocking.
This is the drawback of using HTTP 1.1 ,
In order to run this code , follow the steps below :-
Termianl[1] - node src/server.json Terminal[2] - you can use : curl -v http://127.0.0.1:8080 or browser to send the requests.
or
Termianl[2] - use : nc 127.0.0.1 8080 (to manually write http headers )
Terminal
│
│ TCP connection
▼
Node.js server
127.0.0.1:8080
Optional:
Terminal[3] - ss -tnp | grep 8080
(watch the socket)
You should see the connection:
ESTAB
127.0.0.1:<random-port>
127.0.0.1:8080
Watch the actual TCP packets : - Terminal[4] - sudo tcpdump -i lo -nn -A 'tcp port 8080'
OS : LINUX
So the very next thing to build is an HTTP/1.1 server that deliberately demonstrates keep-alive and request ordering, then we'll upgrade that exact server to HTTP/2.
THIS MODULE CONSIST OF ALL THREE CONCEPT OF http1 , http2 and http3 , You can see the folder structure in src/ .