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. - */ - -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..0b3d7c344 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,8 @@ private[http2] final class HeaderDecompression(masterHeaderParser: HttpHeaderPar } } } - val bis = ByteStringInputStream(payload) try { - decoder.decode(bis, Receiver) + decoder.decode(payload.compact.asInputStream, 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)) @@ -103,8 +102,6 @@ private[http2] final class HeaderDecompression(masterHeaderParser: HttpHeaderPar // this is signalled by the decoder when it failed, we want to react to this by rendering a GOAWAY frame fail(eventsOut, new Http2Compliance.Http2ProtocolException(ErrorCode.COMPRESSION_ERROR, "Decompression failed.")) - } finally { - bis.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 =