In a bash shell scipt, I use several command line tools (
httpie) to test my http server.
When using e.g. curl to invoke a GET request, I see that a tcp connection is opened to my server and closed immediatly after the http communication has been completed.
$ curl http://10.5.1.1/favicon.ico -o /dev/null
For better testing the keep-alive behaviour of my server, I want to keep the tcp connection open over multiple http request / response cycles.
I am able to perform poor http requests directly from bash like this:
exec 3<>/dev/tcp/10.5.1.1/80 printf "GET /\r\n\r\n" >&3 while IFS= read -r -u3 -t2 line || [[ -n "$line" ]]; do echo "$line"; done exec 3>&- exec 3<&-
But because my testing communication is much more complex (incl. authentication et cetera), I don't want to code this completely myself in bash or other scripting language but want to use existing tools instead. The idea is now to first open a tcp socket in bash and then forcing some command line tools to use this connection instead of open their own sockets. Maybe like this;
exec 3<>/dev/tcp/10.5.1.1/80 curl http://10.5.1.1/message.txt --use-existing-socket-fd=3 # ... do some other testing stuff ... wget http://10.5.1.1/message.txt --use-existing-socket-fd=3 # ... do some other testing stuff ... http http://10.5.1.1/message.txt --use-existing-socket-fd=3 exec 3>&- exec 3<&-
Might this be possible using the above mentioned tools or with other tools?