fixed stack overflow error due to recursive call of rewrite

This commit is contained in:
yusing 2024-03-18 20:52:34 +00:00
parent 076c19c4ea
commit 8a640ec484
5 changed files with 17 additions and 7 deletions

View file

@ -37,7 +37,7 @@ In the examples domain `x.y.z` is used, replace them with your domain
![panel screenshot](screenshots/panel.png)
## 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)

Binary file not shown.

View file

@ -162,7 +162,7 @@ func (p *Provider) getDockerProxyConfigs() ([]*ProxyConfig, error) {
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 {
return nil, fmt.Errorf("unable to list containers: %v", err)
}

View file

@ -52,20 +52,22 @@ func NewHTTPRoute(config *ProxyConfig) (*HTTPRoute, error) {
}),
}
var rewriteBegin = proxy.Rewrite
var rewrite func(*ProxyRequest)
var modifyResponse func(*http.Response) error
switch {
case config.Path == "", config.PathMode == ProxyPathMode_Forward:
rewrite = proxy.Rewrite
rewrite = rewriteBegin
case config.PathMode == ProxyPathMode_Sub:
rewrite = func(pr *ProxyRequest) {
proxy.Rewrite(pr)
rewriteBegin(pr)
// disable compression
pr.Out.Header.Set("Accept-Encoding", "identity")
// remove path prefix
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"]
if !ok || len(contentType) == 0 {
route.l.Debug("unknown content type for ", r.Request.URL.String())
@ -93,7 +95,7 @@ func NewHTTPRoute(config *ProxyConfig) (*HTTPRoute, error) {
}
default:
rewrite = func(pr *ProxyRequest) {
proxy.Rewrite(pr)
rewriteBegin(pr)
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 {
route.Proxy.Rewrite = func(pr *ProxyRequest) {
rewrite(pr)
route.l.Debug("Request URL: ", pr.In.Host, pr.In.URL.Path)
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 {
route.Proxy.Rewrite = rewrite
}

View file

@ -21,7 +21,6 @@ func main() {
DisableColors: false,
FullTimestamp: true,
})
InitFSWatcher()
InitDockerWatcher()