mod_component: Distinguish missing stream @to from unknown local component (thanks Daniel_W)
authorKim Alvefur <zash@zash.se>
Fri, 18 Dec 2020 22:29:44 +0100
changeset 11244 0f7ecc9a4560
parent 11243 06a5919e2496
child 11245 7a4dbc4bb74d
mod_component: Distinguish missing stream @to from unknown local component (thanks Daniel_W) Spectrum2 did not include a stream @to attribute due to a configuration error. "nil does not match ..." is not very clear in pointing this out and is somewhat confusing, tho it did help pinpoint what went wrong. It's also not great leak to programming language internals like "nil" out into user-facing strings like this.
plugins/mod_component.lua
--- a/plugins/mod_component.lua	Wed Dec 16 10:55:04 2020 +0100
+++ b/plugins/mod_component.lua	Fri Dec 18 22:29:44 2020 +0100
@@ -193,6 +193,10 @@
 end
 
 function stream_callbacks.streamopened(session, attr)
+	if not attr.to then
+		session:close{ condition = "improper-addressing", text = "A 'to' attribute is required on stream headers" };
+		return;
+	end
 	if not hosts[attr.to] or not hosts[attr.to].modules.component then
 		session:close{ condition = "host-unknown", text = tostring(attr.to).." does not match any configured external components" };
 		return;