mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
fixed stack overflow error due to recursive call of rewrite
This commit is contained in:
parent
076c19c4ea
commit
8a640ec484
5 changed files with 17 additions and 7 deletions
|
@ -37,7 +37,7 @@ In the examples domain `x.y.z` is used, replace them with your domain
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## How to use (docker)
|
## How to use
|
||||||
|
|
||||||
1. Download and extract the latest release (or clone the repository if you want to try out experimental features)
|
1. Download and extract the latest release (or clone the repository if you want to try out experimental features)
|
||||||
|
|
||||||
|
|
BIN
bin/go-proxy
BIN
bin/go-proxy
Binary file not shown.
|
@ -162,7 +162,7 @@ func (p *Provider) getDockerProxyConfigs() ([]*ProxyConfig, error) {
|
||||||
return nil, fmt.Errorf("unable to create docker client: %v", err)
|
return nil, fmt.Errorf("unable to create docker client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
containerSlice, err := p.dockerClient.ContainerList(context.Background(), container.ListOptions{})
|
containerSlice, err := p.dockerClient.ContainerList(context.Background(), container.ListOptions{All: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to list containers: %v", err)
|
return nil, fmt.Errorf("unable to list containers: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,20 +52,22 @@ func NewHTTPRoute(config *ProxyConfig) (*HTTPRoute, error) {
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rewriteBegin = proxy.Rewrite
|
||||||
var rewrite func(*ProxyRequest)
|
var rewrite func(*ProxyRequest)
|
||||||
|
var modifyResponse func(*http.Response) error
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case config.Path == "", config.PathMode == ProxyPathMode_Forward:
|
case config.Path == "", config.PathMode == ProxyPathMode_Forward:
|
||||||
rewrite = proxy.Rewrite
|
rewrite = rewriteBegin
|
||||||
case config.PathMode == ProxyPathMode_Sub:
|
case config.PathMode == ProxyPathMode_Sub:
|
||||||
rewrite = func(pr *ProxyRequest) {
|
rewrite = func(pr *ProxyRequest) {
|
||||||
proxy.Rewrite(pr)
|
rewriteBegin(pr)
|
||||||
// disable compression
|
// disable compression
|
||||||
pr.Out.Header.Set("Accept-Encoding", "identity")
|
pr.Out.Header.Set("Accept-Encoding", "identity")
|
||||||
// remove path prefix
|
// remove path prefix
|
||||||
pr.Out.URL.Path = strings.TrimPrefix(pr.Out.URL.Path, config.Path)
|
pr.Out.URL.Path = strings.TrimPrefix(pr.Out.URL.Path, config.Path)
|
||||||
}
|
}
|
||||||
route.Proxy.ModifyResponse = func(r *http.Response) error {
|
modifyResponse = func(r *http.Response) error {
|
||||||
contentType, ok := r.Header["Content-Type"]
|
contentType, ok := r.Header["Content-Type"]
|
||||||
if !ok || len(contentType) == 0 {
|
if !ok || len(contentType) == 0 {
|
||||||
route.l.Debug("unknown content type for ", r.Request.URL.String())
|
route.l.Debug("unknown content type for ", r.Request.URL.String())
|
||||||
|
@ -93,7 +95,7 @@ func NewHTTPRoute(config *ProxyConfig) (*HTTPRoute, error) {
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
rewrite = func(pr *ProxyRequest) {
|
rewrite = func(pr *ProxyRequest) {
|
||||||
proxy.Rewrite(pr)
|
rewriteBegin(pr)
|
||||||
pr.Out.URL.Path = strings.TrimPrefix(pr.Out.URL.Path, config.Path)
|
pr.Out.URL.Path = strings.TrimPrefix(pr.Out.URL.Path, config.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,8 +103,17 @@ func NewHTTPRoute(config *ProxyConfig) (*HTTPRoute, error) {
|
||||||
if logLevel == logrus.DebugLevel {
|
if logLevel == logrus.DebugLevel {
|
||||||
route.Proxy.Rewrite = func(pr *ProxyRequest) {
|
route.Proxy.Rewrite = func(pr *ProxyRequest) {
|
||||||
rewrite(pr)
|
rewrite(pr)
|
||||||
|
route.l.Debug("Request URL: ", pr.In.Host, pr.In.URL.Path)
|
||||||
route.l.Debug("Request headers: ", pr.In.Header)
|
route.l.Debug("Request headers: ", pr.In.Header)
|
||||||
}
|
}
|
||||||
|
route.Proxy.ModifyResponse = func(r *http.Response) error {
|
||||||
|
route.l.Debug("Response URL: ", r.Request.URL.String())
|
||||||
|
route.l.Debug("Response headers: ", r.Header)
|
||||||
|
if modifyResponse != nil {
|
||||||
|
return modifyResponse(r)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
route.Proxy.Rewrite = rewrite
|
route.Proxy.Rewrite = rewrite
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ func main() {
|
||||||
DisableColors: false,
|
DisableColors: false,
|
||||||
FullTimestamp: true,
|
FullTimestamp: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
InitFSWatcher()
|
InitFSWatcher()
|
||||||
InitDockerWatcher()
|
InitDockerWatcher()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue