aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-06-03 16:15:52 +0200
committerKim Alvefur <zash@zash.se>2023-06-03 16:15:52 +0200
commit99906e5b9c212beaf6cbc21580d67a5806fa4f24 (patch)
tree17f8ef39c3d86523c5fb0d3e28a10e87ff0df706 /spec
parent517f20b5230586df9baee3afb47982a54478d074 (diff)
downloadprosody-99906e5b9c212beaf6cbc21580d67a5806fa4f24.tar.gz
prosody-99906e5b9c212beaf6cbc21580d67a5806fa4f24.zip
util.http: Implement parser for RFC 7239 Forwarded header
Standardized and structured replacement for the X-Forwarded-For, X-Forwarded-Proto set of headers. Notably, this allows per-hop protocol information, unlike X-Forwarded-Proto which is always a single value for some reason.
Diffstat (limited to 'spec')
-rw-r--r--spec/util_http_spec.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/util_http_spec.lua b/spec/util_http_spec.lua
index c6087450..62679f0f 100644
--- a/spec/util_http_spec.lua
+++ b/spec/util_http_spec.lua
@@ -108,4 +108,25 @@ describe("util.http", function()
assert.is_(http.contains_token("fo o", "foo"));
end);
end);
+
+do
+ describe("parse_forwarded", function()
+ it("works", function()
+ assert.same({ { ["for"] = "[2001:db8:cafe::17]:4711" } }, http.parse_forwarded('For="[2001:db8:cafe::17]:4711"'), "case insensitive");
+
+ assert.same({ { ["for"] = "192.0.2.60"; proto = "http"; by = "203.0.113.43" } }, http.parse_forwarded('for=192.0.2.60;proto=http;by=203.0.113.43'),
+ "separated by semicolon");
+
+ assert.same({ { ["for"] = "192.0.2.43" }; { ["for"] = "198.51.100.17" } }, http.parse_forwarded('for=192.0.2.43, for=198.51.100.17'),
+ "Values from multiple proxy servers can be appended using a comma");
+
+ end)
+ it("rejects quoted quotes", function ()
+ assert.falsy(http.parse_forwarded('foo="bar\"bar'), "quoted quotes");
+ end)
+ pending("deals with quoted quotes", function ()
+ assert.same({ { foo = 'bar"baz' } }, http.parse_forwarded('foo="bar\"bar'), "quoted quotes");
+ end)
+ end)
+end
end);