Annotate

mod_s2sout_override/mod_s2sout_override.lua @ 5931:d194d1012fd3

Updating dox for mod_rest. Ideas expressed / clarified: 1) Making clear that mod_rest isn't to be installed under VirtualHosts AND as a component. 2) Understanding some of the implications of this choice: A) Changes to user authentication B) How it affects subdomains 3) More consistent use of domain names for clarity. 4) Using different heading sizes to show scope of section. Essentially, I added all the tidbits I had to clarify in getting this to work in my own example.
author Ben Smith <bens@effortlessis.com>
date Mon, 13 May 2024 13:25:13 -0700
parent 5632:ae62d92506dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5486
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 --% requires: s2sout-pre-connect-event
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local url = require"socket.url";
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local basic_resolver = require "net.resolvers.basic";
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local override_for = module:get_option(module.name, {}); -- map of host to "tcp://example.com:5269"
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 module:hook("s2sout-pre-connect", function(event)
5632
ae62d92506dc mod_s2sout_override: Add support for one-level wildcards (e.g. *.example.net)
Kim Alvefur <zash@zash.se>
parents: 5631
diff changeset
9 local override = override_for[event.session.to_host] or override_for[event.session.to_host:gsub("^[^.]+%.", "*.")] or override_for["*"];
5486
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 if type(override) == "string" then
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 override = url.parse(override);
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 end
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 if type(override) == "table" and override.scheme == "tcp" and type(override.host) == "string" then
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 event.resolver = basic_resolver.new(override.host, tonumber(override.port) or 5269, override.scheme, {});
5487
6cf2f32dbf40 mod_s2sout_override: Add support for Direct TLS
Kim Alvefur <zash@zash.se>
parents: 5486
diff changeset
15 elseif type(override) == "table" and override.scheme == "tls" and type(override.host) == "string" then
6cf2f32dbf40 mod_s2sout_override: Add support for Direct TLS
Kim Alvefur <zash@zash.se>
parents: 5486
diff changeset
16 event.resolver = basic_resolver.new(override.host, tonumber(override.port) or 5270, "tcp",
6cf2f32dbf40 mod_s2sout_override: Add support for Direct TLS
Kim Alvefur <zash@zash.se>
parents: 5486
diff changeset
17 { servername = event.session.to_host; sslctx = event.session.ssl_ctx });
5486
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end
71243bedb2b0 mod_s2sout_override: New module for overriding s2s connections
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end);