Skip to content

Commit 5205d5e

Browse files
jrudolphpjfanning
andauthored
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 <pjfanning@users.noreply.github.com>
1 parent 389416e commit 5205d5e

File tree

4 files changed

+30
-50
lines changed

4 files changed

+30
-50
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# Remove ByteStringInputStream
19+
ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.http.impl.engine.http2.hpack.ByteStringInputStream")
20+
ProblemFilters.exclude[MissingClassProblem]("org.apache.pekko.http.impl.engine.http2.hpack.ByteStringInputStream$")

http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/ByteStringInputStream.scala

Lines changed: 0 additions & 36 deletions
This file was deleted.

http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/hpack/HeaderDecompression.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ private[http2] final class HeaderDecompression(masterHeaderParser: HttpHeaderPar
9292
}
9393
}
9494
}
95-
val bis = ByteStringInputStream(payload)
95+
val stream = payload.compact.asInputStream
9696
try {
97-
decoder.decode(bis, Receiver)
97+
decoder.decode(stream, Receiver) // only compact ByteString supports InputStream with mark/reset
9898
decoder.endHeaderBlock() // TODO: do we have to check the result here?
9999

100100
push(eventsOut, ParsedHeadersFrame(streamId, endStream, headers.result(), prioInfo))
@@ -104,7 +104,7 @@ private[http2] final class HeaderDecompression(masterHeaderParser: HttpHeaderPar
104104
fail(eventsOut,
105105
new Http2Compliance.Http2ProtocolException(ErrorCode.COMPRESSION_ERROR, "Decompression failed."))
106106
} finally {
107-
bis.close()
107+
stream.close()
108108
}
109109
}
110110

http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2FrameHpackSupport.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package org.apache.pekko.http.impl.engine.http2
1616
import scala.collection.immutable.VectorBuilder
1717

1818
import org.apache.pekko
19-
import pekko.http.impl.engine.http2.hpack.ByteStringInputStream
2019
import pekko.http.scaladsl.model._
2120
import pekko.http.scaladsl.model.headers.RawHeader
2221
import pekko.http.shaded.com.twitter.hpack._
@@ -60,16 +59,13 @@ trait Http2FrameHpackSupport extends Http2FrameProbeDelegator with Http2FrameSen
6059

6160
def decodeHeaders(bytes: ByteString): Seq[(String, String)] = {
6261
val hs = new VectorBuilder[(String, String)]()
63-
val bis = ByteStringInputStream(bytes)
64-
try
65-
decoder.decode(bis,
66-
new HeaderListener {
67-
def addHeader(name: String, value: String, parsedValue: AnyRef, sensitive: Boolean): AnyRef = {
68-
hs += name -> value
69-
parsedValue
70-
}
71-
})
72-
finally bis.close()
62+
decoder.decode(bytes.compact.asInputStream,
63+
new HeaderListener {
64+
def addHeader(name: String, value: String, parsedValue: AnyRef, sensitive: Boolean): AnyRef = {
65+
hs += name -> value
66+
parsedValue
67+
}
68+
})
7369
hs.result()
7470
}
7571
def decodeHeadersToResponse(bytes: ByteString): HttpResponse =

0 commit comments

Comments
 (0)