Skip to content

Commit 6b5b7ed

Browse files
chbateyjrudolph
authored andcommitted
Preserve http2 option when doing from javadsl to scaladsl
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.
1 parent 8c4a47d commit 6b5b7ed

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

akka-http-core/src/main/scala/akka/http/javadsl/ConnectHttp.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.util.Optional
99

1010
import akka.annotation.{ DoNotInherit, InternalApi }
1111
import akka.http.javadsl.model.Uri
12+
import akka.http.scaladsl.HttpConnectionContext
1213
import akka.http.scaladsl.UseHttp2.Negotiated
1314

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

26-
final def effectiveConnectionContext(fallbackContext: ConnectionContext): ConnectionContext =
27+
def effectiveConnectionContext(fallbackContext: ConnectionContext): ConnectionContext =
2728
if (connectionContext.isPresent) connectionContext.get()
2829
else fallbackContext
2930

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

169170
def connectionContext: Optional[HttpsConnectionContext] = Optional.empty()
171+
172+
override def effectiveConnectionContext(fallbackContext: ConnectionContext): ConnectionContext =
173+
HttpConnectionContext(http2.asScala)
170174
}
171175

172176
/** INTERNAL API */

akka-http-core/src/main/scala/akka/http/scaladsl/ConnectionContext.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ final class HttpsConnectionContext(
9898
sealed class HttpConnectionContext(http2: UseHttp2) extends akka.http.javadsl.HttpConnectionContext(http2) with ConnectionContext {
9999
def this() = this(Negotiated)
100100
}
101+
101102
final object HttpConnectionContext extends HttpConnectionContext(Negotiated) {
102103
/** Java API */
103104
def getInstance() = this

akka-http-core/src/test/scala/akka/http/javadsl/ConnectHttpSpec.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,10 @@ class ConnectHttpSpec extends WordSpec with Matchers with BeforeAndAfterAll {
9999
}
100100
ex.getMessage should include("non https scheme!")
101101
}
102+
"connect toHost HTTP/2 only" in {
103+
val connect = ConnectHttp.toHost("http://127.0.0.1", 8080, UseHttp2.always)
104+
connect.effectiveConnectionContext(httpsContext).http2 should equal(UseHttp2.always)
105+
}
106+
102107
}
103108
}

0 commit comments

Comments
 (0)