I am having trouble with some Http Client connections returning NoHttpResponseException about 1 in 3 times.
My hypothesis is that the firewall is closing idle connections (not unusual). I would like to use curl to mimic this.
I have been trying something like this but very likely the connection never goes idle
curl --keepalive-time 60 --limit-rate 128B $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL
What I would like is something akin to
curl $URL
sleep 10
curl $URL
sleep 20
curl $URL
sleep 30
curl $URL
Where each time (using some magic!) Curl reuses the same connection.
Is there any way to do this using curl (or wget) and not have to write a program to do it
curl will always try to keep connections alive and reuse existing connections as far as it can. Connections are kept in the connection pool, sometimes also called the connection cache.
The Curl client can tell the server that it wants to close the connection by sending the "Connection: close" header to the server. To pass the "Connection: close" header to Curl, you can use the -H command-line option.
HTTP keep-alive, a.k.a., HTTP persistent connection, is an instruction that allows a single TCP connection to remain open for multiple HTTP requests/responses. By default, HTTP connections close after each request.
There is no such thing you couldn't do with netcat.
REQ="GET / HTTP/1.1\nHost: localhost\nAccept: *\n\n"
(echo -ne $REQ; sleep 1; echo -ne $REQ; sleep 2; echo -ne $REQ) | netcat localhost 80
Change the path to something different than / if you need it...
No, there's no way for neither curl nor wget to do this. When the tool exits, it will close all connections.
I'd say that the best option for you is to use a scripting language and perhaps a libcurl binding that allows you do to all the curl magic in a more programmatic way. That way you can do a request, sleep 10 seconds and then do another request and it will then re-use the same connection - as far as possible.
There are libcurl bindings available for pretty much any programming language of your choice, and even when not using libcurl you can probably achieve this functionality although perhaps not with the same ease.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With