diff --git a/akka-http-core/src/main/mima-filters/10.2.1.backwards.excludes/remove-Http2Shadow.excludes b/akka-http-core/src/main/mima-filters/10.2.1.backwards.excludes/remove-Http2Shadow.excludes new file mode 100644 index 00000000000..af21af75fea --- /dev/null +++ b/akka-http-core/src/main/mima-filters/10.2.1.backwards.excludes/remove-Http2Shadow.excludes @@ -0,0 +1,2 @@ +# Removal of internal class +ProblemFilters.exclude[Problem]("akka.http.impl.engine.Http2Shadow*") \ No newline at end of file diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/Http2Shadow.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/Http2Shadow.scala deleted file mode 100644 index d3a058cf928..00000000000 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/Http2Shadow.scala +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2009-2020 Lightbend Inc. - */ - -package akka.http.impl.engine - -import akka.actor.{ ActorSystem, ExtendedActorSystem } -import akka.annotation.InternalApi -import akka.event.LoggingAdapter -import akka.http.scaladsl.Http.ServerBinding -import akka.http.scaladsl.ConnectionContext -import akka.http.scaladsl.model.{ HttpRequest, HttpResponse } -import akka.http.scaladsl.settings.ServerSettings -import akka.stream.{ ActorMaterializerHelper, Materializer } - -import scala.concurrent.Future - -/** INTERNAL API: Uses reflection to reach for Http2 support if available or fails with an exception */ -@InternalApi -private[akka] object Http2Shadow { - - type ShadowHttp2 = AnyRef - type ShadowHttp2Ext = { - def bindAndHandleAsync( - handler: HttpRequest => Future[HttpResponse], - interface: String, port: Int, - httpContext: ConnectionContext, - settings: ServerSettings, - parallelism: Int, - log: LoggingAdapter)(implicit fm: Materializer): Future[ServerBinding] - } - - def bindAndHandleAsync( - handler: HttpRequest => Future[HttpResponse], - interface: String, port: Int, - httpContext: ConnectionContext, - settings: ServerSettings, - parallelism: Int, - log: LoggingAdapter)(implicit fm: Materializer): Future[ServerBinding] = { - - val mat = ActorMaterializerHelper.downcast(fm) - - try { - val system = mat.system.asInstanceOf[ExtendedActorSystem] - val extensionIdClazz = system.dynamicAccess.getClassFor[ShadowHttp2]("akka.http.scaladsl.Http2").get - - val extensionInstance: ShadowHttp2Ext = extensionIdClazz.getMethod("get", Array(classOf[ActorSystem]): _*) - .invoke(null, system).asInstanceOf[ShadowHttp2Ext] - - import scala.language.reflectiveCalls - extensionInstance.bindAndHandleAsync( - handler, - interface, port, - httpContext, - settings, - parallelism, - log)(fm) - } catch { - case ex: Throwable => throw Http2SupportNotPresentException(ex) - } - } - - final case class Http2SupportNotPresentException(cause: Throwable) - extends RuntimeException("Unable to invoke HTTP2 binding logic (as enabled setting `akka.http.server.enable-http2`). " + - """Please make sure that `"com.typesafe.akka" %% "akka-http2-support" % AkkaHttpVersion` is on the classpath.""", cause) - -} diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/BufferedOutletSupport.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/BufferedOutletSupport.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/BufferedOutletSupport.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/BufferedOutletSupport.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/ByteFlag.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/ByteFlag.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/ByteFlag.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/ByteFlag.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/FrameEvent.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/FrameEvent.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/FrameEvent.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/FrameEvent.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/FrameLogger.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/FrameLogger.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/FrameLogger.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/FrameLogger.scala diff --git a/akka-http2-support/src/main/scala/akka/http/scaladsl/Http2.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2.scala similarity index 95% rename from akka-http2-support/src/main/scala/akka/http/scaladsl/Http2.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2.scala index 92fe6cfe26f..55d0d475e96 100644 --- a/akka-http2-support/src/main/scala/akka/http/scaladsl/Http2.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2.scala @@ -2,14 +2,15 @@ * Copyright (C) 2009-2020 Lightbend Inc. */ -package akka.http.scaladsl +package akka.http.impl.engine.http2 import akka.actor.{ ActorSystem, ClassicActorSystemProvider, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider } +import akka.annotation.InternalApi import akka.dispatch.ExecutionContexts import akka.event.LoggingAdapter -import akka.http.impl.engine.http2.{ Http2AlpnSupport, Http2Blueprint, ProtocolSwitch } import akka.http.impl.engine.server.{ MasterServerTerminator, UpgradeToOtherProtocolResponseHeader } import akka.http.impl.util.LogByteStringTools +import akka.http.scaladsl.{ ConnectionContext, Http, HttpsConnectionContext } import akka.http.scaladsl.Http.ServerBinding import akka.http.scaladsl.model._ import akka.http.scaladsl.model.headers.{ Connection, RawHeader, Upgrade, UpgradeProtocol } @@ -30,8 +31,13 @@ import scala.concurrent.duration.Duration import scala.util.control.NonFatal import scala.util.{ Failure, Success } -/** Entry point for Http/2 server */ -final class Http2Ext(private val config: Config)(implicit val system: ActorSystem) +/** + * INTERNAL API + * + * Internal entry points for Http/2 server + */ +@InternalApi +private[http] final class Http2Ext(private val config: Config)(implicit val system: ActorSystem) extends akka.actor.Extension { // FIXME: won't having the same package as top-level break osgi? @@ -210,7 +216,9 @@ final class Http2Ext(private val config: Config)(implicit val system: ActorSyste } } -object Http2 extends ExtensionId[Http2Ext] with ExtensionIdProvider { +/** INTERNAL API */ +@InternalApi +private[http] object Http2 extends ExtensionId[Http2Ext] with ExtensionIdProvider { val streamId = AttributeKey[Int]("x-http2-stream-id") override def get(system: ActorSystem): Http2Ext = super.get(system) diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2AlpnSupport.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2AlpnSupport.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2AlpnSupport.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2AlpnSupport.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Blueprint.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Blueprint.scala similarity index 99% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Blueprint.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Blueprint.scala index c0913160ca7..a93a7ecde52 100644 --- a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Blueprint.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Blueprint.scala @@ -15,7 +15,6 @@ import akka.http.impl.engine.http2.hpack.{ HeaderCompression, HeaderDecompressio import akka.http.impl.engine.parsing.HttpHeaderParser import akka.http.impl.util.LogByteStringTools.logTLSBidiBySetting import akka.http.impl.util.StreamUtils -import akka.http.scaladsl.Http2 import akka.http.scaladsl.model._ import akka.http.scaladsl.settings.{ ClientConnectionSettings, Http2CommonSettings, ParserSettings, ServerSettings } import akka.stream.TLSProtocol._ diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Compliance.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Compliance.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Compliance.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Compliance.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Multiplexer.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Multiplexer.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Multiplexer.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Multiplexer.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Protocol.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Protocol.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2Protocol.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2Protocol.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2ServerDemux.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2ServerDemux.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2ServerDemux.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2ServerDemux.scala diff --git a/akka-http2-support/src/main/scala/akka/http/scaladsl/model/http2/Http2SettingsHeader.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2SettingsHeader.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/scaladsl/model/http2/Http2SettingsHeader.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2SettingsHeader.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2StreamHandling.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2StreamHandling.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/Http2StreamHandling.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/Http2StreamHandling.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/IncomingFlowController.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/IncomingFlowController.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/IncomingFlowController.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/IncomingFlowController.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/PriorityTree.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/PriorityTree.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/PriorityTree.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/PriorityTree.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/ProtocolSwitch.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/ProtocolSwitch.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/ProtocolSwitch.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/ProtocolSwitch.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/RequestParsing.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/RequestParsing.scala similarity index 99% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/RequestParsing.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/RequestParsing.scala index a45b71a5ca1..37d93d06269 100644 --- a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/RequestParsing.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/RequestParsing.scala @@ -9,7 +9,7 @@ import javax.net.ssl.SSLSession import akka.annotation.InternalApi import akka.http.impl.engine.parsing.HttpHeaderParser import akka.http.impl.engine.server.HttpAttributes -import akka.http.scaladsl.{ Http2, model } +import akka.http.scaladsl.model import akka.http.scaladsl.model._ import akka.http.scaladsl.model.headers.{ `Remote-Address`, `Tls-Session-Info` } import akka.http.scaladsl.settings.ServerSettings diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/ResponseRendering.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/ResponseRendering.scala similarity index 99% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/ResponseRendering.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/ResponseRendering.scala index 6bab75ddcf3..3a265a46daf 100644 --- a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/ResponseRendering.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/ResponseRendering.scala @@ -13,7 +13,6 @@ import akka.http.scaladsl.settings.ServerSettings import scala.collection.immutable import scala.collection.immutable.VectorBuilder import FrameEvent.ParsedHeadersFrame -import akka.http.scaladsl.Http2 private[http2] object ResponseRendering { diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/StreamPrioritizer.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/StreamPrioritizer.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/StreamPrioritizer.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/StreamPrioritizer.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/client/RequestRendering.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/client/RequestRendering.scala similarity index 91% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/client/RequestRendering.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/client/RequestRendering.scala index e2dc345a406..7c42e8a01d4 100644 --- a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/client/RequestRendering.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/client/RequestRendering.scala @@ -10,8 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger import akka.annotation.InternalApi import akka.event.LoggingAdapter import akka.http.impl.engine.http2.FrameEvent.ParsedHeadersFrame -import akka.http.scaladsl.model.http2.RequestResponseAssociation -import akka.http.scaladsl.model.{ ContentTypes, HttpEntity, HttpRequest } +import akka.http.scaladsl.model.{ HttpRequest, RequestResponseAssociation } import scala.collection.immutable.VectorBuilder diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/client/ResponseParsing.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/client/ResponseParsing.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/client/ResponseParsing.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/client/ResponseParsing.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/framing/FrameRenderer.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/framing/FrameRenderer.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/framing/FrameRenderer.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/framing/FrameRenderer.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/framing/Http2FrameParsing.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/framing/Http2FrameParsing.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/framing/Http2FrameParsing.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/framing/Http2FrameParsing.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/framing/Http2FrameRendering.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/framing/Http2FrameRendering.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/framing/Http2FrameRendering.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/framing/Http2FrameRendering.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/hpack/ByteStringInputStream.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/hpack/ByteStringInputStream.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/hpack/ByteStringInputStream.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/hpack/ByteStringInputStream.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/hpack/HandleOrPassOnStage.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/hpack/HandleOrPassOnStage.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/hpack/HandleOrPassOnStage.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/hpack/HandleOrPassOnStage.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/hpack/HeaderCompression.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/hpack/HeaderCompression.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/hpack/HeaderCompression.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/hpack/HeaderCompression.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/hpack/HeaderDecompression.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/hpack/HeaderDecompression.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/hpack/HeaderDecompression.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/hpack/HeaderDecompression.scala diff --git a/akka-http2-support/src/main/scala/akka/http/impl/engine/http2/util/AsciiTreeLayout.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/http2/util/AsciiTreeLayout.scala similarity index 100% rename from akka-http2-support/src/main/scala/akka/http/impl/engine/http2/util/AsciiTreeLayout.scala rename to akka-http-core/src/main/scala/akka/http/impl/engine/http2/util/AsciiTreeLayout.scala diff --git a/akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala b/akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala index ade61ad1fea..37ef500138c 100644 --- a/akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala +++ b/akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala @@ -13,9 +13,9 @@ import akka.annotation.DoNotInherit import akka.annotation.InternalApi import akka.dispatch.ExecutionContexts import akka.event.{ Logging, LoggingAdapter } -import akka.http.impl.engine.Http2Shadow import akka.http.impl.engine.HttpConnectionIdleTimeoutBidi import akka.http.impl.engine.client._ +import akka.http.impl.engine.http2.Http2 import akka.http.impl.engine.server._ import akka.http.impl.engine.ws.WebSocketClientBlueprint import akka.http.impl.settings.{ ConnectionPoolSetup, HostConnectionPoolSetup } @@ -341,7 +341,7 @@ class HttpExt private[http] (private val config: Config)(implicit val system: Ex if (parallelism > 0) settings.mapHttp2Settings(_.withMaxConcurrentStreams(parallelism)) else if (parallelism < 0) throw new IllegalArgumentException("Only positive values allowed for `parallelism`.") else settings - Http2Shadow.bindAndHandleAsync(handler, interface, port, connectionContext, definitiveSettings, definitiveSettings.http2Settings.maxConcurrentStreams, log)(fm) + Http2().bindAndHandleAsync(handler, interface, port, connectionContext, definitiveSettings, definitiveSettings.http2Settings.maxConcurrentStreams, log)(fm) } else { val definitiveParallelism = if (parallelism > 0) parallelism diff --git a/akka-http2-support/src/main/scala/akka/http/scaladsl/model/http2/RequestResponseAssociation.scala b/akka-http-core/src/main/scala/akka/http/scaladsl/model/RequestResponseAssociation.scala similarity index 64% rename from akka-http2-support/src/main/scala/akka/http/scaladsl/model/http2/RequestResponseAssociation.scala rename to akka-http-core/src/main/scala/akka/http/scaladsl/model/RequestResponseAssociation.scala index 5424434c945..4f62ea99338 100644 --- a/akka-http2-support/src/main/scala/akka/http/scaladsl/model/http2/RequestResponseAssociation.scala +++ b/akka-http-core/src/main/scala/akka/http/scaladsl/model/RequestResponseAssociation.scala @@ -2,10 +2,18 @@ * Copyright (C) 2020 Lightbend Inc. */ -package akka.http.scaladsl.model.http2 +package akka.http.scaladsl.model + +import akka.annotation.ApiMayChange /** * A marker trait for attribute values that should be (automatically) carried over from request to response. */ +@ApiMayChange trait RequestResponseAssociation + +/** + * A simple value holder class implementing RequestResponseAssociation. + */ +@ApiMayChange final case class SimpleRequestResponseAttribute[T](value: T) extends RequestResponseAssociation diff --git a/akka-http2-support/src/main/scala/akka/http/scaladsl/model/http2/Http2Exception.scala b/akka-http-core/src/main/scala/akka/http/scaladsl/model/http2/Http2Exception.scala similarity index 92% rename from akka-http2-support/src/main/scala/akka/http/scaladsl/model/http2/Http2Exception.scala rename to akka-http-core/src/main/scala/akka/http/scaladsl/model/http2/Http2Exception.scala index 83edee5b6f0..2002eb602af 100644 --- a/akka-http2-support/src/main/scala/akka/http/scaladsl/model/http2/Http2Exception.scala +++ b/akka-http-core/src/main/scala/akka/http/scaladsl/model/http2/Http2Exception.scala @@ -4,6 +4,7 @@ package akka.http.scaladsl.model.http2 +import akka.annotation.ApiMayChange import akka.http.impl.engine.http2.Http2Protocol.ErrorCode import scala.util.control.NoStackTrace @@ -11,11 +12,13 @@ import scala.util.control.NoStackTrace /** * Base class for HTTP2 exceptions. */ +@ApiMayChange class Http2Exception(msg: String) extends RuntimeException(msg) /** * Exception that will be reported on the request entity stream when the peer closed the stream. */ +@ApiMayChange class PeerClosedStreamException(val streamId: Int, val errorCode: String, val numericErrorCode: Int) extends Http2Exception(f"Stream with ID [$streamId%d] was closed by peer with code $errorCode%s(0x$numericErrorCode%02x)") with NoStackTrace { private[http] def this(streamId: Int, errorCode: ErrorCode) = this(streamId, errorCode.toString, errorCode.id) diff --git a/akka-http2-support/src/test/java/akka/http/javadsl/Http2JavaServerTest.java b/akka-http2-support/src/test/java/akka/http/javadsl/Http2JavaServerTest.java index b7ee5320430..95987864122 100644 --- a/akka-http2-support/src/test/java/akka/http/javadsl/Http2JavaServerTest.java +++ b/akka-http2-support/src/test/java/akka/http/javadsl/Http2JavaServerTest.java @@ -8,10 +8,7 @@ import akka.http.impl.util.ExampleHttpContexts; import akka.http.javadsl.model.HttpRequest; import akka.http.javadsl.model.HttpResponse; -import akka.http.javadsl.HttpsConnectionContext; import akka.japi.function.Function; -import akka.stream.ActorMaterializer; -import akka.stream.Materializer; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; @@ -31,7 +28,6 @@ public static void main(String[] args) { "akka.http.server.preview.enable-http2 = on\n" ); ActorSystem system = ActorSystem.create("ServerTest", testConf); - Materializer materializer = ActorMaterializer.create(system); Function> handler = request -> CompletableFuture.completedFuture(HttpResponse.create().withEntity(request.entity())); diff --git a/akka-http2-support/src/test/scala/akka/http/h2spec/H2SpecIntegrationSpec.scala b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/H2SpecIntegrationSpec.scala similarity index 95% rename from akka-http2-support/src/test/scala/akka/http/h2spec/H2SpecIntegrationSpec.scala rename to akka-http2-support/src/test/scala/akka/http/impl/engine/http2/H2SpecIntegrationSpec.scala index 1468eb6e6b6..96d45d09d12 100644 --- a/akka-http2-support/src/test/scala/akka/http/h2spec/H2SpecIntegrationSpec.scala +++ b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/H2SpecIntegrationSpec.scala @@ -2,14 +2,14 @@ * Copyright (C) 2009-2020 Lightbend Inc. */ -package akka.http.h2spec +package akka.http.impl.engine.http2 import java.io.File import java.util.concurrent.atomic.AtomicBoolean import akka.http.impl.util.{ ExampleHttpContexts, WithLogCapturing } +import akka.http.scaladsl.Http import akka.http.scaladsl.server.Directives -import akka.http.scaladsl.Http2 import akka.stream.ActorMaterializer import akka.testkit._ import akka.util.ByteString @@ -25,6 +25,7 @@ class H2SpecIntegrationSpec extends AkkaSpec( loglevel = DEBUG loggers = ["akka.http.impl.util.SilenceAllTestEventListener"] http.server.log-unencrypted-network-bytes = off + http.server.preview.enable-http2 = on http.server.http2.log-frames = on actor.serialize-creators = off @@ -43,7 +44,12 @@ class H2SpecIntegrationSpec extends AkkaSpec( complete(data) } - val binding = Http2().bindAndHandleAsync(echo, "127.0.0.1", 0, ExampleHttpContexts.exampleServerContext).futureValue + val binding = + Http() + .newServerAt("127.0.0.1", 0) + .enableHttps(ExampleHttpContexts.exampleServerContext) + .bind(echo) + .futureValue val port = binding.localAddress.getPort "H2Spec" must { diff --git a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/H2cUpgradeSpec.scala b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/H2cUpgradeSpec.scala index d7c254d46df..6654bf0eb80 100644 --- a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/H2cUpgradeSpec.scala +++ b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/H2cUpgradeSpec.scala @@ -6,7 +6,7 @@ package akka.http.impl.engine.http2 import akka.http.impl.util._ import akka.http.scaladsl.model.{ HttpResponse, StatusCodes } -import akka.http.scaladsl.{ Http2, HttpConnectionContext } +import akka.http.scaladsl.HttpConnectionContext import akka.stream.scaladsl.{ Source, Tcp } import akka.util.ByteString diff --git a/akka-http2-support/src/test/scala/akka/http/scaladsl/Http2ClientApp.scala b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientApp.scala similarity index 92% rename from akka-http2-support/src/test/scala/akka/http/scaladsl/Http2ClientApp.scala rename to akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientApp.scala index 7e992fa0910..183a6fd60c3 100644 --- a/akka-http2-support/src/test/scala/akka/http/scaladsl/Http2ClientApp.scala +++ b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientApp.scala @@ -2,21 +2,20 @@ * Copyright (C) 2020 Lightbend Inc. */ -package akka.http.scaladsl +package akka.http.impl.engine.http2 import akka.actor.ActorSystem -import akka.http.scaladsl.model.headers import akka.http.scaladsl.model.headers.HttpEncodings -import akka.http.scaladsl.model.http2.RequestResponseAssociation -import akka.http.scaladsl.model.{ AttributeKey, HttpRequest, HttpResponse } +import akka.http.scaladsl.model.{ AttributeKey, HttpRequest, HttpResponse, RequestResponseAssociation, headers } import akka.stream.OverflowStrategy import akka.stream.scaladsl.{ Flow, Sink, Source } import com.typesafe.config.ConfigFactory -import scala.concurrent.{ Future, Promise } import scala.concurrent.duration._ +import scala.concurrent.{ Future, Promise } /** A small example app that shows how to use the HTTP/2 client API currently against actual internet servers */ +// needs to live in impl.engine.http2 for now as we have no public access to the internal HTTP2 client object Http2ClientApp extends App { val config = ConfigFactory.parseString( @@ -30,7 +29,7 @@ object Http2ClientApp extends App { implicit val system = ActorSystem("Http2ClientApp", config) implicit val ec = system.dispatcher - val dispatch = singleRequest(Http2().outgoingConnection("doc.akka.io")) + val dispatch = singleRequest(Http2().outgoingConnection("doc.akka.io")) // FIXME: replace with public API dispatch(HttpRequest(uri = "https://doc.akka.io/api/akka/current/akka/actor/typed/scaladsl/index.html", headers = headers.`Accept-Encoding`(HttpEncodings.gzip) :: Nil)).onComplete { res => println(s"[1] Got index.html: $res") diff --git a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientServerSpec.scala b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientServerSpec.scala index 21a6d193c73..16e7f3609b0 100644 --- a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientServerSpec.scala +++ b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientServerSpec.scala @@ -6,13 +6,11 @@ package akka.http.impl.engine.http2 import akka.http.impl.engine.ws.ByteStringSinkProbe import akka.http.impl.util.{ AkkaSpecWithMaterializer, ExampleHttpContexts } -import akka.http.scaladsl.model.headers +import akka.http.scaladsl.model.{ AttributeKey, ContentTypes, HttpEntity, HttpHeader, HttpMethod, HttpMethods, HttpRequest, HttpResponse, RequestResponseAssociation, StatusCode, StatusCodes, Uri, headers } import akka.http.scaladsl.model.headers.HttpEncodings -import akka.http.scaladsl.model.http2.RequestResponseAssociation -import akka.http.scaladsl.model.{ AttributeKey, ContentTypes, HttpEntity, HttpHeader, HttpMethod, HttpMethods, HttpRequest, HttpResponse, StatusCode, StatusCodes, Uri } import akka.http.scaladsl.settings.ClientConnectionSettings import akka.http.scaladsl.unmarshalling.Unmarshal -import akka.http.scaladsl.{ Http, Http2 } +import akka.http.scaladsl.Http import akka.stream.scaladsl.{ Sink, Source } import akka.stream.testkit.{ TestPublisher, TestSubscriber } import akka.testkit.TestProbe diff --git a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientSpec.scala b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientSpec.scala index 1aa5ffe425e..0ecd9112a43 100644 --- a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientSpec.scala +++ b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ClientSpec.scala @@ -9,7 +9,6 @@ import akka.event.Logging import akka.http.impl.engine.http2.FrameEvent._ import akka.http.impl.engine.http2.Http2Protocol.ErrorCode import akka.http.impl.util.{ AkkaSpecWithMaterializer, LogByteStringTools } -import akka.http.scaladsl.Http2 import akka.http.scaladsl.model.HttpEntity.Strict import akka.http.scaladsl.model._ import akka.http.scaladsl.settings.ClientConnectionSettings @@ -58,10 +57,9 @@ class Http2ClientSpec extends AkkaSpecWithMaterializer(""" "GET request in one HEADERS frame" in new SimpleRequestResponseRoundtripSetup { requestResponseRoundtrip( streamId = 1, - request = HttpRequest(uri = "http://www.example.com/"), + request = HttpRequest(uri = "https://www.example.com/"), expectedHeaders = Seq( ":method" -> "GET", - // TODO check if this makes sense? ":scheme" -> "https", ":authority" -> "www.example.com", ":path" -> "/", @@ -93,7 +91,7 @@ class Http2ClientSpec extends AkkaSpecWithMaterializer(""" "GOAWAY when the response to a second request on different stream has an invalid headers frame" in new SimpleRequestResponseRoundtripSetup { requestResponseRoundtrip( streamId = 1, - request = HttpRequest(uri = "http://www.example.com/"), + request = HttpRequest(uri = "https://www.example.com/"), expectedHeaders = Seq( ":method" -> "GET", // TODO check if this makes sense? @@ -111,7 +109,7 @@ class Http2ClientSpec extends AkkaSpecWithMaterializer(""" .withEntity(Strict(ContentTypes.NoContentType, ByteString.empty)) ) - emitRequest(3, HttpRequest(uri = "http://www.example.com/")) + emitRequest(3, HttpRequest(uri = "https://www.example.com/")) expectFrame() shouldBe a[HeadersFrame] val incorrectHeaderBlock = hex"00 00 01 01 05 00 00 00 01 40" diff --git a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2FrameSending.scala b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2FrameSending.scala index 752b7cc2f88..c4fdd05b4da 100644 --- a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2FrameSending.scala +++ b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2FrameSending.scala @@ -11,8 +11,8 @@ import akka.http.impl.engine.http2.Http2Protocol.{ ErrorCode, Flags, FrameType, import akka.http.impl.engine.http2.framing.FrameRenderer import akka.util.{ ByteString, ByteStringBuilder } -trait Http2FrameSending { - def sendBytes(bytes: ByteString) +private[http2] trait Http2FrameSending { + def sendBytes(bytes: ByteString): Unit def sendFrame(frame: FrameEvent): Unit = sendBytes(FrameRenderer.render(frame)) diff --git a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ServerSpec.scala b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ServerSpec.scala index a05c9b7a4d7..1b50c5f2db9 100644 --- a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ServerSpec.scala +++ b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/Http2ServerSpec.scala @@ -30,7 +30,6 @@ import scala.concurrent.{ Await, Future, Promise } import scala.concurrent.duration._ import FrameEvent._ import akka.event.Logging -import akka.http.scaladsl.Http2 import akka.stream.Attributes import akka.stream.Attributes.LogLevels import akka.stream.testkit.scaladsl.StreamTestKit diff --git a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/RequestParsingSpec.scala b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/RequestParsingSpec.scala index a07e4c077a4..dee55d30d65 100644 --- a/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/RequestParsingSpec.scala +++ b/akka-http2-support/src/test/scala/akka/http/impl/engine/http2/RequestParsingSpec.scala @@ -14,7 +14,6 @@ import akka.testkit.AkkaSpec import akka.util.ByteString import org.scalatest.{ Inside, Inspectors } import FrameEvent._ -import akka.http.scaladsl.Http2 class RequestParsingSpec extends AkkaSpec() with Inside with Inspectors { diff --git a/akka-http2-support/src/test/scala/akka/http/scaladsl/Http2BindingViaConfigSpec.scala b/akka-http2-support/src/test/scala/akka/http/scaladsl/Http2BindingViaConfigSpec.scala deleted file mode 100644 index 14663bf4391..00000000000 --- a/akka-http2-support/src/test/scala/akka/http/scaladsl/Http2BindingViaConfigSpec.scala +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2009-2020 Lightbend Inc. - */ - -package akka.http.scaladsl - -import akka.event.Logging -import akka.http.impl.util.ExampleHttpContexts -import akka.http.scaladsl.model._ -import akka.stream._ -import akka.testkit.{ AkkaSpec, TestProbe } - -import scala.concurrent.Future -import scala.concurrent.duration.{ Duration, _ } - -class Http2BindingViaConfigSpec extends AkkaSpec(""" - akka.http.server.preview.enable-http2 = on - - akka.loglevel = DEBUG - akka.log-dead-letters = off - """) { - implicit val mat = ActorMaterializer() - import system.dispatcher - - var binding: Future[Http.ServerBinding] = _ // initialized atStartup - - val helloWorldHandler: HttpRequest => Future[HttpResponse] = - _ => Future(HttpResponse(entity = "Hello!")) - - "akka.http.server.enable-http2" should { - "bind using HTTP/2 with HttpsConnectionContext provided" in { - // since we're in akka-http core here, the http2 support is not available on classpath, - // so the setting + binding should fail - - var binding: Future[Http.ServerBinding] = null - try { - val p = TestProbe() - system.eventStream.subscribe(p.ref, classOf[Logging.Debug]) - - val connectionContext = ExampleHttpContexts.exampleServerContext - binding = - Http().newServerAt("localhost", 0) - .enableHttps(connectionContext) - .bind(helloWorldHandler) - - // TODO we currently don't verify it really bound as h2, since we don't have a client lib - fishForDebugMessage(p, "Binding server using HTTP/2") - } finally if (binding ne null) binding.map(_.unbind()) - } - } - - "Http2Shadow" should { - "have ShadowHttp2Ext type aligned with real Http2Ext" in { - val ext: Http2Ext = Http2() - // the Shadow is a structural type, so this assignment only works - // if all the methods it requires exist on the real class - val typed: akka.http.impl.engine.Http2Shadow.ShadowHttp2Ext = ext - val _ = typed.bindAndHandleAsync _ // to avoid not-used warnings - } - } - - private def fishForDebugMessage(a: TestProbe, messagePrefix: String, max: Duration = 3.seconds): Unit = { - a.fishForMessage(max, hint = "expected debug message part: " + messagePrefix) { - case Logging.Debug(_, _, msg: String) if msg contains messagePrefix => true - case _ => false - } - } - -} diff --git a/docs/src/main/paradox/compatibility-guidelines.md b/docs/src/main/paradox/compatibility-guidelines.md index f79b12f9545..ca8360ef5f9 100644 --- a/docs/src/main/paradox/compatibility-guidelines.md +++ b/docs/src/main/paradox/compatibility-guidelines.md @@ -81,6 +81,10 @@ Scala akka.http.scaladsl.model.headers.CacheDirectives.immutableDirective akka.http.scaladsl.model.headers.X-Forwarded-Host akka.http.scaladsl.model.headers.X-Forwarded-Proto + akka.http.scaladsl.model.http2.PeerClosedStreamException + akka.http.scaladsl.model.http2.Http2Exception + akka.http.scaladsl.model.SimpleRequestResponseAttribute + akka.http.scaladsl.model.RequestResponseAssociation ``` Java diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 3e0726d10bc..0e0f5a6af51 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -91,6 +91,7 @@ object Dependencies { ) lazy val httpCore = l ++= Seq( + hpack, Test.sprayJson, // for WS Autobahn test metadata Test.scalatest, Test.scalatestplusScalacheck, Test.scalatestplusJUnit, Test.junit ) @@ -103,7 +104,7 @@ object Dependencies { lazy val http = Seq() - lazy val http2 = l ++= Seq(hpack) + lazy val http2 = l ++= Seq() lazy val http2Support = l ++= Seq(Test.h2spec)