Skip to content

Commit 8f85850

Browse files
committed
avoid ByteString when parsing HTTP/2 headers
1 parent dd399de commit 8f85850

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import pekko.http.scaladsl.model._
2424
import pekko.http.scaladsl.model.headers.`Tls-Session-Info`
2525
import pekko.http.scaladsl.settings.ServerSettings
2626
import pekko.stream.Attributes
27-
import pekko.util.ByteString
2827
import pekko.util.OptionVal
2928

3029
import scala.annotation.tailrec
@@ -191,13 +190,12 @@ private[http2] object RequestParsing {
191190
}
192191

193192
private[http2] def parseHeaderPair(httpHeaderParser: HttpHeaderParser, name: String, value: String): HttpHeader = {
194-
// FIXME: later modify by adding HttpHeaderParser.parseHttp2Header that would use (name, value) pair directly
195-
// or use a separate, simpler, parser for Http2
196-
// The odd-looking 'x' below is a by-product of how current parser and HTTP/1.1 work.
197-
// Without '\r\n\x' (x being any additional byte) parsing will fail. See HttpHeaderParserSpec for examples.
198-
val concHeaderLine = name + ": " + value + "\r\nx"
199-
httpHeaderParser.parseHeaderLine(ByteString(concHeaderLine))()
200-
httpHeaderParser.resultHeader
193+
import HttpHeader.ParsingResult
194+
HttpHeader.parse(name, value, httpHeaderParser.settings) match {
195+
case ParsingResult.Ok(header, errors) if errors.isEmpty => header
196+
case ParsingResult.Ok(_, errors) => throw ParsingException(errors.head)
197+
case ParsingResult.Error(info) => throw ParsingException(info)
198+
}
201199
}
202200

203201
private[http2] def checkRequiredPseudoHeader(name: String, value: AnyRef): Unit =

0 commit comments

Comments
 (0)