Setting Request header: Connection
When you make requests with "Connection: keep-alive" the subsequent request to the server will use the same TCP connection. This is called HTTP persistent connection. This helps in reducing CPU load on the server side and improves latency/response time.
If a request is made with "Connection: close" this indicates that once the request has been made the server needs to close the connection. And so for each request a new TCP connection will be established.
By default HTTP 1.1 client/server uses keep-alive whereas HTTP 1.0 client/server doesn't support keep-alive by default.
ajduke
Self-taught, full-stack developer, technology enthusiast, blogger. Working with #NodeJS #MeteorJS #MongoDB #Redis #React, #Redux #Webpack. Oracle certified Java programmer for Java SE 6 On StackOverflow , i am active on following tags, #meteor #nodejs #mongodb #nosql #javascript #git My Blog is at http://blog.ajduke.in profile for ajduke on Stack Exchange, a network of free, community-driven Q&A sites http://stackexchange.com/users/flair/228966.png
Updated on July 05, 2022Comments
-
ajduke almost 2 years
By default
Connection
Header is set toKeep-Alive
in browers, to make it possible to keep connection open for further requests from browser.When I make
Connection
header toclose
, what may be the difference ? Will that affect any performance issue ?(one addition: I am setting header from xmlhttprequest)
-
user772401 over 12 yearsThat's assuming it's possible to change it from within an xmlhttprequest.
-
ajduke over 12 yearsI need to along with this is that, is this create a request/response stream to server and keep this stream open forever for further communication with server or something else
-
ajduke over 12 years@bzlm yes i am changing it from xmlhttprequest
-
ajduke over 12 years@neworld so when one should set Connection to close ? can you give me some example .
-
neworld over 12 years@this-abhi: I think, you dont need close connection self. It's unnecessary. But I you totaly know you generate last request, you can close.
-
user772401 over 12 years@this-abhi, I don't think you're going to have much luck with this. You're supposed to let the browser and server negotiate the communication amongst themselves. Fiddling with the
Connection
header isn't probably even going to work. -
ajduke over 12 years@bzlm , neoworld okay , then i will be better off the hook of this
-
Adam Gu almost 6 yearsI think your answer about
Connection: close
in the request is wrong. According to HTTP/1.1 RFC,Connection: close
in either the request or the response header fields indicates that the connection SHOULD NOT be considered `persistent' after the current request/response is complete.