diff options
author | David Anderson <[email protected]> | 2017-07-06 00:29:51 -0700 |
---|---|---|
committer | Dave Anderson <[email protected]> | 2017-07-06 21:36:14 -0700 |
commit | 815c9425f1ad46ffd3a3fb1bbefc05440072e4a4 (patch) | |
tree | 199b42d5595dad7c0e2aef8ea7500abe3fa4d55b /http.go | |
parent | 2065af4b1e2d181a987a23f64c66f43e474469ff (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 'http.go')
-rw-r--r-- | http.go | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -27,13 +27,19 @@ import ( // // The ipPort is any valid net.Listen TCP address. func (p *Proxy) AddHTTPHostRoute(ipPort, httpHost string, dest Target) { - p.addRoute(ipPort, httpHostMatch(httpHost), dest) + p.addRoute(ipPort, httpHostMatch{httpHost, dest}) } -type httpHostMatch string +type httpHostMatch struct { + host string + target Target +} -func (host httpHostMatch) match(br *bufio.Reader) bool { - return httpHostHeader(br) == string(host) +func (m httpHostMatch) match(br *bufio.Reader) Target { + if httpHostHeader(br) == m.host { + return m.target + } + return nil } // httpHostHeader returns the HTTP Host header from br without |