From 099b9ec59a8b5f344648210a6171dced3b9964e1 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Wed, 13 Nov 2024 13:54:18 -0800 Subject: [PATCH] http (feature): Add interface for Scala Native --- .../scala/wvlet/airframe/http/Compat.scala | 32 +++++++++++++++++++ .../scala/wvlet/airframe/http/CompatApi.scala | 2 +- .../http/client/HttpClientFilterTest.scala | 4 +++ build.sbt | 8 +++-- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 airframe-http/.native/src/main/scala/wvlet/airframe/http/Compat.scala diff --git a/airframe-http/.native/src/main/scala/wvlet/airframe/http/Compat.scala b/airframe-http/.native/src/main/scala/wvlet/airframe/http/Compat.scala new file mode 100644 index 0000000000..69d0f80239 --- /dev/null +++ b/airframe-http/.native/src/main/scala/wvlet/airframe/http/Compat.scala @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wvlet.airframe.http + +import wvlet.airframe.http.client.HttpClientBackend + +import scala.concurrent.ExecutionContext + +/** + * Scala Native specific implementation + */ +private object Compat extends CompatApi { + override def urlEncode(s: String): String = ??? + override def defaultHttpClientBackend: HttpClientBackend = ??? + + override def defaultExecutionContext: ExecutionContext = ??? + override def defaultHttpClientLoggerFactory: HttpLoggerConfig => HttpLogger = ??? + override def currentRPCContext: RPCContext = ??? + override def attachRPCContext(context: RPCContext): RPCContext = ??? + override def detachRPCContext(previous: RPCContext): Unit = ??? +} diff --git a/airframe-http/src/main/scala/wvlet/airframe/http/CompatApi.scala b/airframe-http/src/main/scala/wvlet/airframe/http/CompatApi.scala index 90548c16c1..c5702278f2 100644 --- a/airframe-http/src/main/scala/wvlet/airframe/http/CompatApi.scala +++ b/airframe-http/src/main/scala/wvlet/airframe/http/CompatApi.scala @@ -23,7 +23,7 @@ import scala.concurrent.ExecutionContext private[http] trait CompatApi { def urlEncode(s: String): String - def hostServerAddress: ServerAddress + def hostServerAddress: ServerAddress = ServerAddress.empty def defaultHttpClientBackend: HttpClientBackend def defaultExecutionContext: ExecutionContext def defaultHttpClientLoggerFactory: HttpLoggerConfig => HttpLogger diff --git a/airframe-http/src/test/scala/wvlet/airframe/http/client/HttpClientFilterTest.scala b/airframe-http/src/test/scala/wvlet/airframe/http/client/HttpClientFilterTest.scala index b688c78fdb..a68ac7b7cd 100644 --- a/airframe-http/src/test/scala/wvlet/airframe/http/client/HttpClientFilterTest.scala +++ b/airframe-http/src/test/scala/wvlet/airframe/http/client/HttpClientFilterTest.scala @@ -24,6 +24,10 @@ import scala.concurrent.TimeoutException object HttpClientFilterTest extends AirSpec { + if (isScalaNative) { + pending(s"Http client is not supported in Scala Native yet") + } + private def newDummyClient(config: HttpClientConfig, f: PartialFunction[Request, Response]): AsyncClient = new AsyncClientImpl(new DummyHttpChannel(f), config) diff --git a/build.sbt b/build.sbt index f78301698d..7e95e802ca 100644 --- a/build.sbt +++ b/build.sbt @@ -280,7 +280,8 @@ lazy val nativeProjects: Seq[ProjectReference] = Seq( ulid.native, rx.native, control.native, - codec.native + codec.native, + http.native ) // Integration test projects @@ -767,7 +768,7 @@ lazy val rx = .dependsOn(log) lazy val http = - crossProject(JVMPlatform, JSPlatform) + crossProject(JVMPlatform, JSPlatform, NativePlatform) .crossType(CrossType.Pure) .enablePlugins(BuildInfoPlugin) .in(file("airframe-http")) @@ -797,6 +798,9 @@ lazy val http = "org.scala-js" %%% "scalajs-dom" % SCALAJS_DOM_VERSION ) ) + .nativeSettings( + nativeBuildSettings + ) .dependsOn(rx, control, surface, json, codec, di) lazy val httpCodeGen =