mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:44:35 +03:00
add option to handle autoconfig and mta-sts requests without TLS, for when it is reverse proxied
for #5 with hints from belst & idnovic
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@ -18,9 +19,14 @@ func mtastsPolicyHandle(w http.ResponseWriter, r *http.Request) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
domain, err := dns.ParseDomain(strings.TrimPrefix(r.Host, "mta-sts."))
|
||||
host, _, err := net.SplitHostPort(strings.TrimPrefix(r.Host, "mta-sts."))
|
||||
if err != nil {
|
||||
log.Errorx("mtasts policy request: bad domain", err, mlog.Field("host", r.Host))
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
domain, err := dns.ParseDomain(host)
|
||||
if err != nil {
|
||||
log.Errorx("mtasts policy request: bad domain", err, mlog.Field("host", host))
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
@ -110,12 +110,12 @@ func ListenAndServe() {
|
||||
}))
|
||||
}
|
||||
if l.AutoconfigHTTPS.Enabled {
|
||||
srv := ensureServe(true, config.Port(l.AutoconfigHTTPS.Port, 443), "autoconfig-https")
|
||||
srv := ensureServe(!l.AutoconfigHTTPS.NonTLS, config.Port(l.AutoconfigHTTPS.Port, 443), "autoconfig-https")
|
||||
srv.mux.HandleFunc("/mail/config-v1.1.xml", safeHeaders(autoconfHandle(l)))
|
||||
srv.mux.HandleFunc("/autodiscover/autodiscover.xml", safeHeaders(autodiscoverHandle(l)))
|
||||
}
|
||||
if l.MTASTSHTTPS.Enabled {
|
||||
srv := ensureServe(true, config.Port(l.MTASTSHTTPS.Port, 443), "mtasts-https")
|
||||
srv := ensureServe(!l.AutoconfigHTTPS.NonTLS, config.Port(l.MTASTSHTTPS.Port, 443), "mtasts-https")
|
||||
srv.mux.HandleFunc("/.well-known/mta-sts.txt", safeHeaders(mtastsPolicyHandle))
|
||||
}
|
||||
if l.PprofHTTP.Enabled {
|
||||
|
Reference in New Issue
Block a user