Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

@pjfanning pjfanning Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against this generally. One edge case is a ByteString that has a backing array but a non-zero offset.
We can get a safe InputStream directly from those ByteStreams without compacting them (an InputStream that supports mark/reset). I think in practice such ByteStrings are rare. So if we agree that such ByteStrings are not worrying about then I'm happy enough to go with this change.

decoder.endHeaderBlock() // TODO: do we have to check the result here?

push(eventsOut, ParsedHeadersFrame(streamId, endStream, headers.result(), prioInfo))
Expand All @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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 =
Expand Down
Loading