Skip to content

Conversation

@jrudolph
Copy link
Contributor

Also remove useless nesting / finally blocks, arrays do not need closing.

Fixes #553

Simpler variant of #820. WDYT, @pjfanning ?

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.

Copy link
Member

@pjfanning pjfanning left a comment

Choose a reason for hiding this comment

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

lgtm - I will merge if there are no objections

@pjfanning pjfanning added this to the 2.0.0 milestone Dec 10, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR simplifies the HTTP/2 HPACK header decompression code by removing a single-use utility class ByteStringInputStream and replacing its usage with the direct ByteString API method compact.asInputStream. The PR also removes unnecessary try/finally blocks around InputStream usage since array-backed InputStreams don't hold system resources that need explicit cleanup.

  • Removes the custom ByteStringInputStream utility class (36 lines)
  • Replaces ByteStringInputStream(bytes) calls with bytes.compact.asInputStream
  • Removes unnecessary try/finally blocks and nesting around decoder calls

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala Deleted utility class that wrapped ByteString as InputStream - functionality replaced by built-in ByteString API
http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/HeaderDecompression.scala Updated to use payload.compact.asInputStream directly, removed unnecessary try/finally block, added clarifying comment about mark/reset support
http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala Updated to use bytes.compact.asInputStream directly, removed unnecessary try/finally block and import statement

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pjfanning pjfanning force-pushed the remove-ByteStringInputStream branch from 5da1cf9 to 096c231 Compare December 10, 2025 21:28
@pjfanning pjfanning merged commit 5205d5e into apache:main Dec 12, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Twitter Decoder cannot handle all InputStream implementations

3 participants