Skip to content

Commit

Permalink
Issue 3165: Additional PR tasks (#3179)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottweaver authored Sep 27, 2024
1 parent 44b2a1c commit 15bcccc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
7 changes: 4 additions & 3 deletions zio-http/shared/src/main/scala/zio/http/Header.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
}
}

Expand Down

0 comments on commit 15bcccc

Please sign in to comment.