mirror of
https://github.com/eolinker/apinto
synced 2025-10-19 15:14:32 +08:00
rewrite插件修复context引用
This commit is contained in:
@@ -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
|
||||
|
@@ -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 {
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user