He-Pin commented on code in PR #744:
URL: https://github.com/apache/pekko-http/pull/744#discussion_r2357575435
##########
http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/LineParser.scala:
##########
@@ -43,44 +55,86 @@ private final class LineParser(maxLineSize: Int) extends
GraphStage[FlowShape[By
private var buffer = ByteString.empty
private var lastCharWasCr = false
+ private lazy val log = Logging(materializer.system, classOf[LineParser])
setHandlers(in, out, this)
override def onPush() = {
+ def handleLineOversized(lineLength: Int, line: String): Option[String]
= {
+ oversizedStrategy match {
+ case OversizedSseStrategy.FailStream =>
+ failStage(new IllegalStateException(
+ s"SSE line size: $lineLength exceeds max-line-size:
$maxLineSize. " +
+ s"Configure pekko.http.sse.max-line-size or use
oversized-message-handling setting."))
+ None
+ case OversizedSseStrategy.LogAndSkip =>
+ log.warning("Skipping oversized SSE message: {} bytes > {}
max-line-size", lineLength, maxLineSize)
+ None
+ case OversizedSseStrategy.Truncate =>
+ log.info("Truncating oversized SSE message: {} bytes > {}
max-line-size", lineLength, maxLineSize)
+ Some(line.take(maxLineSize))
+ case OversizedSseStrategy.DeadLetter =>
+ materializer.system.deadLetters ! OversizedSseLine(line)
+ None
+ }
+ }
+
@tailrec
def parseLines(
bs: ByteString,
from: Int = 0,
at: Int,
parsedLines: Vector[String] = Vector.empty,
- lastCharWasCr: Boolean = false): (ByteString, Vector[String],
Boolean) =
+ lastCharWasCr: Boolean): (ByteString, Vector[String], Boolean) =
if (at >= bs.length)
(bs.drop(from), parsedLines, lastCharWasCr)
else
bs(at) match {
case CR if at < bs.length - 1 && bs(at + 1) == LF =>
// Lookahead for LF after CR
- parseLines(bs, at + 2, at + 2, parsedLines :+ bs.slice(from,
at).utf8String)
+ val lineLength = at - from
Review Comment:
I think the `lineSize` should be changed to `lineByteSize` in the setting,
because some Char will use two bytes but just count as one char.
Here, the code seems like count the bytes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]