@@ -10,6 +10,11 @@ class ForwardedTest extends AnyFlatSpec with Matchers {
10
10
actual shouldBe Right (List (Forwarded (Some (" 1.2.3.4" ), Some (" 4.3.2.1" ), Some (" example.com" ), Some (" http" ))))
11
11
}
12
12
13
+ it should " parse a single header correctly, regardless of case of the directives" in {
14
+ val actual = Forwarded .parse(" By=1.2.3.4;For=4.3.2.1;Host=example.com;Proto=http" )
15
+ actual shouldBe Right (List (Forwarded (Some (" 1.2.3.4" ), Some (" 4.3.2.1" ), Some (" example.com" ), Some (" http" ))))
16
+ }
17
+
13
18
it should " parse multiple headers correctly, when given as separate headers" in {
14
19
val actual = Forwarded .parse(List (" by=1.2.3.4;for=4.3.2.1" , " host=example.com;proto=https" ))
15
20
actual shouldBe Right (
@@ -44,4 +49,33 @@ class ForwardedTest extends AnyFlatSpec with Matchers {
44
49
val actual = Forwarded .parse(" by=1.2.3.4;for" )
45
50
actual shouldBe Left (" Invalid part: for" )
46
51
}
52
+
53
+ it should " serialize the header to a string" in {
54
+ val actual =
55
+ Forwarded .toString(List (Forwarded (Some (" 1.2.3.4" ), Some (" 4.3.2.1" ), Some (" example.com" ), Some (" http" ))))
56
+ actual shouldBe " by=1.2.3.4;for=4.3.2.1;host=example.com;proto=http"
57
+ }
58
+
59
+ it should " serialize multiple headers to a string" in {
60
+ val actual =
61
+ Forwarded .toString(
62
+ List (Forwarded (Some (" 1.2.3.4" ), None , None , None ), Forwarded (Some (" 4.3.2.1" ), None , None , None ))
63
+ )
64
+ actual shouldBe " by=1.2.3.4,by=4.3.2.1"
65
+ }
66
+
67
+ it should " parse ipv6 addresses in For" in {
68
+ val actual = Forwarded .parse(""" For="[2001:db8:cafe::17]:4711"""" )
69
+ actual shouldBe Right (List (Forwarded (None , Some (" \" [2001:db8:cafe::17]:4711\" " ), None , None )))
70
+ }
71
+
72
+ it should " parse multiple ipv4 addresses" in {
73
+ val actual = Forwarded .parse(" for=192.0.2.43, for=198.51.100.17" )
74
+ actual shouldBe Right (
75
+ List (
76
+ Forwarded (None , Some (" 192.0.2.43" ), None , None ),
77
+ Forwarded (None , Some (" 198.51.100.17" ), None , None )
78
+ )
79
+ )
80
+ }
47
81
}
0 commit comments