aboutsummaryrefslogtreecommitdiff
path: root/route.go
diff options
context:
space:
mode:
Diffstat (limited to 'route.go')
-rw-r--r--route.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/route.go b/route.go
index 92d318d..5e1b806 100644
--- a/route.go
+++ b/route.go
@@ -1,14 +1,31 @@
package goxy
import (
+ "crypto/tls"
"encoding/json"
+ "errors"
"fmt"
"net/http"
+ "net/url"
"os"
)
// Route defines a set of routes including correspondent TLS certificates
-type Route map[string]Entry
+type Route map[string]route
+
+type route struct {
+ ServerName *url.URL
+ Upstream *url.URL
+ Certificate *tls.Certificate
+}
+
+// GetCertificate returns certificate for SNI negotiation
+func (r Route) GetCertificate(h *tls.ClientHelloInfo) (*tls.Certificate, error) {
+ if route, ok := r[h.ServerName]; ok && route.Certificate != nil {
+ return route.Certificate, nil
+ }
+ return nil, errors.New("no cert for " + h.ServerName)
+}
// Save routes to persistent file
func (r Route) Save(fname string) error {