summaryrefslogtreecommitdiff
path: root/sni.go
diff options
context:
space:
mode:
authorDavid Anderson <[email protected]>2017-07-06 00:29:51 -0700
committerDave Anderson <[email protected]>2017-07-06 21:36:14 -0700
commit815c9425f1ad46ffd3a3fb1bbefc05440072e4a4 (patch)
tree199b42d5595dad7c0e2aef8ea7500abe3fa4d55b /sni.go
parent2065af4b1e2d181a987a23f64c66f43e474469ff (diff)
Merge matcher and route into an interface that yields a Target.
This allows routes to compute a target at match time, instead of being statically mapped to a Target at register time.
Diffstat (limited to 'sni.go')
-rw-r--r--sni.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/sni.go b/sni.go
index e12c744..f0128bf 100644
--- a/sni.go
+++ b/sni.go
@@ -29,13 +29,19 @@ import (
//
// The ipPort is any valid net.Listen TCP address.
func (p *Proxy) AddSNIRoute(ipPort, sni string, dest Target) {
- p.addRoute(ipPort, sniMatch(sni), dest)
+ p.addRoute(ipPort, sniMatch{sni, dest})
}
-type sniMatch string
+type sniMatch struct {
+ sni string
+ target Target
+}
-func (sni sniMatch) match(br *bufio.Reader) bool {
- return clientHelloServerName(br) == string(sni)
+func (m sniMatch) match(br *bufio.Reader) Target {
+ if clientHelloServerName(br) == string(m.sni) {
+ return m.target
+ }
+ return nil
}
// clientHelloServerName returns the SNI server name inside the TLS ClientHello,