pjfanning commented on code in PR #940:
URL: https://github.com/apache/pekko-http/pull/940#discussion_r2740535696


##########
http-cors/src/main/scala/org/apache/pekko/http/cors/scaladsl/model/HttpHeaderRange.scala:
##########
@@ -23,16 +23,30 @@ import org.apache.pekko
 import pekko.http.cors.javadsl
 import pekko.util.Helpers
 
-abstract class HttpHeaderRange extends javadsl.model.HttpHeaderRange
+sealed abstract class HttpHeaderRange extends javadsl.model.HttpHeaderRange {
+  override def concat(range: javadsl.model.HttpHeaderRange): HttpHeaderRange
+
+  def ++(range: javadsl.model.HttpHeaderRange): HttpHeaderRange = concat(range)
+}
 
 object HttpHeaderRange {
   case object `*` extends HttpHeaderRange {
     def matches(header: String) = true
+
+    override def concat(range: javadsl.model.HttpHeaderRange): HttpHeaderRange 
= this
   }
 
   final case class Default(headers: Seq[String]) extends HttpHeaderRange {
     private val lowercaseHeaders: Seq[String] = 
headers.map(Helpers.toRootLowerCase)
     def matches(header: String): Boolean = 
lowercaseHeaders.contains(Helpers.toRootLowerCase(header))
+
+    override def concat(range: javadsl.model.HttpHeaderRange): HttpHeaderRange 
= {
+      range match {
+        case `*`              => `*`
+        case Default(headers) => Default(this.headers ++ headers)
+        case _                => throw new 
IllegalArgumentException(s"Unexpected header range implementation type 
${range.getClass}")

Review Comment:
   Can the error message be more like `s"Concat is not supported for unexpected 
header range implementation type ${range.getClass}"`



##########
http-cors/src/main/scala/org/apache/pekko/http/cors/scaladsl/model/HttpHeaderRange.scala:
##########
@@ -23,16 +23,30 @@ import org.apache.pekko
 import pekko.http.cors.javadsl
 import pekko.util.Helpers
 
-abstract class HttpHeaderRange extends javadsl.model.HttpHeaderRange
+sealed abstract class HttpHeaderRange extends javadsl.model.HttpHeaderRange {
+  override def concat(range: javadsl.model.HttpHeaderRange): HttpHeaderRange
+
+  def ++(range: javadsl.model.HttpHeaderRange): HttpHeaderRange = concat(range)
+}
 
 object HttpHeaderRange {
   case object `*` extends HttpHeaderRange {
     def matches(header: String) = true
+
+    override def concat(range: javadsl.model.HttpHeaderRange): HttpHeaderRange 
= this
   }
 
   final case class Default(headers: Seq[String]) extends HttpHeaderRange {
     private val lowercaseHeaders: Seq[String] = 
headers.map(Helpers.toRootLowerCase)
     def matches(header: String): Boolean = 
lowercaseHeaders.contains(Helpers.toRootLowerCase(header))
+
+    override def concat(range: javadsl.model.HttpHeaderRange): HttpHeaderRange 
= {
+      range match {
+        case `*`              => `*`
+        case Default(headers) => Default(this.headers ++ headers)
+        case _                => throw new 
IllegalArgumentException(s"Unexpected header range implementation type 
${range.getClass}")

Review Comment:
   Can the error message be more like `s"Concat is not supported for unexpected 
header range implementation type ${range.getClass}"`?



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