This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-http.git


The following commit(s) were added to refs/heads/main by this push:
     new 4638cdd52 chore: fold Http2JDKAlpnSupport into Http2AlpnSupport (#1232)
4638cdd52 is described below

commit 4638cdd5279795669aa45c260e53d29a2fb57070
Author: PJ Fanning <[email protected]>
AuthorDate: Mon Aug 31 09:53:50 2026 +0100

    chore: fold Http2JDKAlpnSupport into Http2AlpnSupport (#1232)
    
    Motivation:
    Http2AlpnSupport was a thin facade in front of Http2JDKAlpnSupport, split 
in two
    purely so that the ALPN classes would load lazily. Its scaladoc still says
    "Will add support to an engine either using jetty alpn or using netty APIs
    (later)" and "We rely on lazy class loading to not fail with class loading
    errors when ALPN support is missing", and Http2.scala had a matching "e.g. 
when
    ALPN jar is missing" comment. All of that dates from Java 8, where ALPN 
needed
    an external jar. This branch requires JDK 17, where ALPN is always 
available.
    
    While reading it I also found that clientSetApplicationProtocols ignored its
    `protocols` parameter and hardcoded Array("h2"). That is invisible today 
because
    the only caller passes exactly Array("h2"), but it is a trap.
    
    Modification:
    Merge the two objects into Http2AlpnSupport, make chooseProtocol private to 
it,
    and correct the scaladoc and the Http2.scala comment. Pass the `protocols`
    argument through to setApplicationProtocols instead of ignoring it. Drop
    applySessionParameters, a one-line delegate to TlsUtils that had no callers.
    
    Both objects are @InternalApi, and removing Http2JDKAlpnSupport is a
    MissingClassProblem, so a mima-filters exclude file is added in the same 
way as
    the existing remove-bytestringinputstream and remove-previewserversettings
    entries do for other removed impl classes.
    
    Result:
    One object instead of two, no misleading documentation, and no silently 
ignored
    parameter. No behaviour change.
    
    Tests:
    - sbt "http2-tests / Test / testOnly ...Http2ClientServerSpec 
...ProtocolSwitchSpec" - 10 passed, 1 ignored. These negotiate h2 over TLS end 
to end, exercising both enableForServer and clientSetApplicationProtocols
    - sbt http-core/mimaReportBinaryIssues - clean with the new filter, and 
reports the two expected MissingClassProblems without it
    - scalafmt --mode diff-ref=upstream/main - clean
    
    References:
    None - found while reviewing the code base against the JDK 17 baseline
---
 .../remove-http2jdkalpnsupport.excludes            | 20 ++++++++++++
 .../pekko/http/impl/engine/http2/Http2.scala       |  3 +-
 .../http/impl/engine/http2/Http2AlpnSupport.scala  | 38 +++++-----------------
 3 files changed, 31 insertions(+), 30 deletions(-)

diff --git 
a/http-core/src/main/mima-filters/2.0.x.backwards.excludes/remove-http2jdkalpnsupport.excludes
 
b/http-core/src/main/mima-filters/2.0.x.backwards.excludes/remove-http2jdkalpnsupport.excludes
new file mode 100644
index 000000000..2b7a2c1c9
--- /dev/null
+++ 
b/http-core/src/main/mima-filters/2.0.x.backwards.excludes/remove-http2jdkalpnsupport.excludes
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+# Merge Http2JDKAlpnSupport into Http2AlpnSupport, both @InternalApi
+ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.http.impl.engine.http2.Http2JDKAlpnSupport")
+ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.http.impl.engine.http2.Http2JDKAlpnSupport$")
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2.scala 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2.scala
index e4d2b3879..74025c4f4 100644
--- 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2.scala
+++ 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2.scala
@@ -249,7 +249,8 @@ private[http] final class Http2Ext(implicit val system: 
ActorSystem)
     def setChosenProtocol(protocol: String): Unit =
       if (chosenProtocol.isEmpty) chosenProtocol = Some(protocol)
       else throw new IllegalStateException("ChosenProtocol was set twice. 
Http2.serverLayer is not reusable.")
-    def getChosenProtocol(): String = 
chosenProtocol.getOrElse(Http2AlpnSupport.HTTP11) // default to http/1, e.g. 
when ALPN jar is missing
+    // default to http/1.1 when the peer did not negotiate a protocol over ALPN
+    def getChosenProtocol(): String = 
chosenProtocol.getOrElse(Http2AlpnSupport.HTTP11)
 
     var eng: Option[SSLEngine] = None
     def createEngine(): SSLEngine = {
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2AlpnSupport.scala
 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2AlpnSupport.scala
index e8cecbfc8..713ce3246 100644
--- 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2AlpnSupport.scala
+++ 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2AlpnSupport.scala
@@ -15,9 +15,6 @@ package org.apache.pekko.http.impl.engine.http2
 
 import org.apache.pekko
 import pekko.annotation.InternalApi
-import pekko.http.impl.engine.http2.Http2AlpnSupport.{ H2, HTTP11 }
-import pekko.stream.TLSProtocol.NegotiateNewSession
-import pekko.stream.impl.io.TlsUtils
 
 import java.{ util => ju }
 import javax.net.ssl.SSLEngine
@@ -25,7 +22,7 @@ import javax.net.ssl.SSLEngine
 /**
  * INTERNAL API
  *
- * Will add support to an engine either using jetty alpn or using netty APIs 
(later).
+ * ALPN support, which every JDK this project builds against provides natively.
  */
 @InternalApi
 private[http] object Http2AlpnSupport {
@@ -36,22 +33,8 @@ private[http] object Http2AlpnSupport {
   /**
    * Enables server-side Http/2 ALPN support for the given engine.
    */
-  def enableForServer(engine: SSLEngine, setChosenProtocol: String => Unit): 
SSLEngine =
-    Http2JDKAlpnSupport.jdkAlpnSupport(engine, setChosenProtocol)
-
-  def clientSetApplicationProtocols(engine: SSLEngine, protocols: 
Array[String]): Unit =
-    Http2JDKAlpnSupport.clientSetApplicationProtocols(engine, protocols)
-}
-
-/**
- * INTERNAL API
- *
- * The actual implementation of ALPN support on supported JDKs. We rely on 
lazy class loading to not fail with class loading errors
- * when ALPN support is missing.
- */
-private[http] object Http2JDKAlpnSupport {
-  def jdkAlpnSupport(engine: SSLEngine, setChosenProtocol: String => Unit): 
SSLEngine = {
-    engine.setHandshakeApplicationProtocolSelector { (engine: SSLEngine, 
protocols: ju.List[String]) =>
+  def enableForServer(engine: SSLEngine, setChosenProtocol: String => Unit): 
SSLEngine = {
+    engine.setHandshakeApplicationProtocolSelector { (_: SSLEngine, protocols: 
ju.List[String]) =>
       val chosen = chooseProtocol(protocols)
       chosen.foreach(setChosenProtocol)
 
@@ -63,17 +46,14 @@ private[http] object Http2JDKAlpnSupport {
     engine
   }
 
-  private def chooseProtocol(protocols: ju.List[String]): Option[String] =
-    if (protocols.contains(H2)) Some(H2)
-    else if (protocols.contains(HTTP11)) Some(HTTP11)
-    else None
-
-  def applySessionParameters(engine: SSLEngine, sessionParameters: 
NegotiateNewSession): Unit =
-    TlsUtils.applySessionParameters(engine, sessionParameters)
-
   def clientSetApplicationProtocols(engine: SSLEngine, protocols: 
Array[String]): Unit = {
     val params = engine.getSSLParameters
-    params.setApplicationProtocols(Array("h2"))
+    params.setApplicationProtocols(protocols)
     engine.setSSLParameters(params)
   }
+
+  private def chooseProtocol(protocols: ju.List[String]): Option[String] =
+    if (protocols.contains(H2)) Some(H2)
+    else if (protocols.contains(HTTP11)) Some(HTTP11)
+    else None
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to