Software /
code /
prosody-modules
Comparison
mod_strict_https/mod_strict_https.lua @ 5415:f8797e3284ff
mod_strict_https: Add way to disable redirect
Since Prosody 0.12+ does not listen on unencrypted http anymore, this is
likely to cause trouble. Especially since the URL construction is
problematic and awkward.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 03 May 2023 10:55:22 +0200 |
parent | 5411:b3158647cb36 |
comparison
equal
deleted
inserted
replaced
5414:0c8e6269ea38 | 5415:f8797e3284ff |
---|---|
4 module:set_global(); | 4 module:set_global(); |
5 | 5 |
6 local http_server = require "net.http.server"; | 6 local http_server = require "net.http.server"; |
7 | 7 |
8 local hsts_header = module:get_option_string("hsts_header", "max-age=31556952"); -- This means "Don't even try to access without HTTPS for a year" | 8 local hsts_header = module:get_option_string("hsts_header", "max-age=31556952"); -- This means "Don't even try to access without HTTPS for a year" |
9 local redirect = module:get_option_boolean("hsts_redirect", true); | |
9 | 10 |
10 module:wrap_object_event(http_server._events, false, function(handlers, event_name, event_data) | 11 module:wrap_object_event(http_server._events, false, function(handlers, event_name, event_data) |
11 local request, response = event_data.request, event_data.response; | 12 local request, response = event_data.request, event_data.response; |
12 if request and response then | 13 if request and response then |
13 if request.secure then | 14 if request.secure then |
14 response.headers.strict_transport_security = hsts_header; | 15 response.headers.strict_transport_security = hsts_header; |
15 else | 16 elseif redirect then |
16 -- This won't get the port number right | 17 -- This won't get the port number right |
17 response.headers.location = "https://" .. request.host .. request.path .. (request.query and "?" .. request.query or ""); | 18 response.headers.location = "https://" .. request.host .. request.path .. (request.query and "?" .. request.query or ""); |
18 return 301; | 19 return 301; |
19 end | 20 end |
20 end | 21 end |