diff --git a/zio-http/jvm/src/test/scala/zio/http/headers/ForwardedSpec.scala b/zio-http/jvm/src/test/scala/zio/http/headers/ForwardedSpec.scala index b51397dbff..61726d5459 100644 --- a/zio-http/jvm/src/test/scala/zio/http/headers/ForwardedSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/headers/ForwardedSpec.scala @@ -72,7 +72,7 @@ object ForwardedSpec extends ZIOHttpSpec { val expected = Header.Forwarded(by = by, forValues = forv, host = host, proto = proto) val raw = Header.Forwarded.render(expected) val actual = Header.Forwarded.parse(raw) - assertTrue(actual.is(_.right) == expected) + assertTrue(actual.is(_.right) == expected).label(s"Rendering result > '${raw}'") } } @@ TestAspect.shrinks(0), ) diff --git a/zio-http/shared/src/main/scala/zio/http/Header.scala b/zio-http/shared/src/main/scala/zio/http/Header.scala index 4e2cdf01a9..48a87bb8ad 100644 --- a/zio-http/shared/src/main/scala/zio/http/Header.scala +++ b/zio-http/shared/src/main/scala/zio/http/Header.scala @@ -2857,11 +2857,12 @@ object Header { } def render(forwarded: Forwarded): String = { - def formatDirective(directive: Option[String]) = directive.map(_ + ";").getOrElse("") + def formatDirective(directiveName: String, directiveValue: Option[String]) = + directiveValue.map(v => s"${directiveName}=${v};").getOrElse("") - val forValues = if (forwarded.forValues.nonEmpty) forwarded.forValues.map(v => s"for=$v").mkString(",") + ";" else "" + val forValues = if (forwarded.forValues.nonEmpty) forwarded.forValues.mkString("for=", ",for=", ";") else "" - s"${formatDirective(forwarded.by.map("by=" + _))}${forValues}${formatDirective(forwarded.host.map("host=" + _))}${formatDirective(forwarded.proto.map("proto=" + _))}" + s"${formatDirective("by", forwarded.by)}${forValues}${formatDirective("host", forwarded.host)}${formatDirective("proto", forwarded.proto)}" } }