From ed65eee130d61f674cdf0aa88edf0cc7f805d1f1 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 3 Oct 2025 14:29:05 +0100 Subject: [PATCH] use ByteString.asInputStream --- .../http2/hpack/ByteStringInputStream.scala | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) 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 index f3b3dc5a3..bcb2c45b5 100644 --- 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 @@ -13,24 +13,21 @@ package org.apache.pekko.http.impl.engine.http2.hpack -import java.io.{ ByteArrayInputStream, InputStream } +import java.io.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) - } + def apply(bs: ByteString): InputStream = bs match { + case bss: ByteString.ByteStrings => + // bss.asInputStream would create a SequenceInputStream which does not support mark/reset + bss.compact.asInputStream + case _ => + // returns a ByteArrayInputStream (twitter hpack needs mark/reset support) + bs.asInputStream + } }