diff --git a/build/rpc.json b/build/rpc.json index d82b1ab..27beaf6 100644 --- a/build/rpc.json +++ b/build/rpc.json @@ -14898,7 +14898,7 @@ }, { "name": "CreateHTTPPageRequest", - "code": "message CreateHTTPPageRequest {\n\trepeated string statusList = 1;\n\tstring bodyType = 5;\n\tstring url = 2;\n\tstring body = 4;\n\tint32 newStatus = 3;\n}", + "code": "message CreateHTTPPageRequest {\n\trepeated string statusList = 1; // 状态码列表\n\tstring bodyType = 5; // 页面类型:html|url|redirectURL\n\tstring url = 2; // 读取或者跳转的URL\n\tstring body = 4; // HTML内容\n\tint32 newStatus = 3; // 新的状态码\n\tbytes exceptURLPatternsJSON = 6; // 例外URL列表\n\tbytes onlyURLPatternsJSON = 7; // 限制URL列表\n}", "doc": "创建Page" }, { @@ -21743,7 +21743,7 @@ }, { "name": "UpdateHTTPPageRequest", - "code": "message UpdateHTTPPageRequest {\n\tint64 httpPageId = 1;\n\trepeated string statusList = 2;\n\tstring bodyType = 6;\n\tstring url = 3;\n\tstring body = 5;\n\tint32 newStatus = 4;\n}", + "code": "message UpdateHTTPPageRequest {\n\tint64 httpPageId = 1;\n\trepeated string statusList = 2;\n\tstring bodyType = 6; // 页面类型:html|url|redirectURL\n\tstring url = 3;\n\tstring body = 5;\n\tint32 newStatus = 4;\n\tbytes exceptURLPatternsJSON = 7; // 例外URL列表\n\tbytes onlyURLPatternsJSON = 8; // 限制URL列表\n}", "doc": "修改Page" }, { diff --git a/pkg/rpc/pb/service_http_page.pb.go b/pkg/rpc/pb/service_http_page.pb.go index 1d1603f..606963f 100644 --- a/pkg/rpc/pb/service_http_page.pb.go +++ b/pkg/rpc/pb/service_http_page.pb.go @@ -26,11 +26,13 @@ type CreateHTTPPageRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - StatusList []string `protobuf:"bytes,1,rep,name=statusList,proto3" json:"statusList,omitempty"` - BodyType string `protobuf:"bytes,5,opt,name=bodyType,proto3" json:"bodyType,omitempty"` - Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` - Body string `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` - NewStatus int32 `protobuf:"varint,3,opt,name=newStatus,proto3" json:"newStatus,omitempty"` + StatusList []string `protobuf:"bytes,1,rep,name=statusList,proto3" json:"statusList,omitempty"` // 状态码列表 + BodyType string `protobuf:"bytes,5,opt,name=bodyType,proto3" json:"bodyType,omitempty"` // 页面类型:html|url|redirectURL + Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` // 读取或者跳转的URL + Body string `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"` // HTML内容 + NewStatus int32 `protobuf:"varint,3,opt,name=newStatus,proto3" json:"newStatus,omitempty"` // 新的状态码 + ExceptURLPatternsJSON []byte `protobuf:"bytes,6,opt,name=exceptURLPatternsJSON,proto3" json:"exceptURLPatternsJSON,omitempty"` // 例外URL列表 + OnlyURLPatternsJSON []byte `protobuf:"bytes,7,opt,name=onlyURLPatternsJSON,proto3" json:"onlyURLPatternsJSON,omitempty"` // 限制URL列表 } func (x *CreateHTTPPageRequest) Reset() { @@ -100,6 +102,20 @@ func (x *CreateHTTPPageRequest) GetNewStatus() int32 { return 0 } +func (x *CreateHTTPPageRequest) GetExceptURLPatternsJSON() []byte { + if x != nil { + return x.ExceptURLPatternsJSON + } + return nil +} + +func (x *CreateHTTPPageRequest) GetOnlyURLPatternsJSON() []byte { + if x != nil { + return x.OnlyURLPatternsJSON + } + return nil +} + type CreateHTTPPageResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -153,12 +169,14 @@ type UpdateHTTPPageRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - HttpPageId int64 `protobuf:"varint,1,opt,name=httpPageId,proto3" json:"httpPageId,omitempty"` - StatusList []string `protobuf:"bytes,2,rep,name=statusList,proto3" json:"statusList,omitempty"` - BodyType string `protobuf:"bytes,6,opt,name=bodyType,proto3" json:"bodyType,omitempty"` - Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"` - Body string `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"` - NewStatus int32 `protobuf:"varint,4,opt,name=newStatus,proto3" json:"newStatus,omitempty"` + HttpPageId int64 `protobuf:"varint,1,opt,name=httpPageId,proto3" json:"httpPageId,omitempty"` + StatusList []string `protobuf:"bytes,2,rep,name=statusList,proto3" json:"statusList,omitempty"` + BodyType string `protobuf:"bytes,6,opt,name=bodyType,proto3" json:"bodyType,omitempty"` // 页面类型:html|url|redirectURL + Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"` + Body string `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"` + NewStatus int32 `protobuf:"varint,4,opt,name=newStatus,proto3" json:"newStatus,omitempty"` + ExceptURLPatternsJSON []byte `protobuf:"bytes,7,opt,name=exceptURLPatternsJSON,proto3" json:"exceptURLPatternsJSON,omitempty"` // 例外URL列表 + OnlyURLPatternsJSON []byte `protobuf:"bytes,8,opt,name=onlyURLPatternsJSON,proto3" json:"onlyURLPatternsJSON,omitempty"` // 限制URL列表 } func (x *UpdateHTTPPageRequest) Reset() { @@ -235,6 +253,20 @@ func (x *UpdateHTTPPageRequest) GetNewStatus() int32 { return 0 } +func (x *UpdateHTTPPageRequest) GetExceptURLPatternsJSON() []byte { + if x != nil { + return x.ExceptURLPatternsJSON + } + return nil +} + +func (x *UpdateHTTPPageRequest) GetOnlyURLPatternsJSON() []byte { + if x != nil { + return x.OnlyURLPatternsJSON + } + return nil +} + // 查找单个Page配置 type FindEnabledHTTPPageConfigRequest struct { state protoimpl.MessageState @@ -336,7 +368,7 @@ var file_service_http_page_proto_rawDesc = []byte{ 0x0a, 0x17, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x19, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2f, 0x72, 0x70, 0x63, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x97, 0x01, 0x0a, 0x15, 0x43, 0x72, 0x65, + 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xff, 0x01, 0x0a, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4c, 0x69, @@ -346,22 +378,35 @@ var file_service_http_page_proto_rawDesc = []byte{ 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x6e, 0x65, 0x77, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x22, 0x38, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, - 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x0a, - 0x68, 0x74, 0x74, 0x70, 0x50, 0x61, 0x67, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x50, 0x61, 0x67, 0x65, 0x49, 0x64, 0x22, 0xb7, 0x01, 0x0a, - 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x50, 0x61, 0x67, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x50, 0x61, - 0x67, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x68, 0x74, 0x74, 0x70, - 0x50, 0x61, 0x67, 0x65, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x4c, 0x69, 0x73, 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x6f, 0x64, 0x79, 0x54, 0x79, - 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x6f, 0x64, 0x79, 0x54, 0x79, - 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x75, 0x72, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x6e, 0x65, 0x77, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x42, 0x0a, 0x20, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, + 0x75, 0x73, 0x12, 0x34, 0x0a, 0x15, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x55, 0x52, 0x4c, 0x50, + 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x15, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x55, 0x52, 0x4c, 0x50, 0x61, 0x74, 0x74, + 0x65, 0x72, 0x6e, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x12, 0x30, 0x0a, 0x13, 0x6f, 0x6e, 0x6c, 0x79, + 0x55, 0x52, 0x4c, 0x50, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x13, 0x6f, 0x6e, 0x6c, 0x79, 0x55, 0x52, 0x4c, 0x50, 0x61, + 0x74, 0x74, 0x65, 0x72, 0x6e, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x22, 0x38, 0x0a, 0x16, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x50, 0x61, 0x67, 0x65, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x50, 0x61, + 0x67, 0x65, 0x49, 0x64, 0x22, 0x9f, 0x02, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x48, + 0x54, 0x54, 0x50, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, + 0x0a, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x50, 0x61, 0x67, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x50, 0x61, 0x67, 0x65, 0x49, 0x64, 0x12, 0x1e, + 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x02, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x1a, + 0x0a, 0x08, 0x62, 0x6f, 0x64, 0x79, 0x54, 0x79, 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x62, 0x6f, 0x64, 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, + 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x12, 0x0a, 0x04, + 0x62, 0x6f, 0x64, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, + 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x09, 0x6e, 0x65, 0x77, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x34, + 0x0a, 0x15, 0x65, 0x78, 0x63, 0x65, 0x70, 0x74, 0x55, 0x52, 0x4c, 0x50, 0x61, 0x74, 0x74, 0x65, + 0x72, 0x6e, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x15, 0x65, + 0x78, 0x63, 0x65, 0x70, 0x74, 0x55, 0x52, 0x4c, 0x50, 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x73, + 0x4a, 0x53, 0x4f, 0x4e, 0x12, 0x30, 0x0a, 0x13, 0x6f, 0x6e, 0x6c, 0x79, 0x55, 0x52, 0x4c, 0x50, + 0x61, 0x74, 0x74, 0x65, 0x72, 0x6e, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x13, 0x6f, 0x6e, 0x6c, 0x79, 0x55, 0x52, 0x4c, 0x50, 0x61, 0x74, 0x74, 0x65, 0x72, + 0x6e, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x22, 0x42, 0x0a, 0x20, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x48, 0x54, 0x54, 0x50, 0x50, 0x61, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x68, 0x74, 0x74, 0x70, 0x50, 0x61, 0x67, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, diff --git a/pkg/rpc/protos/service_http_page.proto b/pkg/rpc/protos/service_http_page.proto index 34613de..22e7b53 100644 --- a/pkg/rpc/protos/service_http_page.proto +++ b/pkg/rpc/protos/service_http_page.proto @@ -19,11 +19,13 @@ service HTTPPageService { // 创建Page message CreateHTTPPageRequest { - repeated string statusList = 1; - string bodyType = 5; - string url = 2; - string body = 4; - int32 newStatus = 3; + repeated string statusList = 1; // 状态码列表 + string bodyType = 5; // 页面类型:html|url|redirectURL + string url = 2; // 读取或者跳转的URL + string body = 4; // HTML内容 + int32 newStatus = 3; // 新的状态码 + bytes exceptURLPatternsJSON = 6; // 例外URL列表 + bytes onlyURLPatternsJSON = 7; // 限制URL列表 } message CreateHTTPPageResponse { @@ -34,10 +36,12 @@ message CreateHTTPPageResponse { message UpdateHTTPPageRequest { int64 httpPageId = 1; repeated string statusList = 2; - string bodyType = 6; + string bodyType = 6; // 页面类型:html|url|redirectURL string url = 3; string body = 5; int32 newStatus = 4; + bytes exceptURLPatternsJSON = 7; // 例外URL列表 + bytes onlyURLPatternsJSON = 8; // 限制URL列表 } // 查找单个Page配置 diff --git a/pkg/serverconfigs/http_page_config.go b/pkg/serverconfigs/http_page_config.go index 2d69216..7fd9cbb 100644 --- a/pkg/serverconfigs/http_page_config.go +++ b/pkg/serverconfigs/http_page_config.go @@ -28,7 +28,6 @@ func FindAllHTTPPageBodyTypes() []*shared.Definition { } // HTTPPageConfig 特殊页面配置 -// TODO 需要支持Header定义 type HTTPPageConfig struct { Id int64 `yaml:"id" json:"id"` // 页面ID IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启 TODO @@ -39,6 +38,9 @@ type HTTPPageConfig struct { URL string `yaml:"url" json:"url"` // URL Body string `yaml:"body" json:"body"` // 输出的内容 + OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL + ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL + statusList []*WildcardStatus hasStatusList bool } @@ -57,6 +59,21 @@ func (this *HTTPPageConfig) Init() error { this.statusList = append(this.statusList, NewWildcardStatus(s)) } this.hasStatusList = len(this.statusList) > 0 + + for _, urlPattern := range this.OnlyURLPatterns { + err := urlPattern.Init() + if err != nil { + return err + } + } + + for _, urlPattern := range this.ExceptURLPatterns { + err := urlPattern.Init() + if err != nil { + return err + } + } + return nil } @@ -72,3 +89,25 @@ func (this *HTTPPageConfig) Match(status int) bool { } return false } + +func (this *HTTPPageConfig) MatchURL(url string) bool { + // except + if len(this.ExceptURLPatterns) > 0 { + for _, pattern := range this.ExceptURLPatterns { + if pattern.Match(url) { + return false + } + } + } + + if len(this.OnlyURLPatterns) > 0 { + for _, pattern := range this.OnlyURLPatterns { + if pattern.Match(url) { + return true + } + } + return false + } + + return true +}