Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 0fee13a

Browse files
committed
[proxy]路径规则增加"是否终止往下匹配"选项
1 parent 922ba71 commit 0fee13a

6 files changed

Lines changed: 31 additions & 9 deletions

File tree

teaconfigs/location.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ type LocationConfig struct {
7070
// - cond ${requestPath} regexp .*\.png
7171
Cond []*shared.RequestCond `yaml:"cond" json:"cond"`
7272

73+
IsBreak bool `yaml:"isBreak" json:"isBreak"` // 终止向下解析
74+
7375
Pages []*PageConfig `yaml:"pages" json:"pages"` // 特殊页
7476
Shutdown *ShutdownConfig `yaml:"shutdown" json:"shutdown"` // 关闭页
7577
ShutdownPageOn1 bool `yaml:"shutdownPageOn" json:"shutdownPageOn"` // deprecated: v0.1.8, 是否开启临时关闭页面

teaproxy/request.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ func (this *Request) configure(server *teaconfigs.ServerConfig, redirects int, b
558558
this.locationContext = nil
559559
return nil
560560
}
561+
562+
// break
563+
if location.IsBreak {
564+
break
565+
}
561566
}
562567
this.locationContext = nil
563568
}

teaweb/actions/default/proxy/locations/add.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ func (this *AddAction) Run(params struct {
6666

6767
// 保存提交
6868
func (this *AddAction) RunPost(params struct {
69-
ServerId string
70-
Name string
71-
Pattern string
72-
PatternType int
69+
ServerId string
70+
Name string
71+
Pattern string
72+
PatternType int
73+
74+
IsBreak bool
75+
7376
Root string
7477
Charset string
7578
Index []string
@@ -129,6 +132,7 @@ func (this *AddAction) RunPost(params struct {
129132

130133
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
131134
location.On = params.On
135+
location.IsBreak = params.IsBreak
132136
location.CacheOn = true
133137
location.Name = params.Name
134138
location.Root = params.Root

teaweb/actions/default/proxy/locations/detail.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func (this *DetailAction) Run(params struct {
2828
"type": location.PatternType(),
2929
"pattern": location.PatternString(),
3030
"name": location.Name,
31+
"isBreak": location.IsBreak,
3132
"caseInsensitive": location.IsCaseInsensitive(),
3233
"reverse": location.IsReverse(),
3334
"root": location.Root,

teaweb/actions/default/proxy/locations/index.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package locations
33
import (
44
"github.com/TeaWeb/code/teaconfigs"
55
"github.com/iwind/TeaGo/actions"
6+
"github.com/iwind/TeaGo/logs"
67
"github.com/iwind/TeaGo/maps"
78
)
89

@@ -22,14 +23,18 @@ func (this *IndexAction) Run(params struct {
2223

2324
locations := []maps.Map{}
2425
for _, location := range server.Locations {
25-
location.Validate()
26+
err := location.Validate()
27+
if err != nil {
28+
logs.Error(err)
29+
}
2630
locations = append(locations, maps.Map{
2731
"on": location.On,
2832
"id": location.Id,
2933
"name": location.Name,
3034
"type": location.PatternType(),
3135
"pattern": location.PatternString(),
3236
"patternTypeName": teaconfigs.FindLocationPatternTypeName(location.PatternType()),
37+
"isBreak": location.IsBreak,
3338
"isCaseInsensitive": location.IsCaseInsensitive(),
3439
"isReverse": location.IsReverse(),
3540
"rewrite": location.Rewrite,

teaweb/actions/default/proxy/locations/update.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (this *UpdateAction) Run(params struct {
6060
"pattern": location.PatternString(),
6161
"type": location.PatternType(),
6262
"name": location.Name,
63+
"isBreak": location.IsBreak,
6364
"isReverse": location.IsReverse(),
6465
"isCaseInsensitive": location.IsCaseInsensitive(),
6566
"root": location.Root,
@@ -104,10 +105,13 @@ func (this *UpdateAction) Run(params struct {
104105

105106
// 保存修改
106107
func (this *UpdateAction) RunPost(params struct {
107-
ServerId string
108-
LocationId string
109-
Pattern string
110-
PatternType int
108+
ServerId string
109+
LocationId string
110+
Pattern string
111+
PatternType int
112+
113+
IsBreak bool
114+
111115
Name string
112116
Root string
113117
URLPrefix string `alias:"urlPrefix"`
@@ -170,6 +174,7 @@ func (this *UpdateAction) RunPost(params struct {
170174

171175
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
172176
location.On = params.On
177+
location.IsBreak = params.IsBreak
173178
location.Name = params.Name
174179
location.Root = params.Root
175180
location.URLPrefix = params.URLPrefix

0 commit comments

Comments
 (0)