Curl/Bash code for Curl Close Connection Header ExampleThis Curl/Bash code snippet was generated automatically for the Curl Close Connection Header example.
<< Back to the Curl Close Connection Header example
What is Curl?
Curl is a command-line utility that allows sending HTTP requests to the server with different parameters and methods. Curl is universal, works on all modern platforms - Linux, Mac, Windows, supports over 25+ protocols, including HTTP, HTTPS, FTP, and has built-in support for proxies, web forms, HTTP Cookies, user authentication, and SSL.
What is Connection Header?
The Сonnection Header determines whether the current network connection remains open after a transaction. A persistent connection allows multiple requests to be sent without opening a new connection for each request/response pair. When the "Connection: close" header is used in the request message, the server closes the connection after sending the response message. To pass the "Connection: close" header for the Curl request, use the -H command-line option.
Curl Close Connection Header Syntax
The following is the syntax of sending a Curl request with a Close Connection Header:
How to Close a Connection in Curl?
This example shows how to tell Curl to close the connection by passing in the "Connection: close" header using the -H command line parameter.
Close Connection in HTTP versions
The table shows the difference between closing connections in HTTP versions.
|HTTP/1.0||In HTTP/1.0, the server by default always closes the connection after sending a response, unless the client has sent a "Connection: open" request header. If there is no such header, the server will close the connection after sending the response to the client.|
|HTTP/1.1||In HTTP 1.1, the server does not close the connection after sending the response, and clients need to pass the "Connection: close" header if they want the connection to be closed after receiving the response from the server. An HTTP/1.1 server typically supports 2 to 8 open TCP connections per client.|
|HTTP/2||In HTTP/2, requests are bundled into the same TCP connection so that the browser can send them simultaneously without waiting for a response to a previous request. On the server-side, connections from various clients will remain open until they are closed by the client or the server-side timed out. In HTTP/2, the server only needs to support one TCP connection per client, which is less than in HTTP/1.1|
What is TCP connection?
TCP (Transmission Control Protocol) is a communication protocol that allows computing devices and application programs to exchange messages over a network. TCP is one of the main Internet standards defined by the IETF (Internet Engineering Task Force), which defines the rules of the Internet. TCP is one of the most commonly used protocols in digital network communications and provides end-to-end data delivery.