diff --git a/core/src/main/scala/sttp/model/headers/Forwarded.scala b/core/src/main/scala/sttp/model/headers/Forwarded.scala index 5d31bca..2f19b65 100644 --- a/core/src/main/scala/sttp/model/headers/Forwarded.scala +++ b/core/src/main/scala/sttp/model/headers/Forwarded.scala @@ -30,6 +30,9 @@ object Forwarded { /** Parses a single Forwarded header, which can contain multiple Forwarded values. */ def parse(headerValue: String): Either[String, List[Forwarded]] = { + def removeApostrophes(v: String): String = + if (v.startsWith("\"") && v.endsWith("\"")) v.substring(1, v.length - 1) else v + def parseSingle(headerValue: String): Either[String, Forwarded] = { val parts = headerValue.split(";").map(_.trim).toList val kvPairs = parts.map { part => @@ -41,9 +44,9 @@ object Forwarded { val pairs = kvPairs.collect { case Right(pair) => pair } if (pairs.size == kvPairs.size) { - val by = pairs.collectFirst { case ("by", v) => v } - val `for` = pairs.collectFirst { case ("for", v) => v } - val host = pairs.collectFirst { case ("host", v) => v } + val by = pairs.collectFirst { case ("by", v) => v }.map(removeApostrophes) + val `for` = pairs.collectFirst { case ("for", v) => v }.map(removeApostrophes) + val host = pairs.collectFirst { case ("host", v) => v }.map(removeApostrophes) val proto = pairs.collectFirst { case ("proto", v) => v } Right(Forwarded(by, `for`, host, proto)) } else diff --git a/core/src/test/scala/sttp/model/headers/ForwardedTest.scala b/core/src/test/scala/sttp/model/headers/ForwardedTest.scala index 04df0eb..1d03032 100644 --- a/core/src/test/scala/sttp/model/headers/ForwardedTest.scala +++ b/core/src/test/scala/sttp/model/headers/ForwardedTest.scala @@ -64,9 +64,9 @@ class ForwardedTest extends AnyFlatSpec with Matchers { actual shouldBe "by=1.2.3.4,by=4.3.2.1" } - it should "parse ipv6 addresses in For" in { + it should "parse ipv6 addresses in 'for', removing the apostrophes" in { val actual = Forwarded.parse("""For="[2001:db8:cafe::17]:4711"""") - actual shouldBe Right(List(Forwarded(None, Some("\"[2001:db8:cafe::17]:4711\""), None, None))) + actual shouldBe Right(List(Forwarded(None, Some("[2001:db8:cafe::17]:4711"), None, None))) } it should "parse multiple ipv4 addresses" in {