0
私はスカラのスカラーからakka-http に書き直しています。プロジェクトのサードパーティの依存関係の数を減らすためです同じプロジェクトです)。コードは、一般的なタイプの要求を、ライブラリによって提供される基本的な一般要求に単純にラップします。プロキシを使用してakka-httpリクエストをルーティングする
大抵は問題なく、要求にプロキシを追加するという問題があります。
要求は、いずれかの宛先への、または実行時のパラメータによって決定プロキシを介して、直接的であるべきです。私scalajの実装では
、私は次のヘルパークラスとメソッド
object HttpUtils {
private def request(
host: Host,
method: HttpMethod,
params: Map[String, String],
postData: Option[String],
timeout: Duration,
headers: Seq[(String, String)],
proxy: Option[ProxyConfig]
): HttpResponse[String] = {
// most general request builder. Other methods in the object fill in parameters and wrap this in a Future
val baseRequest = Http(host.url)
val proxiedRequest = addProxy(proxy, baseRequest)
val fullRequest = addPostData(postData)(proxiedRequest)
.method(method.toString)
.params(params)
.headers(headers)
.option(HttpOptions.connTimeout(timeout.toMillis.toInt))
.option(HttpOptions.readTimeout(timeout.toMillis.toInt))
fullRequest.asString // scalaj for send off request and block until response
}
// Other methods ...
private def addProxy(proxy: Option[ProxyConfig], request: HttpRequest): HttpRequest =
proxy.fold(request)((p: ProxyConfig) => request.proxy(p.host, p.port))
}
case class ProxyConfig(host: String, port: Int)
はアッカ-HTTPと同様の構造を構築する方法はありますか?