Skip to content

Commit

Permalink
Preserve http2 option when doing from javadsl to scaladsl
Browse files Browse the repository at this point in the history
The only information passed from javadsl to the scaladsl in Http
was the context which for Http connections was always the default one
meaning that setting http2 always had no effect.
  • Loading branch information
chbatey committed Aug 15, 2018
1 parent 8c1ba48 commit 0c6a4ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package akka.http.javadsl
import java.util.Locale
import java.util.Optional

import akka.annotation.{ DoNotInherit, InternalApi }
import akka.annotation.{DoNotInherit, InternalApi}
import akka.http.javadsl.model.Uri
import akka.http.scaladsl.HttpConnectionContext
import akka.http.scaladsl.UseHttp2.Negotiated

@DoNotInherit
Expand All @@ -23,7 +24,7 @@ abstract class ConnectHttp {
final def effectiveHttpsConnectionContext(fallbackContext: HttpsConnectionContext): HttpsConnectionContext =
connectionContext.orElse(fallbackContext)

final def effectiveConnectionContext(fallbackContext: ConnectionContext): ConnectionContext =
def effectiveConnectionContext(fallbackContext: ConnectionContext): ConnectionContext =
if (connectionContext.isPresent) connectionContext.get()
else fallbackContext

Expand Down Expand Up @@ -167,6 +168,9 @@ final class ConnectHttpImpl(val host: String, val port: Int, val http2: UseHttp2
def isHttps: Boolean = false

def connectionContext: Optional[HttpsConnectionContext] = Optional.empty()

override def effectiveConnectionContext(fallbackContext: ConnectionContext): ConnectionContext =
HttpConnectionContext(http2.asScala)
}

/** INTERNAL API */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import akka.stream.TLSProtocol._
import com.typesafe.sslconfig.akka.AkkaSSLConfig

import scala.collection.JavaConverters._
import java.util.{ Optional, Collection JCollection }
import java.util.{Optional, Collection => JCollection}

import akka.http.scaladsl.UseHttp2.Negotiated
import javax.net.ssl._
Expand Down Expand Up @@ -98,6 +98,7 @@ final class HttpsConnectionContext(
sealed class HttpConnectionContext(http2: UseHttp2) extends akka.http.javadsl.HttpConnectionContext(http2) with ConnectionContext {
def this() = this(Negotiated)
}

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,10 @@ 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)
}

}
}

0 comments on commit 0c6a4ec

Please sign in to comment.