diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/HeaderParser.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/HeaderParser.scala index 6b7bd7029..68ae18e63 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/HeaderParser.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/HeaderParser.scala @@ -86,8 +86,9 @@ private[http] class HeaderParser( def failure(error: Throwable): HeaderParser.Failure = HeaderParser.Failure { error match { - case IllegalUriException(info) => info - case NonFatal(e) => ErrorInfo.fromCompoundString(e.getMessage) + case IllegalUriException(info) => info + case NonFatal(e) if e.getMessage == null => ErrorInfo.fromCompoundString(e.toString) + case NonFatal(e) => ErrorInfo.fromCompoundString(e.getMessage) } } def ruleNotFound(ruleName: String): Result = HeaderParser.RuleNotFound diff --git a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala index 6597d5b39..2435f11ae 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpHeader.scala @@ -99,11 +99,10 @@ object HttpHeader { case HeaderParser.RuleNotFound => ParsingResult.Ok(RawHeader(name, preProcessedValue), Nil) } case Failure(error) => - val info = error match { - case e: ParseError => parser.parseError(e).info - case e if e.getMessage == null => ErrorInfo() - case e => parser.failure(e).info - } + val info = (error match { + case e: ParseError => parser.parseError(e) + case e => parser.failure(e) + }).info ParsingResult.Error(info.withSummaryPrepended(s"Illegal HTTP header value")) } } else ParsingResult.Error(ErrorInfo(s"Illegal HTTP header name", name)) diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/model/parser/HttpHeaderSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/model/parser/HttpHeaderSpec.scala index 9d2f35a7d..b317648b4 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/model/parser/HttpHeaderSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/model/parser/HttpHeaderSpec.scala @@ -878,7 +878,9 @@ class HttpHeaderSpec extends AnyFreeSpec with Matchers { } "should not broken when header-value is null" in { - parse("Content-Disposition", null).errors.head.isInstanceOf[ErrorInfo] shouldBe true + val errors = parse("Content-Disposition", null).errors + errors.size shouldBe 1 + errors.head shouldBe an[ErrorInfo] } }