This is an automated email from the ASF dual-hosted git repository.
fanningpj 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 5205d5e79 http2: remove single use ByteStringInputStream (#833)
5205d5e79 is described below
commit 5205d5e79d0dee79e0f835c041e20b793ecf9eba
Author: Johannes Rudolph <[email protected]>
AuthorDate: Fri Dec 12 10:57:59 2025 +0100
http2: remove single use ByteStringInputStream (#833)
* http2: remove single use ByteStringInputStream
Also remove useless nesting / finally blocks, arrays do not need closing.
Fixes #553
* Remove unused import for ByteStringInputStream
* Create remove-bytestringinputstream.excludes
* Update HeaderDecompression.scala
---------
Co-authored-by: PJ Fanning <[email protected]>
---
.../remove-bytestringinputstream.excludes | 20 ++++++++++++
.../engine/http2/hpack/ByteStringInputStream.scala | 36 ----------------------
.../engine/http2/hpack/HeaderDecompression.scala | 6 ++--
.../impl/engine/http2/Http2FrameHpackSupport.scala | 18 +++++------
4 files changed, 30 insertions(+), 50 deletions(-)
diff --git
a/http-core/src/main/mima-filters/2.0.x.backwards.excludes/remove-bytestringinputstream.excludes
b/http-core/src/main/mima-filters/2.0.x.backwards.excludes/remove-bytestringinputstream.excludes
new file mode 100644
index 000000000..d19a8bccc
--- /dev/null
+++
b/http-core/src/main/mima-filters/2.0.x.backwards.excludes/remove-bytestringinputstream.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.
+
+# Remove ByteStringInputStream
+ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.http.impl.engine.http2.hpack.ByteStringInputStream")
+ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.http.impl.engine.http2.hpack.ByteStringInputStream$")
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala
deleted file mode 100644
index f3b3dc5a3..000000000
---
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * license agreements; and to You under the Apache License, version 2.0:
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * This file is part of the Apache Pekko project, which was derived from Akka.
- */
-
-/*
- * Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
- */
-
-package org.apache.pekko.http.impl.engine.http2.hpack
-
-import java.io.{ ByteArrayInputStream, InputStream }
-
-import org.apache.pekko
-import pekko.annotation.InternalApi
-import pekko.util.ByteString
-import pekko.util.ByteString.ByteString1C
-
-/** INTERNAL API */
-@InternalApi
-private[http2] object ByteStringInputStream {
-
- def apply(bs: ByteString): InputStream =
- bs match {
- case cs: ByteString1C =>
- // TODO optimise, ByteString needs to expose InputStream (esp if array
backed, nice!)
- new ByteArrayInputStream(cs.toArrayUnsafe())
- case _ =>
- // NOTE: We actually measured recently, and compact + use array was
pretty good usually
- apply(bs.compact)
- }
-}
diff --git
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/HeaderDecompression.scala
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/HeaderDecompression.scala
index b496090f0..6ed39670a 100644
---
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/HeaderDecompression.scala
+++
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/HeaderDecompression.scala
@@ -92,9 +92,9 @@ private[http2] final class
HeaderDecompression(masterHeaderParser: HttpHeaderPar
}
}
}
- val bis = ByteStringInputStream(payload)
+ val stream = payload.compact.asInputStream
try {
- decoder.decode(bis, Receiver)
+ decoder.decode(stream, Receiver) // only compact ByteString supports
InputStream with mark/reset
decoder.endHeaderBlock() // TODO: do we have to check the result
here?
push(eventsOut, ParsedHeadersFrame(streamId, endStream,
headers.result(), prioInfo))
@@ -104,7 +104,7 @@ private[http2] final class
HeaderDecompression(masterHeaderParser: HttpHeaderPar
fail(eventsOut,
new
Http2Compliance.Http2ProtocolException(ErrorCode.COMPRESSION_ERROR,
"Decompression failed."))
} finally {
- bis.close()
+ stream.close()
}
}
diff --git
a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala
b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala
index 4099d5649..5bb6e0d2b 100644
---
a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala
+++
b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala
@@ -16,7 +16,6 @@ package org.apache.pekko.http.impl.engine.http2
import scala.collection.immutable.VectorBuilder
import org.apache.pekko
-import pekko.http.impl.engine.http2.hpack.ByteStringInputStream
import pekko.http.scaladsl.model._
import pekko.http.scaladsl.model.headers.RawHeader
import pekko.http.shaded.com.twitter.hpack._
@@ -60,16 +59,13 @@ trait Http2FrameHpackSupport extends
Http2FrameProbeDelegator with Http2FrameSen
def decodeHeaders(bytes: ByteString): Seq[(String, String)] = {
val hs = new VectorBuilder[(String, String)]()
- val bis = ByteStringInputStream(bytes)
- try
- decoder.decode(bis,
- new HeaderListener {
- def addHeader(name: String, value: String, parsedValue: AnyRef,
sensitive: Boolean): AnyRef = {
- hs += name -> value
- parsedValue
- }
- })
- finally bis.close()
+ decoder.decode(bytes.compact.asInputStream,
+ new HeaderListener {
+ def addHeader(name: String, value: String, parsedValue: AnyRef,
sensitive: Boolean): AnyRef = {
+ hs += name -> value
+ parsedValue
+ }
+ })
hs.result()
}
def decodeHeadersToResponse(bytes: ByteString): HttpResponse =
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]