raboof commented on code in PR #744:
URL: https://github.com/apache/pekko-http/pull/744#discussion_r2357863014


##########
http/src/main/java/org/apache/pekko/http/javadsl/settings/OversizedSseStrategy.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.http.javadsl.settings;
+
+/**
+ * Strategy for handling oversized SSE messages that exceed the configured 
max-line-size.
+ *
+ * @since 1.3.0
+ */
+public enum OversizedSseStrategy {
+  /**
+   * Fail the stream with an IllegalStateException when an oversized message 
is encountered. This is
+   * the default behavior to maintain backward compatibility.
+   */
+  FailStream,

Review Comment:
   I think the convention for Java enums is still `FAIL_STREAM`, right? or is 
that outdated? For example compared to 
https://github.com/apache/pekko/blob/main/stream/src/main/java/org/apache/pekko/stream/javadsl/AsPublisher.java
 ?



##########
http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/sse/ServerSentEventParser.scala:
##########
@@ -110,18 +120,57 @@ private final class ServerSentEventParser(
       import shape._
 
       private val builder = new Builder()
+      private lazy val log = Logging(materializer.system, 
classOf[ServerSentEventParser])
+      @volatile private var shouldSkipUntilEventEnd = false
 
       setHandlers(in, out, this)
 
-      override def onPush() = {
+      override def onPush(): Unit = {
         val line = grab(in)
-        if (line == "") { // An event is terminated with a new line
-          if (builder.hasData) // Events without data are ignored according to 
the spec
-            push(out, builder.build())
-          else
-            pull(in)
+        if (shouldSkipUntilEventEnd) { // Max event size was previously 
reached. Skip successive lines until event ends
+          if (line.isEmpty) shouldSkipUntilEventEnd = false // Stop skipping 
when end of event (empty line) is reached
+          pull(in) // Already reported oversized event (below). Drop and 
continue to next line.
+        } else if (maxEventSize > 0 && builder.size + line.length > 
maxEventSize) { // Next line exceeds the size limit
+          shouldSkipUntilEventEnd = true
+          oversizedStrategy match {
+            case OversizedSseStrategy.FailStream =>
+              builder.appendData(line)
+              val event = builder.build()
+              failStage(new IllegalStateException(
+                s"Oversized SSE Event ${event.id.fold("") { id => s"at ID: $id 
" }}" +

Review Comment:
   Can the `id` ever be user-controlled here? Perhaps to be safe it might make 
sense to use a `ExceptionWithErrorInfo` here where the id is in the 'detail' 
rather than the 'summary'.



-- 
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]

Reply via email to