Faq

Do I need to specify any params to ensure requests are concurrent?

No additional params are required, but you have to do them all in the same call, just like it’s documented.

Whether the requests will be performed concurrently is dependent on the server, i.e. HTTP/2 enabled servers can receive multiple requests at the same time, and HTTP/1.1 servers supporting pipeline as well.

Concurrency is therefore protocol-dependent, and httpx will not support distributing M requests over N connections on the same pool. If the server you’re requesting to doesn’t fit the criteria above, check Connection Pools.

Will each thread need its own static Session object with the persistent plugin in order to leverage the persistent connections?

No. httpx handles the complexity for you, so you just need to assign HTTPX.plugin(:persistent) to a variable, and this can be used in any context.

httpx does maintain per-session connection pools however, meaning that, if you’re using multiple threads, connections to the same origin server will be managed in a thread-safe manner.

How can I tell if connections are being reused?

You can troubleshoot that by enabling the logs, where information of DNS requests, TLS handshake and connection state transitions will be displayed.

How do I force HTTP/1.1 even if the server supports HTTP/2?

You must disable it in the ALPN negotiation:

HTTPX.with(ssl: { alpn_protocols: %w[http/1.1] }).get("https://example.com")

Will httpx ever support other protocols?

This library does HTTP only, and will not support other protocols. Ever. There is only one cURL :) .

Next: home