Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve http2 option when going from javadsl to scaladsl #2149

Merged
merged 2 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ ProblemFilters.exclude[IncompatibleResultTypeProblem]("akka.http.scaladsl.settin
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.http.scaladsl.settings.Http2ServerSettings#Http2ServerSettingsImpl.apply")
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.http.scaladsl.settings.Http2ServerSettings#Http2ServerSettingsImpl.copy")
ProblemFilters.exclude[DirectMissingMethodProblem]("akka.http.scaladsl.settings.Http2ServerSettings#Http2ServerSettingsImpl.this")

# #2149: additions to @DoNotInherit classes

ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.javadsl.HttpsConnectionContext.withHttp2")
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.javadsl.HttpConnectionContext.withHttp2")
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.javadsl.ConnectionContext.withHttp2")
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package akka.http.javadsl
import java.util.Locale
import java.util.Optional

import scala.compat.java8.OptionConverters._

import akka.annotation.{ DoNotInherit, InternalApi }
import akka.http.javadsl.model.Uri
import akka.http.scaladsl.UseHttp2.Negotiated
Expand All @@ -21,11 +23,14 @@ abstract class ConnectHttp {
def http2: UseHttp2

final def effectiveHttpsConnectionContext(fallbackContext: HttpsConnectionContext): HttpsConnectionContext =
connectionContext.orElse(fallbackContext)
connectionContext.asScala
.getOrElse(fallbackContext)
.withHttp2(http2)

final def effectiveConnectionContext(fallbackContext: ConnectionContext): ConnectionContext =
if (connectionContext.isPresent) connectionContext.get()
else fallbackContext
connectionContext.asScala // Optional doesn't deal well with covariance
.getOrElse(fallbackContext)
.withHttp2(http2)

override def toString = s"ConnectHttp($host,$port,$isHttps,$connectionContext,$http2)"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ abstract class ConnectionContext {
def sslConfig: Option[AkkaSSLConfig]
def http2: UseHttp2

def withHttp2(newValue: UseHttp2): ConnectionContext

@deprecated("'default-http-port' and 'default-https-port' configuration properties are used instead", since = "10.0.11")
def getDefaultPort: Int
}
Expand All @@ -74,13 +76,17 @@ abstract class HttpConnectionContext(override val http2: UseHttp2) extends akka.
override final def isSecure = false
override final def getDefaultPort = 80
override def sslConfig: Option[AkkaSSLConfig] = None

override def withHttp2(newValue: UseHttp2): HttpConnectionContext
}

@DoNotInherit
abstract class HttpsConnectionContext(override val http2: UseHttp2) extends akka.http.javadsl.ConnectionContext {
override final def isSecure = true
override final def getDefaultPort = 443

override def withHttp2(newValue: UseHttp2): HttpsConnectionContext

/** Java API */
def getEnabledCipherSuites: Optional[JCollection[String]]
/** Java API */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.typesafe.sslconfig.akka.AkkaSSLConfig
import scala.collection.JavaConverters._
import java.util.{ Optional, Collection ⇒ JCollection }

import akka.http.javadsl
import akka.http.scaladsl.UseHttp2.Negotiated
import javax.net.ssl._

Expand Down Expand Up @@ -93,11 +94,22 @@ final class HttpsConnectionContext(
override def getEnabledProtocols: Optional[JCollection[String]] = enabledProtocols.map(_.asJavaCollection).asJava
override def getClientAuth: Optional[TLSClientAuth] = clientAuth.asJava
override def getSslParameters: Optional[SSLParameters] = sslParameters.asJava

override def withHttp2(newValue: javadsl.UseHttp2): javadsl.HttpsConnectionContext =
withHttp2(newValue.asScala)
def withHttp2(newValue: UseHttp2): javadsl.HttpsConnectionContext =
new HttpsConnectionContext(sslContext, sslConfig, enabledCipherSuites, enabledProtocols, clientAuth, sslParameters, newValue)
}

sealed class HttpConnectionContext(http2: UseHttp2) extends akka.http.javadsl.HttpConnectionContext(http2) with ConnectionContext {
def this() = this(Negotiated)

override def withHttp2(newValue: javadsl.UseHttp2): javadsl.HttpConnectionContext =
withHttp2(newValue.asScala)
def withHttp2(newValue: UseHttp2): javadsl.HttpConnectionContext =
new HttpConnectionContext(newValue)
}

final object HttpConnectionContext extends HttpConnectionContext(Negotiated) {
/** Java API */
def getInstance() = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,14 @@ class ConnectHttpSpec extends WordSpec with Matchers with BeforeAndAfterAll {
}
ex.getMessage should include("non https scheme!")
}
"connect toHost HTTP/2 only" in {
val connect = ConnectHttp.toHost("http://127.0.0.1", 8080, UseHttp2.always)
connect.effectiveConnectionContext(httpsContext).http2 should equal(UseHttp2.always)
}
"connect toHostHttps HTTP/2 only" in {
val connect = ConnectHttp.toHostHttps("https://127.0.0.1", 8080, UseHttp2.always)
connect.effectiveConnectionContext(httpsContext).http2 should equal(UseHttp2.always)
}

}
}