rewrite插件修复context引用

This commit is contained in:
Liujian
2021-11-12 10:14:41 +08:00
parent f04c8862fa
commit e90aee63ab
3 changed files with 14 additions and 9 deletions

View File

@@ -43,7 +43,7 @@ func (d *Driver) Create(id, name string, v interface{}, workers map[eosc.Require
Driver: d,
id: id,
name: name,
url: conf.ReWriteUrl,
path: conf.ReWriteUrl,
}
return rw, nil

View File

@@ -23,12 +23,11 @@ func (r *Rewrite) DoFilter(ctx http_service.IHttpContext, next http_service.ICha
location, has := router.Location()
if has && location.CheckType() == http_service.CheckTypePrefix {
path := recombinePath(string(ctx.Request().URL().Path), location.Value(), r.path)
ctx.Request().URL().Path = path
ctx.Proxy().SetPath(recombinePath(string(ctx.Request().URL().Path), location.Value(), r.path))
}
} else {
if r.path != "" {
ctx.Request().URL().Path = r.path
ctx.Proxy().SetPath(r.path)
}
}
if next != nil {

View File

@@ -20,6 +20,11 @@ type ProxyRequest struct {
method string
}
func (r *ProxyRequest) SetPath(s string) {
r.initUrl()
r.uri.Path = s
}
func NewProxyRequest(requestReader *RequestReader) *ProxyRequest {
return &ProxyRequest{RequestReader: requestReader}
}
@@ -91,19 +96,20 @@ func (r *ProxyRequest) SetRaw(contentType string, body []byte) {
}
func (r *ProxyRequest) TargetServer() string {
if r.uri == nil {
uri := r.URL()
r.uri = &uri
}
r.initUrl()
return r.uri.Host
}
func (r *ProxyRequest) TargetURL() string {
r.initUrl()
return r.uri.Path
}
func (r *ProxyRequest) initUrl() {
if r.uri == nil {
uri := r.URL()
r.uri = &uri
}
return r.uri.Path
}
func (r *ProxyRequest) SetMethod(s string) {