@@ -24,17 +24,31 @@ import (
2424 "strings"
2525)
2626
27- // AddSNIRoute appends a route to the ipPort listener that says if the
28- // incoming TLS SNI server name is sni, the connection is given to
29- // dest. If it doesn't match, rule processing continues for any
30- // additional routes on ipPort.
27+ // AddSNIRoute appends a route to the ipPort listener that routes to
28+ // dest if the incoming TLS SNI server name is sni. If it doesn't
29+ // match, rule processing continues for any additional routes on
30+ // ipPort.
3131//
3232// By default, the proxy will route all ACME tls-sni-01 challenges
3333// received on ipPort to all SNI dests. You can disable ACME routing
3434// with AddStopACMESearch.
3535//
3636// The ipPort is any valid net.Listen TCP address.
3737func (p * Proxy ) AddSNIRoute (ipPort , sni string , dest Target ) {
38+ p .AddSNIMatchRoute (ipPort , equals (sni ), dest )
39+ }
40+
41+ // AddSNIMatchRoute appends a route to the ipPort listener that routes
42+ // to dest if the incoming TLS SNI server name is accepted by
43+ // matcher. If it doesn't match, rule processing continues for any
44+ // additional routes on ipPort.
45+ //
46+ // By default, the proxy will route all ACME tls-sni-01 challenges
47+ // received on ipPort to all SNI dests. You can disable ACME routing
48+ // with AddStopACMESearch.
49+ //
50+ // The ipPort is any valid net.Listen TCP address.
51+ func (p * Proxy ) AddSNIMatchRoute (ipPort string , matcher Matcher , dest Target ) {
3852 cfg := p .configFor (ipPort )
3953 if ! cfg .stopACME {
4054 if len (cfg .acmeTargets ) == 0 {
@@ -43,7 +57,7 @@ func (p *Proxy) AddSNIRoute(ipPort, sni string, dest Target) {
4357 cfg .acmeTargets = append (cfg .acmeTargets , dest )
4458 }
4559
46- p .addRoute (ipPort , sniMatch {sni , dest })
60+ p .addRoute (ipPort , sniMatch {matcher , dest })
4761}
4862
4963// AddStopACMESearch prevents ACME probing of subsequent SNI routes.
@@ -55,12 +69,12 @@ func (p *Proxy) AddStopACMESearch(ipPort string) {
5569}
5670
5771type sniMatch struct {
58- sni string
59- target Target
72+ matcher Matcher
73+ target Target
6074}
6175
6276func (m sniMatch ) match (br * bufio.Reader ) Target {
63- if clientHelloServerName ( br ) == string ( m . sni ) {
77+ if m . matcher ( context . TODO (), clientHelloServerName ( br ) ) {
6478 return m .target
6579 }
6680 return nil
0 commit comments