diff --git a/reverseproxy.go b/reverseproxy.go index 3b62134..26a93a9 100644 --- a/reverseproxy.go +++ b/reverseproxy.go @@ -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)