update
This commit is contained in:
parent
9882ad3edb
commit
e554570004
1 changed files with 20 additions and 2 deletions
|
|
@ -9,15 +9,18 @@ import (
|
|||
)
|
||||
|
||||
type ReverseProxy struct {
|
||||
context.Context
|
||||
*httputil.ReverseProxy
|
||||
}
|
||||
|
||||
type CtxKey string
|
||||
|
||||
func New(ctx context.Context, host string) *ReverseProxy {
|
||||
|
||||
ctxKey := CtxKey("host")
|
||||
ctx = context.WithValue(ctx, ctxKey, host)
|
||||
reverseproxy := &httputil.ReverseProxy{
|
||||
|
||||
reverseProxySTDLIB := &httputil.ReverseProxy{
|
||||
Director: func(r *http.Request) {
|
||||
r = r.WithContext(ctx)
|
||||
hostFromCtx := ctx.Value(ctxKey).(string)
|
||||
|
|
@ -33,7 +36,17 @@ func New(ctx context.Context, host string) *ReverseProxy {
|
|||
}
|
||||
},
|
||||
}
|
||||
return &ReverseProxy{reverseproxy}
|
||||
reverseProxy := &ReverseProxy{}
|
||||
reverseProxy.Context = ctx
|
||||
reverseProxy.ReverseProxy = reverseProxySTDLIB
|
||||
return reverseProxy
|
||||
}
|
||||
func (revereProxy *ReverseProxy) SetContext(ctx context.Context) {
|
||||
revereProxy.Context = ctx
|
||||
}
|
||||
func (revereProxy *ReverseProxy) DirectorFunc(df func(jup JoinURLPathFunc) DirectorFunc) {
|
||||
d := df(joinURLPath)
|
||||
revereProxy.Director = d
|
||||
}
|
||||
|
||||
func singleJoiningSlash(a, b string) string {
|
||||
|
|
@ -68,3 +81,8 @@ func joinURLPath(a, b *url.URL) (path, rawpath string) {
|
|||
}
|
||||
return a.Path + b.Path, apath + bpath
|
||||
}
|
||||
|
||||
type JoinURLPathFunc func(*url.URL, *url.URL) (string, string)
|
||||
|
||||
// type SingleJoiningSlashFunc func(string, string) string
|
||||
type DirectorFunc func(*http.Request)
|
||||
|
|
|
|||
Loading…
Reference in a new issue