ain menu Main menu move to sidebar hide Navigation Main page Contents Current events Random article About Wikipedia Contact us Contribute Help Learn to edit Community portal Recent changes Upload file Special pages Search Search Appearance Donate Create account Log in Personal tools Donate Create account Log in Contents move to sidebar hide (Top) 1 Operation Toggle Operation subsection 1.1 HTTP 1.0 1.2 HTTP 1.1 1.2.1 Keepalive with chunked transfer encoding 2 Advantages 3 Disadvantages 4 Use in web browsers 5 Implementation 6 See also 7 References 8 External links Toggle the table of contents HTTP persistent connection 10 languages فارسی Magyar 日本語 한국어 Português Русский Српски / srpski ไทย Українська 中文 Edit links Article Talk English Read Edit View history Tools Tools move to sidebar hide Actions Read Edit View history General What links here Related changes Upload file Permanent link Page information Cite this page Get shortened URL Switch to legacy parser Print/export Download as PDF Printable version In other projects Wikidata item Appearance move to sidebar hide From Wikipedia, the free encyclopedia Using a single TCP connection to send and receive multiple HTTP requests/responses HTTP Persistence Compression HTTPS QUIC Request methods OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT PATCH Header fields Cookie ETag Location HTTP referer DNT X-Forwarded-For Upgrade Response status codes 301 Moved Permanently 302 Found 303 See Other 403 Forbidden 404 Not Found 451 Unavailable for Legal Reasons Security access control methods Basic access authentication Digest access authentication Security vulnerabilities HTTP header injection HTTP request smuggling HTTP response splitting HTTP parameter pollution v t e HTTP persistent connection , also called HTTP keep-alive , or HTTP connection reuse , is the idea of using a single TCP connection to send and receive multiple HTTP requests /responses, as opposed to opening a new connection for every single request/response pair. The newer HTTP/2 protocol uses the same idea and takes it further to allow multiple concurrent requests/responses to be multiplexed over a single connection. Operation [ edit ] HTTP 1.0 [ edit ] Under HTTP 1.0, connections should always be closed by the server after sending the response. [ 1 ] Since at least late 1995, [ 2 ] developers of popular products (browsers, web servers, etc.) using HTTP/1.0, started to add an unofficial extension (to the protocol) named "keep-alive" in order to allow the reuse of a connection for multiple requests/responses. [ 3 ] [ 4 ] If the client supports keep-alive, it adds an additional header to the request: Connection: keep-alive When the server receives this request and generates a response, if it supports keep-alive then it also adds the same above header to the response. Following this, the connection is not dropped, but is instead kept open. When the client sends another request, it uses the same connection. This will continue until either the client or the server decides that the conversation is over and in this case they omit the "Connection:" header from the last message sent or, better, they add the keyword "close" to it: Connection: close After that the connection is closed following specified rules. Since 1997, the various versions of HTTP/1.1 specifications acknowledged the usage of this unofficial extension and included a few caveats regarding the interoperability between HTTP/1.0 (keep-alive) and HTTP/1.1 clients / servers. [ 5 ] HTTP 1.1 [ edit ] In HTTP 1.1, all connections are considered persistent unless declared otherwise. [ 5 ] The HTTP persistent connections do not use separate keepalive messages, they just allow multiple requests to use a single connection. However, the default connection timeout of Apache httpd 1.3 and 2.0 is as little as 15 seconds [ 6 ] [ 7 ] and just 5 seconds for Apache httpd 2.2 and above. [ 8 ] [ 9 ] The advantage of a short timeout is the ability to deliver multiple components of a web page quickly while not consuming resources to run multiple server processes or threads for too long. [ 10 ] Keepalive with chunked transfer encoding [ edit ] Keepalive makes it difficult for the client to determine where one response ends and the next response begins, particularly during pipelined HTTP operation. [ 11 ] This is a serious problem when Content-Length cannot be used due to streaming. [ 12 ] To solve this problem, HTTP 1.1 introduced a chunked transfer coding that defines a last-chunk bit. [ 13 ] The last-chunk bit is set at the end of each response so that the client knows where the next response begins. Advantages [ edit ] Reduced latency in subsequent requests (no handshaking and no slow start ). Reduced CPU usage and round-trips because of fewer new connections and TLS handshakes . Enables HTTP pipelining of requests and responses. Reduced network congestion (fewer TCP connections ). Errors can be reported without the penalty of closing the TCP connection. According to RFC 7230, section 6.4 , "a client ought to limit the number of simultaneous open connections that it maintains to a given server". The previous version of the HTTP/1.1 specification stated specific maximum values but in the words of RFC 7230 "this was found to be impractical for many applications... instead... be conservative when opening multiple connections". These guidelines are intended to improve HTTP response times and avoid congestion. If HTTP pipelining is correctly implemented, there is no performance benefit to be gained from additional connections, while additional connections may cause issues with congestion. [ 14 ] Disadvantages [ edit ] If the client does not close the connection when all of the data it needs has been received, the resources needed to keep the connection open on the server will be unavailable for other clients. This affects both server's availability and the availability of resources on the server, with the degree of impact depending on the server's architecture and configuration. Also a race condition can occur where the client sends a request to the server at the same time that the server closes the TCP connection. [ 15 ] A server should send a 408 Request Timeout status code to the client immediately before closing the connection. When a client receives the 408 status code, after having sent the request, it may open a new connection to the server and re-send the request. [ 16 ] Not all clients will re-send the request, and many that do will only do so if the request has an idempotent HTTP method . Use in web browsers [ edit ] Schema of multiple vs. persistent connection. All modern web browsers including Chrome , Edge , Firefox , Opera (since 4.0), [ 17 ] and Safari use persistent connections. In Firefox, the number of simultaneous connections can be customized (per-server, per-proxy, total). Persistent connections time out after 115 seconds (1.92 minutes) of inactivity which is changeable via the configuration. [ 18 ] Implementation [ edit ] Python's requests library contains requests.Session() , which establishes a persistent HTTP connection, thereby allowing the underlying TCP connection to be reused, which can result in a significant performance increase. [ 19 ] See also [ edit ] HTTP pipelining , whereby multiple requests can be sent without waiting for a response HTTP/2 , which allows out-of-order pipelining of requests and responses, and also predictive pushing of content before it has been requested References [ edit ] ↑ Hypertext Transfer Protocol (HTTP/1.0): Overall Operation ↑ Gildor, Dan. "HTTP_Connection?" . Google Groups . Retrieved 17 November 2023 . ↑ "The TCP/IP Guide - HTTP Persistent Connection Establishment, Management and Termination" . www.tcpipguide.com . Archived from the original on 2017-05-21 . Retrieved 2017-12-31 . ↑ David Gourley; Brian Totty; Marjorie Sayer; Anshu Aggarwal; Sailu Reddy (2002). HTTP: The Definitive Guide. (excerpt of chapter: "Persistent Connections") . O'Reilly Media, inc. ISBN 9781565925090 . Retrieved 2021-10-18 . 1 2 Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing, Persistence ↑ "Apache HTTP Server 1.3 – KeepAliveTimeout Directive" . Archived from the original on 2015-10-26 . Retrieved 2015-01-28 . ↑ Apache HTTP Server 2.0 – KeepAliveTimeout Directive ↑ Apache HTTP Server 2.2 – KeepAliveTimeout Directive ↑ Apache HTTP Server 2.4 – KeepAliveTimeout Directive ↑ Multiple (wiki). "Httpd/KeepAlive" . Docforge . Archived from the original on January 6, 2010 . Retrieved 2010-01-30 . ↑ "HTTP: What are the relations between pipelining, keep alive and server sent events" . ↑ "HTTP Streaming (or Chunked vs Store & Forward)" . ↑ "Chunked Transfer Coding" . June 1999. ↑ Nielssen, Frystyk Henryk; Gettys, James; Baird-Smith, Anselm; Prud’hommeaux, Eric; Wium Lie, Håkon; Lilley, Chris (October 1997), "Network Performance Effects of HTTP/1.1, CSS1, and PNG" , ACM SIGCOMM Computer Communication Review , 27 (4), ISSN 0146-4833 ↑ "How do browsers handle HTTP keepalive race condition?" . Stack Overflow . Mar 6, 2017. ↑ Fielding, Roy T.; Reschke, Julian (June 2014). Fielding, R.; Reschke, J. (eds.). "Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content" . IETF Datatracker . doi : 10.17487/RFC7231 . S2CID 14399078 . ↑ "Opera 4.0 Upgrades File Exchange: Includes HTTP 1.1" . Opera Software. 2000-03-28 . Retrieved 2009-07-08 . ↑ "Network.http.keep-alive.timeout" . Mozillazine.org . Retrieved 2009-07-17 . ↑ "Requests.AdvancedUsage.SessionObjects" . ©MMXVIX. A Kenneth Reitz Project . Retrieved 2023-04-22 . External links [ edit ] Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing, Connection Management, Persistence Persistent Connection Behavior of Popular Browsers (dated) Apache HTTPD Keep-Alive Support Network Performance Effects of HTTP/1.1, CSS1, and PNG Retrieved from " https://en.wikipedia.org/w/index.php?title=HTTP_persistent_connection&oldid=1324875059 " Category : Hypertext Transfer Protocol Hidden categories: Articles with short description Short description matches Wikidata This page was last edited on 30 November 2025, at 00:56  (UTC) . Page was rendered with Parsoid . Text is available under the Creative Commons Attribution-ShareAlike 4.0 License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy . Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit organization. Privacy policy About Wikipedia Disclaimers Contact Wikipedia Legal & safety contacts Code of Conduct Developers Statistics Cookie statement Mobile view Search Search Toggle the table of contents HTTP persistent connection 10 languages Add topic