Migrate Sirupsen to sirupsen.

This commit is contained in:
Ludovic Fernandez 2018-01-22 12:16:03 +01:00 committed by Traefiker
parent c134dcd6fe
commit fb4ba7af2b
684 changed files with 92394 additions and 33943 deletions

View file

@ -31,7 +31,7 @@ import (
"sync"
"time"
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/mailgun/timetools"
"github.com/vulcand/oxy/memmetrics"

View file

@ -9,7 +9,7 @@ import (
"net/url"
"strings"
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/utils"
)

View file

@ -6,7 +6,7 @@ import (
"net/url"
"strconv"
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/utils"
)

View file

@ -4,7 +4,7 @@ import (
"fmt"
"time"
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/vulcand/predicate"
)

View file

@ -4,8 +4,8 @@ import (
"fmt"
"time"
log "github.com/Sirupsen/logrus"
"github.com/mailgun/timetools"
log "github.com/sirupsen/logrus"
)
// ratioController allows passing portions traffic back to the endpoints,

View file

@ -6,7 +6,7 @@ import (
"net/http"
"sync"
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/utils"
)

View file

@ -5,6 +5,7 @@ package forward
import (
"crypto/tls"
"fmt"
"net/http"
"net/http/httptest"
"net/http/httputil"
@ -14,8 +15,8 @@ import (
"strings"
"time"
log "github.com/Sirupsen/logrus"
"github.com/gorilla/websocket"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/utils"
)
@ -281,6 +282,7 @@ func (f *httpForwarder) serveWebSocket(w http.ResponseWriter, req *http.Request,
outReq := f.copyWebSocketRequest(req)
dialer := websocket.DefaultDialer
if outReq.URL.Scheme == "wss" && f.tlsClientConfig != nil {
dialer.TLSClientConfig = f.tlsClientConfig.Clone()
// WebSocket is only in http/1.1
@ -323,6 +325,7 @@ func (f *httpForwarder) serveWebSocket(w http.ResponseWriter, req *http.Request,
}}
utils.RemoveHeaders(resp.Header, WebsocketUpgradeHeaders...)
underlyingConn, err := upgrader.Upgrade(w, req, resp.Header)
if err != nil {
log.Errorf("vulcand/oxy/forward/websocket: Error while upgrading connection : %v", err)
@ -331,29 +334,45 @@ func (f *httpForwarder) serveWebSocket(w http.ResponseWriter, req *http.Request,
defer underlyingConn.Close()
defer targetConn.Close()
errc := make(chan error, 2)
replicateWebsocketConn := func(dst, src *websocket.Conn, dstName, srcName string) {
var err error
errClient := make(chan error)
errBackend := make(chan error)
replicateWebsocketConn := func(dst, src *websocket.Conn, errc chan error) {
for {
msgType, msg, err := src.ReadMessage()
if err != nil {
f.log.Errorf("vulcand/oxy/forward/websocket: Error when copying from %s to %s using ReadMessage: %v", srcName, dstName, err)
m := websocket.FormatCloseMessage(websocket.CloseNormalClosure, fmt.Sprintf("%v", err))
if e, ok := err.(*websocket.CloseError); ok {
if e.Code != websocket.CloseNoStatusReceived {
m = websocket.FormatCloseMessage(e.Code, e.Text)
}
}
errc <- err
dst.WriteMessage(websocket.CloseMessage, m)
break
}
err = dst.WriteMessage(msgType, msg)
if err != nil {
f.log.Errorf("vulcand/oxy/forward/websocket: Error when copying from %s to %s using WriteMessage: %v", srcName, dstName, err)
errc <- err
break
}
}
errc <- err
}
go replicateWebsocketConn(underlyingConn, targetConn, "client", "backend")
go replicateWebsocketConn(targetConn, underlyingConn, "backend", "client")
go replicateWebsocketConn(underlyingConn, targetConn, errClient)
go replicateWebsocketConn(targetConn, underlyingConn, errBackend)
<-errc
var message string
select {
case err = <-errClient:
message = "vulcand/oxy/forward/websocket: Error when copying from backend to client: %v"
case err = <-errBackend:
message = "vulcand/oxy/forward/websocket: Error when copying from client to backend: %v"
}
if e, ok := err.(*websocket.CloseError); !ok || e.Code == websocket.CloseAbnormalClosure {
f.log.Errorf(message, err)
}
}
// copyWebsocketRequest makes a copy of the specified request.

View file

@ -49,6 +49,7 @@ var WebsocketUpgradeHeaders = []string{
Upgrade,
Connection,
SecWebsocketAccept,
SecWebsocketExtensions,
}
var XHeaders = []string{

View file

@ -7,9 +7,9 @@ import (
"sync"
"time"
log "github.com/Sirupsen/logrus"
"github.com/mailgun/timetools"
"github.com/mailgun/ttlmap"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/utils"
)

View file

@ -7,8 +7,8 @@ import (
"sync"
"time"
log "github.com/Sirupsen/logrus"
"github.com/mailgun/timetools"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/memmetrics"
"github.com/vulcand/oxy/utils"
)

View file

@ -7,7 +7,7 @@ import (
"net/url"
"sync"
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/utils"
)

View file

@ -9,7 +9,7 @@ import (
"net/url"
"reflect"
log "github.com/Sirupsen/logrus"
log "github.com/sirupsen/logrus"
)
// ProxyWriter helps to capture response headers and status code

150
vendor/github.com/vulcand/predicate/lib.go generated vendored Normal file
View file

@ -0,0 +1,150 @@
/*
Copyright 2016 Vulcand Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package predicate
import (
"reflect"
"strings"
"github.com/gravitational/trace"
)
// GetStringMapValue is a helper function that returns property
// from map[string]string or map[string][]string
// the function returns empty value in case if key not found
// In case if map is nil, returns empty value as well
func GetStringMapValue(mapVal, keyVal interface{}) (interface{}, error) {
key, ok := keyVal.(string)
if !ok {
return nil, trace.BadParameter("only string keys are supported")
}
switch m := mapVal.(type) {
case map[string][]string:
if len(m) == 0 {
// to return nil with a proper type
var n []string
return n, nil
}
return m[key], nil
case map[string]string:
if len(m) == 0 {
return "", nil
}
return m[key], nil
default:
return nil, trace.BadParameter("type %T is not supported", m)
}
}
// BoolPredicate is a function without arguments that returns
// boolean value when called
type BoolPredicate func() bool
// Equals can compare complex objects, e.g. arrays of strings
// and strings together
func Equals(a interface{}, b interface{}) BoolPredicate {
return func() bool {
switch aval := a.(type) {
case string:
bval, ok := b.(string)
return ok && aval == bval
case []string:
bval, ok := b.([]string)
if !ok {
return false
}
if len(aval) != len(bval) {
return false
}
for i := range aval {
if aval[i] != bval[i] {
return false
}
}
return true
default:
return false
}
}
}
// Contains checks if string slice contains a string
// Contains([]string{"a", "b"}, "b") -> true
func Contains(a interface{}, b interface{}) BoolPredicate {
return func() bool {
aval, ok := a.([]string)
if !ok {
return false
}
bval, ok := b.(string)
if !ok {
return false
}
for _, v := range aval {
if v == bval {
return true
}
}
return false
}
}
// And is a boolean predicate that calls two boolean predicates
// and returns result of && operation on their return values
func And(a, b BoolPredicate) BoolPredicate {
return func() bool {
return a() && b()
}
}
// Or is a boolean predicate that calls two boolean predicates
// and returns result of || operation on their return values
func Or(a, b BoolPredicate) BoolPredicate {
return func() bool {
return a() || b()
}
}
// GetFieldByTag returns a field from the object based on the tag
func GetFieldByTag(ival interface{}, tagName string, fieldNames []string) (interface{}, error) {
if len(fieldNames) == 0 {
return nil, trace.BadParameter("missing field names")
}
val := reflect.ValueOf(ival)
if val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr {
val = val.Elem()
}
if val.Kind() != reflect.Struct {
return nil, trace.NotFound("field name %v is not found", strings.Join(fieldNames, "."))
}
fieldName := fieldNames[0]
rest := fieldNames[1:]
valType := val.Type()
for i := 0; i < valType.NumField(); i++ {
tagValue := valType.Field(i).Tag.Get(tagName)
parts := strings.Split(tagValue, ",")
if parts[0] == fieldName {
value := val.Field(i).Interface()
if len(rest) == 0 {
return value, nil
}
return GetFieldByTag(value, tagName, rest)
}
}
return nil, trace.NotFound("field name %v is not found", strings.Join(fieldNames, "."))
}

View file

@ -7,6 +7,9 @@ import (
"go/token"
"reflect"
"strconv"
"strings"
"github.com/gravitational/trace"
)
func NewParser(d Def) (Parser, error) {
@ -49,7 +52,7 @@ func (p *predicateParser) parseNode(node ast.Node) (interface{}, error) {
if err != nil {
return nil, err
}
arguments, err := collectLiterals(n.Args)
arguments, err := p.evaluateArguments(n.Args)
if err != nil {
return nil, err
}
@ -57,13 +60,92 @@ func (p *predicateParser) parseNode(node ast.Node) (interface{}, error) {
case *ast.ParenExpr:
return p.parseNode(n.X)
}
return nil, fmt.Errorf("unsupported %T", node)
return nil, trace.BadParameter("unsupported %T", node)
}
func (p *predicateParser) evaluateArguments(nodes []ast.Expr) ([]interface{}, error) {
out := make([]interface{}, len(nodes))
for i, n := range nodes {
val, err := p.evaluateExpr(n)
if err != nil {
return nil, trace.Wrap(err)
}
out[i] = val
}
return out, nil
}
func (p *predicateParser) evaluateExpr(n ast.Expr) (interface{}, error) {
switch l := n.(type) {
case *ast.BasicLit:
val, err := literalToValue(l)
if err != nil {
return nil, err
}
return val, nil
case *ast.IndexExpr:
if p.d.GetProperty == nil {
return nil, trace.NotFound("properties are not supported")
}
mapVal, err := p.evaluateExpr(l.X)
if err != nil {
return nil, trace.Wrap(err)
}
keyVal, err := p.evaluateExpr(l.Index)
if err != nil {
return nil, trace.Wrap(err)
}
val, err := p.d.GetProperty(mapVal, keyVal)
if err != nil {
return nil, trace.Wrap(err)
}
return val, nil
case *ast.SelectorExpr:
fields, err := evaluateSelector(l, []string{})
if err != nil {
return nil, trace.Wrap(err)
}
if p.d.GetIdentifier == nil {
return nil, trace.NotFound("%v is not defined", strings.Join(fields, "."))
}
val, err := p.d.GetIdentifier(fields)
if err != nil {
return nil, trace.Wrap(err)
}
return val, nil
case *ast.Ident:
if p.d.GetIdentifier == nil {
return nil, trace.NotFound("%v is not defined", l.Name)
}
val, err := p.d.GetIdentifier([]string{l.Name})
if err != nil {
return nil, trace.Wrap(err)
}
return val, nil
default:
return nil, trace.BadParameter("%T is not supported", n)
}
}
// evaluateSelector recursively evaluates the selector field and returns a list
// of properties at the end
func evaluateSelector(sel *ast.SelectorExpr, fields []string) ([]string, error) {
fields = append([]string{sel.Sel.Name}, fields...)
switch l := sel.X.(type) {
case *ast.SelectorExpr:
return evaluateSelector(l, fields)
case *ast.Ident:
fields = append([]string{l.Name}, fields...)
return fields, nil
default:
return nil, trace.BadParameter("unsupported selector type: %T", l)
}
}
func (p *predicateParser) getFunction(name string) (interface{}, error) {
v, ok := p.d.Functions[name]
if !ok {
return nil, fmt.Errorf("unsupported function: %s", name)
return nil, trace.BadParameter("unsupported function: %s", name)
}
return v, nil
}
@ -97,7 +179,7 @@ func (p *predicateParser) getJoinFunction(op token.Token) (interface{}, error) {
fn = p.d.Operators.NEQ
}
if fn == nil {
return nil, fmt.Errorf("%v is not supported", op)
return nil, trace.BadParameter("%v is not supported", op)
}
return fn, nil
}
@ -107,62 +189,46 @@ func getIdentifier(node ast.Node) (string, error) {
if ok {
id, ok := sexpr.X.(*ast.Ident)
if !ok {
return "", fmt.Errorf("expected selector identifier, got: %T", sexpr.X)
return "", trace.BadParameter("expected selector identifier, got: %T", sexpr.X)
}
return fmt.Sprintf("%s.%s", id.Name, sexpr.Sel.Name), nil
}
id, ok := node.(*ast.Ident)
if !ok {
return "", fmt.Errorf("expected identifier, got: %T", node)
return "", trace.BadParameter("expected identifier, got: %T", node)
}
return id.Name, nil
}
func collectLiterals(nodes []ast.Expr) ([]interface{}, error) {
out := make([]interface{}, len(nodes))
for i, n := range nodes {
l, ok := n.(*ast.BasicLit)
if !ok {
return nil, fmt.Errorf("expected literal, got %T", n)
}
val, err := literalToValue(l)
if err != nil {
return nil, err
}
out[i] = val
}
return out, nil
}
func literalToValue(a *ast.BasicLit) (interface{}, error) {
switch a.Kind {
case token.FLOAT:
value, err := strconv.ParseFloat(a.Value, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse argument: %s, error: %s", a.Value, err)
return nil, trace.BadParameter("failed to parse argument: %s, error: %s", a.Value, err)
}
return value, nil
case token.INT:
value, err := strconv.Atoi(a.Value)
if err != nil {
return nil, fmt.Errorf("failed to parse argument: %s, error: %s", a.Value, err)
return nil, trace.BadParameter("failed to parse argument: %s, error: %s", a.Value, err)
}
return value, nil
case token.STRING:
value, err := strconv.Unquote(a.Value)
if err != nil {
return nil, fmt.Errorf("failed to parse argument: %s, error: %s", a.Value, err)
return nil, trace.BadParameter("failed to parse argument: %s, error: %s", a.Value, err)
}
return value, nil
}
return nil, fmt.Errorf("unsupported function argument type: '%v'", a.Kind)
return nil, trace.BadParameter("unsupported function argument type: '%v'", a.Kind)
}
func callFunction(f interface{}, args []interface{}) (v interface{}, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%s", r)
err = trace.BadParameter("%s", r)
}
}()
arguments := make([]reflect.Value, len(args))
@ -182,9 +248,9 @@ func callFunction(f interface{}, args []interface{}) (v interface{}, err error)
}
err, ok := e.(error)
if !ok {
return nil, fmt.Errorf("expected error as a second return value, got %T", e)
return nil, trace.BadParameter("expected error as a second return value, got %T", e)
}
return v, err
}
return nil, fmt.Errorf("expected at least one return argument for '%v'", fn)
return nil, trace.BadParameter("expected at least one return argument for '%v'", fn)
}

View file

@ -48,8 +48,21 @@ type Def struct {
Operators Operators
// Function matching is case sensitive, e.g. Len is different from len
Functions map[string]interface{}
// GetIdentifier returns value of any identifier passed in
// in the form []string{"id", "field", "subfield"}
GetIdentifier GetIdentifierFn
// GetProperty returns property from a map
GetProperty GetPropertyFn
}
// GetIdentifierFn function returns identifier based on selector
// e.g. id.field.subfield will be passed as.
// GetIdentifierFn([]string{"id", "field", "subfield"})
type GetIdentifierFn func(selector []string) (interface{}, error)
// GetPropertyFn reuturns property from a mapVal by key keyVal
type GetPropertyFn func(mapVal, keyVal interface{}) (interface{}, error)
// Operators contain functions for equality and logical comparison.
type Operators struct {
EQ interface{}

View file

@ -1,5 +1,5 @@
/*
package route provides http package-compatible routing library. It can route http requests by by hostname, method, path and headers.
package route provides http package-compatible routing library. It can route http requests by hostname, method, path and headers.
Route defines simple language for matching requests based on Go syntax. Route provides series of matchers that follow the syntax:

View file

@ -0,0 +1,7 @@
package cacheprovider
import "golang.org/x/crypto/acme/autocert"
type T interface {
GetAutoCertCache() autocert.Cache
}

View file

@ -0,0 +1,71 @@
package cacheprovider
import (
"context"
etcd "github.com/coreos/etcd/client"
"golang.org/x/crypto/acme/autocert"
)
func NewEtcdV2CacheProvider(kapi etcd.KeysAPI, vulcanPrefix string) T {
return &etcdv2CacheProvider{
kapi: kapi,
vulcanPrefix: vulcanPrefix,
}
}
type etcdv2CacheProvider struct {
kapi etcd.KeysAPI
vulcanPrefix string
autoCertCache autocert.Cache
}
func (p *etcdv2CacheProvider) GetAutoCertCache() autocert.Cache {
if p.autoCertCache == nil {
p.autoCertCache = &etcdv2AutoCertCache{
kapi: p.kapi,
prefix: p.vulcanPrefix + "/autocert_cache/",
}
}
return p.autoCertCache
}
type etcdv2AutoCertCache struct {
kapi etcd.KeysAPI
prefix string
}
// Get returns a certificate data for the specified key.
// If there's no such key, Get returns ErrCacheMiss.
func (ng *etcdv2AutoCertCache) Get(ctx context.Context, rawKey string) ([]byte, error) {
key := ng.normalized(rawKey)
r, err := ng.kapi.Get(ctx, key, &etcd.GetOptions{})
if err != nil {
return nil, err
}
if r.Node == nil {
return nil, autocert.ErrCacheMiss
}
return []byte(r.Node.Value), nil
}
// Put stores the data in the cache under the specified key.
// Inderlying implementations may use any data storage format,
// as long as the reverse operation, Get, results in the original data.
func (ng *etcdv2AutoCertCache) Put(ctx context.Context, rawKey string, data []byte) error {
key := ng.normalized(rawKey)
_, err := ng.kapi.Set(ctx, key, string(data), &etcd.SetOptions{})
return err
}
// Delete removes a certificate data from the cache under the specified key.
// If there's no such key in the cache, Delete returns nil.
func (ng *etcdv2AutoCertCache) Delete(ctx context.Context, rawKey string) error {
key := ng.normalized(rawKey)
_, err := ng.kapi.Delete(ctx, key, &etcd.DeleteOptions{})
return err
}
func (ng *etcdv2AutoCertCache) normalized(key string) string {
return ng.prefix + key
}

View file

@ -0,0 +1,76 @@
package cacheprovider
import (
"context"
etcd "github.com/coreos/etcd/clientv3"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/acme/autocert"
)
func NewEtcdV3CacheProvider(client *etcd.Client, vulcanPrefix string) T {
return &etcdv3CacheProvider{
client: client,
vulcanPrefix: vulcanPrefix,
}
}
type etcdv3CacheProvider struct {
client *etcd.Client
vulcanPrefix string
autoCertCache autocert.Cache
}
func (p *etcdv3CacheProvider) GetAutoCertCache() autocert.Cache {
if p.autoCertCache == nil {
p.autoCertCache = &etcdv3AutoCertCache{
client: p.client,
prefix: p.vulcanPrefix + "/autocert_cache/",
}
}
return p.autoCertCache
}
type etcdv3AutoCertCache struct {
client *etcd.Client
prefix string
}
// Get returns a certificate data for the specified key.
// If there's no such key, Get returns ErrCacheMiss.
func (ng *etcdv3AutoCertCache) Get(ctx context.Context, rawKey string) ([]byte, error) {
key := ng.normalize(rawKey)
r, err := ng.client.Get(ctx, key)
if err != nil {
return nil, err
}
if r.Count == 0 {
return nil, autocert.ErrCacheMiss
}
if r.Count > 1 {
log.Errorf("Against all odds, multiple results returned from Etcd when looking for single key: %s. "+
"Returning the first one.", key)
}
return r.Kvs[0].Value, nil
}
// Put stores the data in the cache under the specified key.
// Inderlying implementations may use any data storage format,
// as long as the reverse operation, Get, results in the original data.
func (ng *etcdv3AutoCertCache) Put(ctx context.Context, rawKey string, data []byte) error {
key := ng.normalize(rawKey)
_, err := ng.client.Put(ctx, key, string(data))
return err
}
// Delete removes a certificate data from the cache under the specified key.
// If there's no such key in the cache, Delete returns nil.
func (ng *etcdv3AutoCertCache) Delete(ctx context.Context, rawKey string) error {
key := ng.normalize(rawKey)
_, err := ng.client.Delete(ctx, key)
return err
}
func (ng *etcdv3AutoCertCache) normalize(rawKey string) string {
return ng.prefix + rawKey
}

View file

@ -0,0 +1,61 @@
package cacheprovider
import (
"context"
"sync"
"golang.org/x/crypto/acme/autocert"
)
func NewMemCacheProvider() T {
return &memCacheProvider{}
}
type memCacheProvider struct {
autocertCache autocert.Cache
}
func (p *memCacheProvider) GetAutoCertCache() autocert.Cache {
if p.autocertCache == nil {
p.autocertCache = &memAutoCertCache{
kv: make(map[string][]byte),
}
}
return p.autocertCache
}
type memAutoCertCache struct {
kv map[string][]byte
mtx sync.Mutex
}
// Get returns a certificate data for the specified key.
// If there's no such key, Get returns ErrCacheMiss.
func (ng *memAutoCertCache) Get(ctx context.Context, key string) ([]byte, error) {
ng.mtx.Lock()
defer ng.mtx.Unlock()
val, ok := ng.kv[key]
if ok {
return val, nil
}
return nil, autocert.ErrCacheMiss
}
// Put stores the data in the cache under the specified key.
// Inderlying implementations may use any data storage format,
// as long as the reverse operation, Get, results in the original data.
func (ng *memAutoCertCache) Put(ctx context.Context, key string, data []byte) error {
ng.mtx.Lock()
defer ng.mtx.Unlock()
ng.kv[key] = data
return nil
}
// Delete removes a certificate data from the cache under the specified key.
// If there's no such key in the cache, Delete returns nil.
func (ng *memAutoCertCache) Delete(ctx context.Context, key string) error {
ng.mtx.Lock()
defer ng.mtx.Unlock()
delete(ng.kv, key)
return nil
}

View file

@ -0,0 +1,11 @@
package cacheprovider
import "golang.org/x/crypto/acme/autocert"
type noOpCacheProvider struct{}
func (*noOpCacheProvider) GetAutoCertCache() autocert.Cache { return nil }
func NoOp() T {
return &noOpCacheProvider{}
}

View file

@ -3,12 +3,16 @@ package plugin
import (
"encoding/json"
"fmt"
"github.com/codegangsta/cli"
"github.com/vulcand/route"
"github.com/vulcand/vulcand/conntracker"
"github.com/vulcand/vulcand/router"
"net/http"
"reflect"
"github.com/codegangsta/cli"
"github.com/vulcand/oxy/forward"
"github.com/vulcand/oxy/roundrobin"
"github.com/vulcand/route"
"github.com/vulcand/vulcand/conntracker"
"github.com/vulcand/vulcand/plugin/cacheprovider"
"github.com/vulcand/vulcand/router"
)
// Middleware specification, used to construct new middlewares and plug them into CLI API and backends
@ -53,12 +57,22 @@ type CliReader func(c *cli.Context) (Middleware, error)
// Function that returns middleware spec by it's type
type SpecGetter func(string) *MiddlewareSpec
// Holds a bunch of Listeners a frontend might have.
// This allows callers to consolidate all their listeners in one convenient struct.
type FrontendListeners struct {
ConnTck forward.UrlForwardingStateListener
RbRewriteListener roundrobin.RequestRewriteListener
RrRewriteListener roundrobin.RequestRewriteListener
}
// Registry contains currently registered middlewares and used to support pluggable middlewares across all modules of the vulcand
type Registry struct {
specs []*MiddlewareSpec
notFound Middleware
router router.Router
connTracker conntracker.ConnectionTracker
specs []*MiddlewareSpec
notFound Middleware
router router.Router
incomingConnectionTracker conntracker.ConnectionTracker
frontendListeners FrontendListeners
cacheProvider cacheprovider.T
}
func NewRegistry() *Registry {
@ -113,13 +127,31 @@ func (r *Registry) GetRouter() router.Router {
return r.router
}
func (r *Registry) SetConnectionTracker(connTracker conntracker.ConnectionTracker) error {
r.connTracker = connTracker
func (r *Registry) SetIncomingConnectionTracker(connTracker conntracker.ConnectionTracker) error {
r.incomingConnectionTracker = connTracker
return nil
}
func (r *Registry) GetConnectionTracker() conntracker.ConnectionTracker {
return r.connTracker
func (r *Registry) GetIncomingConnectionTracker() conntracker.ConnectionTracker {
return r.incomingConnectionTracker
}
func (r *Registry) GetFrontendListeners() FrontendListeners {
return r.frontendListeners
}
func (r *Registry) SetFrontendListeners(frontendListeners FrontendListeners) error {
r.frontendListeners = frontendListeners
return nil
}
func (r *Registry) GetCacheProvider() cacheprovider.T {
return r.cacheProvider
}
func (r *Registry) SetCacheProvider(cacheprovider cacheprovider.T) error {
r.cacheProvider = cacheprovider
return nil
}
func verifySignature(fn interface{}) error {

View file

@ -10,8 +10,8 @@ import (
"strconv"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/utils"
"github.com/vulcand/vulcand/plugin"
)
@ -109,8 +109,7 @@ func (rw *rewriteHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
rw.next.ServeHTTP(bw, req)
if err := Apply(bw.buffer, newBody, req); err != nil {
log.Errorf("Failed to rewrite response body: %v", err)
return
log.Errorf("While rewriting response body for '%s': %v", req.RequestURI, err)
}
utils.CopyHeaders(w.Header(), bw.Header())

View file

@ -2,25 +2,25 @@ package router
import "net/http"
//This interface captures all routing functionality required by vulcan.
//The routing functionality mainly comes from "github.com/vulcand/route",
// This interface captures all routing functionality required by vulcan.
// The routing functionality mainly comes from "github.com/vulcand/route",
type Router interface {
//Sets the not-found handler (this handler is called when no other handlers/routes in the routing library match
// Sets the not-found handler (this handler is called when no other handlers/routes in the routing library match
SetNotFound(http.Handler) error
//Gets the not-found handler that is currently in use by this router.
// Gets the not-found handler that is currently in use by this router.
GetNotFound() http.Handler
//Validates whether this is an acceptable route expression
// Validates whether this is an acceptable route expression
IsValid(string) bool
//Adds a new route->handler combination. The route is a string which provides the routing expression. http.Handler is called when this expression matches a request.
// Adds a new route->handler combination. The route is a string which provides the routing expression. http.Handler is called when this expression matches a request.
Handle(string, http.Handler) error
//Removes a route. The http.Handler associated with it, will be discarded.
// Removes a route. The http.Handler associated with it, will be discarded.
Remove(string) error
//ServiceHTTP is the http.Handler implementation that allows callers to route their calls to sub-http.Handlers based on route matches.
// ServiceHTTP is the http.Handler implementation that allows callers to route their calls to sub-http.Handlers based on route matches.
ServeHTTP(http.ResponseWriter, *http.Request)
}