For an Akka HTTP HTTPS request, configure its client transport to establish CONNECT through the forward proxy:

import java.net.InetSocketAddress
import akka.http.scaladsl.{ClientTransport, Http}
import akka.http.scaladsl.model.HttpRequest
import akka.http.scaladsl.settings.ConnectionPoolSettings

val transport = ClientTransport.httpsProxy(
  InetSocketAddress.createUnresolved("proxy.example", 8080))

val settings = ConnectionPoolSettings(system)
  .withConnectionSettings(_.withTransport(transport))

val response = Http().singleRequest(
  HttpRequest(uri = "https://example.com/"),
  settings = settings)

The application supplies its existing ActorSystem as system and retains the usual stream and response-entity lifecycle. Consume or discard the returned response entity as appropriate so the connection can be released.

The name httpsProxy refers here to establishing an HTTPS destination connection through an HTTP CONNECT proxy. It is not an instruction to open a TLS session to the proxy listener itself.

Pass the customized settings into the request or pool that sends the traffic. Constructing settings beside a call that uses another pool configuration leaves that call unchanged.

Akka documents this transport for HTTPS requests. Keep the destination as its real HTTPS URI. An HTTP endpoint from the HTTP proxy list is a candidate for the transport when it permits the required CONNECT destination. A server-side bindFlow forwarding example creates another HTTP service and answers a different construction problem.

Ũhoro ũhĩtĩte