diff --git a/internal/options/parse.go b/internal/options/parse.go index 26c8974..43ebde5 100644 --- a/internal/options/parse.go +++ b/internal/options/parse.go @@ -160,7 +160,7 @@ func ParseOptions() *Options { } //https://www.cnblogs.com/feiquan/p/11429065.html os.Chmod(options.Proxy.PluginDir, 0755) //nolint: - // plugin demo.yaml + // plugin pam.yaml demo := `Name: demo Version: 0.0.1 Description: this is a description @@ -178,7 +178,7 @@ Rule: Response: # 替换的响应内容 Body: Append: # 追加字符串` - pluginDemo := options.Proxy.PluginDir + "/" + "demo.yaml" + pluginDemo := options.Proxy.PluginDir + "/" + "pam.yaml" err = ioutil.WriteFile(pluginDemo, []byte(demo), 0755) //nolint: if err != nil { log.Fatal("%s", err.Error()) diff --git a/internal/reverse/response.go b/internal/reverse/response.go index e31241a..26ce516 100644 --- a/internal/reverse/response.go +++ b/internal/reverse/response.go @@ -169,10 +169,11 @@ func (reverse *Reverse) modifyLocationHeader(shost string, response *http.Respon log.Trace("Location: %s", location.String()) target := reverse.AllowSite[shost] targetHost, _ := url.Parse(target) - locationHost, err := utils.Parse(location.String()) + locationHost, err := url.Parse(location.String()) if err != nil { return err } + log.Trace("targetHost.Host:%s, locationHost.Host: %s", targetHost.Host, locationHost.Host) if targetHost.Host == locationHost.Host { location.Scheme = "" @@ -181,7 +182,7 @@ func (reverse *Reverse) modifyLocationHeader(shost string, response *http.Respon log.Trace("url: %s,Location: %s", response.Request.URL, location.String()) } if location.String() == "" { - log.Trace("url: %s,Location is empty", response.Request.URL) + log.Trace("url: %s, Location is empty", response.Request.URL) return nil } response.Header.Set("Location", location.String()) diff --git a/internal/reverse/reverse.go b/internal/reverse/reverse.go index 4a96332..c93c5e7 100644 --- a/internal/reverse/reverse.go +++ b/internal/reverse/reverse.go @@ -77,12 +77,16 @@ func (reverse *Reverse) ServeHTTP(w http.ResponseWriter, r *http.Request) { if utils.EleInArray(r.Method, rp.Request.Method) { log.Info("[plugin:%s.Replace.%s] Method match:%s", rules.Name, rule.URL, rp.Request.Method) //处理响应数据 - if rp.Response.Location != "" { - log.Info("[plugin: %s.Location]: %s", rules.Name, rp.Response.Location) - w.Header().Set("Location", rp.Response.Location) - w.WriteHeader(302) - return + + if rp.Response != nil { + if rp.Response.Location != "" { + log.Info("[plugin: %s.Location]: %s", rules.Name, rp.Response.Location) + w.Header().Set("Location", rp.Response.Location) + w.WriteHeader(302) + return + } } + } } }