Skip to content

Commit 6e3f56c

Browse files
committed
bugfix
1 parent 85e6d8b commit 6e3f56c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

proxy.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,31 @@ func NewProxy() *proxy {
2020

2121
//管理逻辑
2222
func (p *proxy) admin(w http.ResponseWriter, r *http.Request) {
23-
//重置路由表
24-
p.table.DelAll()
2523
data := r.FormValue("data")
26-
var newData = ""
2724
if data != "" {
25+
//重置路由表
26+
p.table.DelAll()
2827
arr := strings.Split(data, "\r\n")
29-
var newArr []string
3028
for _, item := range arr {
3129
d := strings.Split(item, "=>")
30+
if len(d) < 2 {
31+
continue
32+
}
3233
_, err := url.Parse(d[1])
3334
if err != nil {
3435
fmt.Println(err.Error())
3536
continue
3637
}
37-
newArr = append(newArr, item)
3838
fmt.Println(d[0], d[1])
3939
p.table.Set(d[0], d[1])
4040
}
41-
newData = strings.Join(newArr, "\n")
41+
}
42+
var newData string
43+
for service, newUrl := range p.table.GetAll() {
44+
if service == "" {
45+
continue
46+
}
47+
newData = service + "=>" + newUrl
4248
}
4349
w.Header().Set("Content-Type", "text/html;charset=utf-8")
4450
w.Write([]byte("<form method=\"POST\"><center><textarea autofocus name=\"data\" rows=\"30\" cols=\"100\">" + newData + "</textarea><br><input type=\"submit\" value=\"提交\"></center></form>"))
@@ -63,7 +69,7 @@ func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
6369
w.Write([]byte(err.Error()))
6470
return
6571
}
66-
r.URL.Path = strings.TrimLeft(r.URL.Path, "/"+service)
72+
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/"+service)
6773
targetQuery := target.RawQuery
6874
director := func(req *http.Request) {
6975
req.URL.Scheme = target.Scheme

0 commit comments

Comments
 (0)