I am trying to request a persistent HTTP Connection using Scala Spray-client library such that the client has to establish the connection once and then it can make multiple calls on the same connection.
I am not able to find any information for this on the Spray documentation page
I think by default spray client will reuse connections where possible.
By default, connections that are unused for 60 seconds will be terminated by the client.
From the reference config of spray:
If we disable idle timeouts, our connections will stay active forever unless the remote server is set to kill idle connections after some timeout (it probably is, but spray client should make sure we can always get a new connection, obeying the limit bellow).
We can limit the size of the Host Connector pool to 1 to get the desired behaviour (one connection per host):
This will mean that if we send a second request before our first request has received a response the second will not be sent until the first is completed. To send multiple requests on a single connection without waiting for the first to complete we can enable pipelining.