mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-17 23:50:24 +08:00
实现gzip
This commit is contained in:
@@ -30,12 +30,12 @@ type HTTPGzip struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
IsOn bool `protobuf:"varint,2,opt,name=isOn,proto3" json:"isOn,omitempty"`
|
||||
Level int32 `protobuf:"varint,3,opt,name=level,proto3" json:"level,omitempty"`
|
||||
MinLength *SizeCapacity `protobuf:"bytes,4,opt,name=minLength,proto3" json:"minLength,omitempty"`
|
||||
MaxLength *SizeCapacity `protobuf:"bytes,5,opt,name=maxLength,proto3" json:"maxLength,omitempty"`
|
||||
CondGroupsJSON []byte `protobuf:"bytes,6,opt,name=CondGroupsJSON,proto3" json:"CondGroupsJSON,omitempty"`
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
IsOn bool `protobuf:"varint,2,opt,name=isOn,proto3" json:"isOn,omitempty"`
|
||||
Level int32 `protobuf:"varint,3,opt,name=level,proto3" json:"level,omitempty"`
|
||||
MinLength *SizeCapacity `protobuf:"bytes,4,opt,name=minLength,proto3" json:"minLength,omitempty"`
|
||||
MaxLength *SizeCapacity `protobuf:"bytes,5,opt,name=maxLength,proto3" json:"maxLength,omitempty"`
|
||||
CondsJSON []byte `protobuf:"bytes,6,opt,name=condsJSON,proto3" json:"condsJSON,omitempty"`
|
||||
}
|
||||
|
||||
func (x *HTTPGzip) Reset() {
|
||||
@@ -105,9 +105,9 @@ func (x *HTTPGzip) GetMaxLength() *SizeCapacity {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *HTTPGzip) GetCondGroupsJSON() []byte {
|
||||
func (x *HTTPGzip) GetCondsJSON() []byte {
|
||||
if x != nil {
|
||||
return x.CondGroupsJSON
|
||||
return x.CondsJSON
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -118,7 +118,7 @@ var file_model_http_gzip_proto_rawDesc = []byte{
|
||||
0x0a, 0x15, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x5f, 0x68, 0x74, 0x74, 0x70, 0x5f, 0x67, 0x7a, 0x69,
|
||||
0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x19, 0x6d, 0x6f, 0x64,
|
||||
0x65, 0x6c, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x63, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79,
|
||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xcc, 0x01, 0x0a, 0x08, 0x48, 0x54, 0x54, 0x50, 0x47,
|
||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc2, 0x01, 0x0a, 0x08, 0x48, 0x54, 0x54, 0x50, 0x47,
|
||||
0x7a, 0x69, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52,
|
||||
0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x69, 0x73, 0x4f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x08, 0x52, 0x04, 0x69, 0x73, 0x4f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c,
|
||||
@@ -128,11 +128,10 @@ var file_model_http_gzip_proto_rawDesc = []byte{
|
||||
0x74, 0x79, 0x52, 0x09, 0x6d, 0x69, 0x6e, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x2e, 0x0a,
|
||||
0x09, 0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x32, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x7a, 0x65, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69,
|
||||
0x74, 0x79, 0x52, 0x09, 0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x26, 0x0a,
|
||||
0x0e, 0x43, 0x6f, 0x6e, 0x64, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18,
|
||||
0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x43, 0x6f, 0x6e, 0x64, 0x47, 0x72, 0x6f, 0x75, 0x70,
|
||||
0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x74, 0x79, 0x52, 0x09, 0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x1c, 0x0a,
|
||||
0x09, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c,
|
||||
0x52, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x42, 0x06, 0x5a, 0x04, 0x2e,
|
||||
0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -35,10 +35,10 @@ type CreateHTTPGzipRequest struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Level int32 `protobuf:"varint,1,opt,name=level,proto3" json:"level,omitempty"`
|
||||
MinLength *SizeCapacity `protobuf:"bytes,2,opt,name=minLength,proto3" json:"minLength,omitempty"`
|
||||
MaxLength *SizeCapacity `protobuf:"bytes,3,opt,name=maxLength,proto3" json:"maxLength,omitempty"`
|
||||
CondGroupsJSON []byte `protobuf:"bytes,4,opt,name=condGroupsJSON,proto3" json:"condGroupsJSON,omitempty"`
|
||||
Level int32 `protobuf:"varint,1,opt,name=level,proto3" json:"level,omitempty"`
|
||||
MinLength *SizeCapacity `protobuf:"bytes,2,opt,name=minLength,proto3" json:"minLength,omitempty"`
|
||||
MaxLength *SizeCapacity `protobuf:"bytes,3,opt,name=maxLength,proto3" json:"maxLength,omitempty"`
|
||||
CondsJSON []byte `protobuf:"bytes,4,opt,name=condsJSON,proto3" json:"condsJSON,omitempty"`
|
||||
}
|
||||
|
||||
func (x *CreateHTTPGzipRequest) Reset() {
|
||||
@@ -94,9 +94,9 @@ func (x *CreateHTTPGzipRequest) GetMaxLength() *SizeCapacity {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *CreateHTTPGzipRequest) GetCondGroupsJSON() []byte {
|
||||
func (x *CreateHTTPGzipRequest) GetCondsJSON() []byte {
|
||||
if x != nil {
|
||||
return x.CondGroupsJSON
|
||||
return x.CondsJSON
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -249,11 +249,11 @@ type UpdateHTTPGzipRequest struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
GzipId int64 `protobuf:"varint,1,opt,name=gzipId,proto3" json:"gzipId,omitempty"`
|
||||
Level int32 `protobuf:"varint,2,opt,name=level,proto3" json:"level,omitempty"`
|
||||
MinLength *SizeCapacity `protobuf:"bytes,3,opt,name=minLength,proto3" json:"minLength,omitempty"`
|
||||
MaxLength *SizeCapacity `protobuf:"bytes,4,opt,name=maxLength,proto3" json:"maxLength,omitempty"`
|
||||
CondGroupsJSON []byte `protobuf:"bytes,5,opt,name=condGroupsJSON,proto3" json:"condGroupsJSON,omitempty"`
|
||||
GzipId int64 `protobuf:"varint,1,opt,name=gzipId,proto3" json:"gzipId,omitempty"`
|
||||
Level int32 `protobuf:"varint,2,opt,name=level,proto3" json:"level,omitempty"`
|
||||
MinLength *SizeCapacity `protobuf:"bytes,3,opt,name=minLength,proto3" json:"minLength,omitempty"`
|
||||
MaxLength *SizeCapacity `protobuf:"bytes,4,opt,name=maxLength,proto3" json:"maxLength,omitempty"`
|
||||
CondsJSON []byte `protobuf:"bytes,5,opt,name=condsJSON,proto3" json:"condsJSON,omitempty"`
|
||||
}
|
||||
|
||||
func (x *UpdateHTTPGzipRequest) Reset() {
|
||||
@@ -316,9 +316,9 @@ func (x *UpdateHTTPGzipRequest) GetMaxLength() *SizeCapacity {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *UpdateHTTPGzipRequest) GetCondGroupsJSON() []byte {
|
||||
func (x *UpdateHTTPGzipRequest) GetCondsJSON() []byte {
|
||||
if x != nil {
|
||||
return x.CondGroupsJSON
|
||||
return x.CondsJSON
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -330,7 +330,7 @@ var file_service_http_gzip_proto_rawDesc = []byte{
|
||||
0x7a, 0x69, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x19, 0x6d,
|
||||
0x6f, 0x64, 0x65, 0x6c, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x63, 0x61, 0x70, 0x61, 0x63, 0x69,
|
||||
0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x12, 0x72, 0x70, 0x63, 0x5f, 0x6d, 0x65,
|
||||
0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb5, 0x01, 0x0a,
|
||||
0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xab, 0x01, 0x0a,
|
||||
0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x2e, 0x0a, 0x09,
|
||||
@@ -339,50 +339,49 @@ var file_service_http_gzip_proto_rawDesc = []byte{
|
||||
0x79, 0x52, 0x09, 0x6d, 0x69, 0x6e, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x2e, 0x0a, 0x09,
|
||||
0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x10, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x7a, 0x65, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74,
|
||||
0x79, 0x52, 0x09, 0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x26, 0x0a, 0x0e,
|
||||
0x63, 0x6f, 0x6e, 0x64, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x04,
|
||||
0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x63, 0x6f, 0x6e, 0x64, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x73,
|
||||
0x4a, 0x53, 0x4f, 0x4e, 0x22, 0x30, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54,
|
||||
0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16,
|
||||
0x0a, 0x06, 0x67, 0x7a, 0x69, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06,
|
||||
0x67, 0x7a, 0x69, 0x70, 0x49, 0x64, 0x22, 0x36, 0x0a, 0x1c, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e,
|
||||
0x61, 0x62, 0x6c, 0x65, 0x64, 0x47, 0x7a, 0x69, 0x70, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x7a, 0x69, 0x70, 0x49, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, 0x7a, 0x69, 0x70, 0x49, 0x64, 0x22, 0x3b,
|
||||
0x0a, 0x1d, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x47, 0x7a, 0x69,
|
||||
0x70, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x1a, 0x0a, 0x08, 0x67, 0x7a, 0x69, 0x70, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x0c, 0x52, 0x08, 0x67, 0x7a, 0x69, 0x70, 0x4a, 0x53, 0x4f, 0x4e, 0x22, 0xcd, 0x01, 0x0a, 0x15,
|
||||
0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x7a, 0x69, 0x70, 0x49, 0x64, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, 0x7a, 0x69, 0x70, 0x49, 0x64, 0x12, 0x14, 0x0a,
|
||||
0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x65,
|
||||
0x76, 0x65, 0x6c, 0x12, 0x2e, 0x0a, 0x09, 0x6d, 0x69, 0x6e, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x7a, 0x65,
|
||||
0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x52, 0x09, 0x6d, 0x69, 0x6e, 0x4c, 0x65, 0x6e,
|
||||
0x67, 0x74, 0x68, 0x12, 0x2e, 0x0a, 0x09, 0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68,
|
||||
0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x69, 0x7a, 0x65,
|
||||
0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x52, 0x09, 0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e,
|
||||
0x67, 0x74, 0x68, 0x12, 0x26, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x64, 0x47, 0x72, 0x6f, 0x75, 0x70,
|
||||
0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x63, 0x6f, 0x6e,
|
||||
0x64, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x32, 0xff, 0x01, 0x0a, 0x0f,
|
||||
0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12,
|
||||
0x47, 0x0a, 0x0e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69,
|
||||
0x70, 0x12, 0x19, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54,
|
||||
0x50, 0x47, 0x7a, 0x69, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70,
|
||||
0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x60, 0x0a, 0x19, 0x66, 0x69, 0x6e, 0x64,
|
||||
0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x43,
|
||||
0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x20, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45,
|
||||
0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x47, 0x7a, 0x69, 0x70, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e,
|
||||
0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x47, 0x7a, 0x69, 0x70, 0x43, 0x6f, 0x6e, 0x66,
|
||||
0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0e, 0x75, 0x70,
|
||||
0x64, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x12, 0x19, 0x2e, 0x70,
|
||||
0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x50, 0x43,
|
||||
0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x42, 0x06, 0x5a,
|
||||
0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x79, 0x52, 0x09, 0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x1c, 0x0a, 0x09,
|
||||
0x63, 0x6f, 0x6e, 0x64, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52,
|
||||
0x09, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x22, 0x30, 0x0a, 0x16, 0x43, 0x72,
|
||||
0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x7a, 0x69, 0x70, 0x49, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, 0x7a, 0x69, 0x70, 0x49, 0x64, 0x22, 0x36, 0x0a, 0x1c,
|
||||
0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x47, 0x7a, 0x69, 0x70, 0x43,
|
||||
0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06,
|
||||
0x67, 0x7a, 0x69, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, 0x7a,
|
||||
0x69, 0x70, 0x49, 0x64, 0x22, 0x3b, 0x0a, 0x1d, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62,
|
||||
0x6c, 0x65, 0x64, 0x47, 0x7a, 0x69, 0x70, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73,
|
||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x7a, 0x69, 0x70, 0x4a, 0x53, 0x4f,
|
||||
0x4e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x67, 0x7a, 0x69, 0x70, 0x4a, 0x53, 0x4f,
|
||||
0x4e, 0x22, 0xc3, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50,
|
||||
0x47, 0x7a, 0x69, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x67,
|
||||
0x7a, 0x69, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, 0x7a, 0x69,
|
||||
0x70, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x05, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x2e, 0x0a, 0x09, 0x6d, 0x69, 0x6e,
|
||||
0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70,
|
||||
0x62, 0x2e, 0x53, 0x69, 0x7a, 0x65, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x52, 0x09,
|
||||
0x6d, 0x69, 0x6e, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x2e, 0x0a, 0x09, 0x6d, 0x61, 0x78,
|
||||
0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70,
|
||||
0x62, 0x2e, 0x53, 0x69, 0x7a, 0x65, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x52, 0x09,
|
||||
0x6d, 0x61, 0x78, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e,
|
||||
0x64, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x6f,
|
||||
0x6e, 0x64, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x32, 0xff, 0x01, 0x0a, 0x0f, 0x48, 0x54, 0x54, 0x50,
|
||||
0x47, 0x7a, 0x69, 0x70, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x0e, 0x63,
|
||||
0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x12, 0x19, 0x2e,
|
||||
0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69,
|
||||
0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x72,
|
||||
0x65, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70,
|
||||
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x60, 0x0a, 0x19, 0x66, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62,
|
||||
0x6c, 0x65, 0x64, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x43, 0x6f, 0x6e, 0x66, 0x69,
|
||||
0x67, 0x12, 0x20, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c,
|
||||
0x65, 0x64, 0x47, 0x7a, 0x69, 0x70, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61,
|
||||
0x62, 0x6c, 0x65, 0x64, 0x47, 0x7a, 0x69, 0x70, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65,
|
||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0e, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65,
|
||||
0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x12, 0x19, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x70,
|
||||
0x64, 0x61, 0x74, 0x65, 0x48, 0x54, 0x54, 0x50, 0x47, 0x7a, 0x69, 0x70, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x50, 0x43, 0x55, 0x70, 0x64, 0x61,
|
||||
0x74, 0x65, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70,
|
||||
0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -11,5 +11,5 @@ message HTTPGzip {
|
||||
int32 level = 3;
|
||||
SizeCapacity minLength = 4;
|
||||
SizeCapacity maxLength = 5;
|
||||
bytes CondGroupsJSON = 6;
|
||||
bytes condsJSON = 6;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ message CreateHTTPGzipRequest {
|
||||
int32 level = 1;
|
||||
SizeCapacity minLength = 2;
|
||||
SizeCapacity maxLength = 3;
|
||||
bytes condGroupsJSON = 4;
|
||||
bytes condsJSON = 4;
|
||||
}
|
||||
|
||||
message CreateHTTPGzipResponse {
|
||||
@@ -44,5 +44,5 @@ message UpdateHTTPGzipRequest {
|
||||
int32 level = 2;
|
||||
SizeCapacity minLength = 3;
|
||||
SizeCapacity maxLength = 4;
|
||||
bytes condGroupsJSON = 5;
|
||||
bytes condsJSON = 5;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -14,47 +13,21 @@ import (
|
||||
// 日志存储策略
|
||||
// 存储在configs/accesslog.storage.$id.conf
|
||||
type HTTPAccessLogStoragePolicy struct {
|
||||
Id int64 `yaml:"id" json:"id"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
Type string `yaml:"type" json:"type"` // 存储类型
|
||||
Options map[string]interface{} `yaml:"options" json:"options"` // 存储选项
|
||||
CondGroups []*shared.HTTPRequestCondGroup `yaml:"condGroups" json:"condsGroups"` // 请求条件
|
||||
}
|
||||
|
||||
// 创建新策略
|
||||
func NewHTTPAccessLogStoragePolicy() *HTTPAccessLogStoragePolicy {
|
||||
return &HTTPAccessLogStoragePolicy{
|
||||
IsOn: true,
|
||||
}
|
||||
}
|
||||
|
||||
// 从文件中加载策略
|
||||
func NewAccessLogStoragePolicyFromId(id string) *HTTPAccessLogStoragePolicy {
|
||||
filename := "accesslog.storage." + id + ".conf"
|
||||
data, err := ioutil.ReadFile(Tea.ConfigFile(filename))
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return nil
|
||||
}
|
||||
policy := NewHTTPAccessLogStoragePolicy()
|
||||
err = yaml.Unmarshal(data, policy)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return nil
|
||||
}
|
||||
return policy
|
||||
Id int64 `yaml:"id" json:"id"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
Type string `yaml:"type" json:"type"` // 存储类型
|
||||
Options map[string]interface{} `yaml:"options" json:"options"` // 存储选项
|
||||
Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 请求条件
|
||||
}
|
||||
|
||||
// 校验
|
||||
func (this *HTTPAccessLogStoragePolicy) Init() error {
|
||||
// cond
|
||||
if len(this.CondGroups) > 0 {
|
||||
for _, cond := range this.CondGroups {
|
||||
err := cond.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if this.Conds != nil {
|
||||
err := this.Conds.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,19 +66,6 @@ func (this *HTTPAccessLogStoragePolicy) MatchKeyword(keyword string) (matched bo
|
||||
return
|
||||
}
|
||||
|
||||
// 匹配条件
|
||||
func (this *HTTPAccessLogStoragePolicy) MatchConds(formatter func(string) string) bool {
|
||||
if len(this.CondGroups) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, cond := range this.CondGroups {
|
||||
if !cond.Match(formatter) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 将ID转换为字符串
|
||||
func (this *HTTPAccessLogStoragePolicy) IdString() string {
|
||||
return strconv.FormatInt(this.Id, 10)
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package serverconfigs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/files"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
var accessLogStoragePolicyListFilename = "accesslog.storage.list.conf"
|
||||
|
||||
// 获取共享的存储策略列表
|
||||
func SharedHTTPAccessLogStoragePolicyList() *AccessLogStoragePolicyList {
|
||||
path := Tea.ConfigFile(accessLogStoragePolicyListFilename)
|
||||
file := files.NewFile(path)
|
||||
if !file.Exists() {
|
||||
return &AccessLogStoragePolicyList{}
|
||||
}
|
||||
reader, err := file.Reader()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return &AccessLogStoragePolicyList{}
|
||||
}
|
||||
defer reader.Close()
|
||||
policyList := &AccessLogStoragePolicyList{}
|
||||
err = reader.ReadYAML(policyList)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return policyList
|
||||
}
|
||||
return policyList
|
||||
}
|
||||
|
||||
// 存储策略列表
|
||||
type AccessLogStoragePolicyList struct {
|
||||
Ids []string `yaml:"id" json:"id"`
|
||||
}
|
||||
|
||||
// 添加策略ID
|
||||
func (this *AccessLogStoragePolicyList) AddId(id string) {
|
||||
this.Ids = append(this.Ids, id)
|
||||
}
|
||||
|
||||
// 删除策略ID
|
||||
func (this *AccessLogStoragePolicyList) RemoveId(id string) {
|
||||
result := []string{}
|
||||
for _, id2 := range this.Ids {
|
||||
if id2 == id {
|
||||
continue
|
||||
}
|
||||
result = append(result, id2)
|
||||
}
|
||||
this.Ids = result
|
||||
}
|
||||
|
||||
// 保存
|
||||
func (this *AccessLogStoragePolicyList) Save() error {
|
||||
data, err := yaml.Marshal(this)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(Tea.ConfigFile(accessLogStoragePolicyListFilename), data, 0666)
|
||||
}
|
||||
|
||||
// 查找所有的策略列表
|
||||
func (this *AccessLogStoragePolicyList) FindAllPolicies() []*HTTPAccessLogStoragePolicy {
|
||||
shared.Locker.Lock()
|
||||
defer shared.Locker.Unlock()
|
||||
|
||||
result := []*HTTPAccessLogStoragePolicy{}
|
||||
for _, id := range this.Ids {
|
||||
policy := NewAccessLogStoragePolicyFromId(id)
|
||||
if policy != nil {
|
||||
result = append(result, policy)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -29,7 +29,7 @@ type HTTPCachePolicy struct {
|
||||
SkipResponseSetCookie bool `yaml:"skipSetCookie" json:"skipSetCookie"` // 是否跳过响应的Set-Cookie Header
|
||||
EnableRequestCachePragma bool `yaml:"enableRequestCachePragma" json:"enableRequestCachePragma"` // 是否支持客户端的Pragma: no-cache
|
||||
|
||||
CondGroups []*shared.HTTPRequestCondGroup `yaml:"condGroups" json:"condGroups"`
|
||||
Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 请求条件
|
||||
|
||||
life time.Duration
|
||||
maxSize int64
|
||||
@@ -86,12 +86,10 @@ func (this *HTTPCachePolicy) Init() error {
|
||||
}
|
||||
|
||||
// cond
|
||||
if len(this.CondGroups) > 0 {
|
||||
for _, cond := range this.CondGroups {
|
||||
err := cond.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if this.Conds != nil {
|
||||
err := this.Conds.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package serverconfigs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 默认的文件类型
|
||||
@@ -12,14 +11,15 @@ var (
|
||||
|
||||
// gzip配置
|
||||
type HTTPGzipConfig struct {
|
||||
Id int64 `yaml:"id" json:"id"` // ID
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
Level int8 `yaml:"level" json:"level"` // 1-9
|
||||
MinLength *shared.SizeCapacity `yaml:"minLength" json:"minLength"` // 最小压缩对象比如4m, 24k
|
||||
MaxLength *shared.SizeCapacity `yaml:"maxLength" json:"maxLength"` // 最大压缩对象 TODO 需要实现
|
||||
CondGroups []*shared.HTTPRequestCondGroup `yaml:"condGroups" json:"condGroups"` // 匹配条件
|
||||
Id int64 `yaml:"id" json:"id"` // ID
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
Level int8 `yaml:"level" json:"level"` // 1-9
|
||||
MinLength *shared.SizeCapacity `yaml:"minLength" json:"minLength"` // 最小压缩对象比如4m, 24k
|
||||
MaxLength *shared.SizeCapacity `yaml:"maxLength" json:"maxLength"` // 最大压缩对象
|
||||
Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 匹配条件
|
||||
|
||||
minLength int64
|
||||
maxLength int64
|
||||
mimeTypes []*MimeTypeRule
|
||||
}
|
||||
|
||||
@@ -28,6 +28,16 @@ func (this *HTTPGzipConfig) Init() error {
|
||||
if this.MinLength != nil {
|
||||
this.minLength = this.MinLength.Bytes()
|
||||
}
|
||||
if this.MaxLength != nil {
|
||||
this.maxLength = this.MaxLength.Bytes()
|
||||
}
|
||||
|
||||
if this.Conds != nil {
|
||||
err := this.Conds.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -37,18 +47,7 @@ func (this *HTTPGzipConfig) MinBytes() int64 {
|
||||
return this.minLength
|
||||
}
|
||||
|
||||
// 检查是否匹配Content-Type
|
||||
func (this *HTTPGzipConfig) MatchContentType(contentType string) bool {
|
||||
index := strings.Index(contentType, ";")
|
||||
if index >= 0 {
|
||||
contentType = contentType[:index]
|
||||
}
|
||||
for _, mimeType := range this.mimeTypes {
|
||||
if mimeType.Regexp == nil && contentType == mimeType.Value {
|
||||
return true
|
||||
} else if mimeType.Regexp != nil && mimeType.Regexp.MatchString(contentType) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
// 可压缩最大尺寸
|
||||
func (this *HTTPGzipConfig) MaxBytes() int64 {
|
||||
return this.maxLength
|
||||
}
|
||||
|
||||
@@ -1,43 +1,9 @@
|
||||
package serverconfigs
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGzipConfig_MatchContentType(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
gzip := &HTTPGzipConfig{}
|
||||
a.IsNil(gzip.Init())
|
||||
a.IsTrue(gzip.MatchContentType("text/html"))
|
||||
}
|
||||
|
||||
{
|
||||
gzip := &HTTPGzipConfig{}
|
||||
a.IsNil(gzip.Init())
|
||||
a.IsTrue(gzip.MatchContentType("text/html; charset=utf-8"))
|
||||
}
|
||||
|
||||
{
|
||||
gzip := &HTTPGzipConfig{}
|
||||
gzip.MimeTypes = []string{"text/*"}
|
||||
a.IsNil(gzip.Init())
|
||||
a.IsTrue(gzip.MatchContentType("text/html; charset=utf-8"))
|
||||
}
|
||||
|
||||
{
|
||||
gzip := &HTTPGzipConfig{}
|
||||
gzip.MimeTypes = []string{"text/*"}
|
||||
a.IsNil(gzip.Init())
|
||||
a.IsFalse(gzip.MatchContentType("application/json; charset=utf-8"))
|
||||
}
|
||||
|
||||
{
|
||||
gzip := &HTTPGzipConfig{}
|
||||
gzip.MimeTypes = []string{"text/*", "image/*"}
|
||||
a.IsNil(gzip.Init())
|
||||
a.IsTrue(gzip.MatchContentType("image/jpeg; charset=utf-8"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ type HTTPLocationConfig struct {
|
||||
ReverseProxy *ReverseProxyConfig `yaml:"reverseProxy" json:"reverseProxy"` // 反向代理设置
|
||||
IsBreak bool `yaml:"isBreak" json:"isBreak"` // 终止向下解析
|
||||
Children []*HTTPLocationConfig `yaml:"children" json:"children"` // 子规则
|
||||
CondGroups []*shared.HTTPRequestCondGroup `yaml:"condGroups" json:"condGroups"` // 匹配条件 TODO
|
||||
Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 匹配条件 TODO
|
||||
|
||||
patternType HTTPLocationPatternType // 规则类型:LocationPattern*
|
||||
prefix string // 前缀
|
||||
@@ -66,8 +66,8 @@ func (this *HTTPLocationConfig) Init() error {
|
||||
}
|
||||
|
||||
// conds
|
||||
for _, group := range this.CondGroups {
|
||||
err := group.Init()
|
||||
if this.Conds != nil {
|
||||
err := this.Conds.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -232,16 +232,8 @@ func (this *HTTPLocationConfig) parsePattern() error {
|
||||
// TODO 支持子Location
|
||||
func (this *HTTPLocationConfig) Match(path string, formatter func(source string) string) (vars map[string]string, isMatched bool) {
|
||||
// 判断条件
|
||||
if len(this.CondGroups) > 0 {
|
||||
for _, condGroup := range this.CondGroups {
|
||||
if !condGroup.IsOn {
|
||||
continue
|
||||
}
|
||||
|
||||
if !condGroup.Match(formatter) {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
if this.Conds != nil && !this.Conds.MatchRequest(formatter) {
|
||||
return
|
||||
}
|
||||
|
||||
if this.patternType == HTTPLocationPatternTypePrefix {
|
||||
|
||||
@@ -35,7 +35,7 @@ type HTTPRewriteRule struct {
|
||||
// - cond ${status} gte 200
|
||||
// - cond ${arg.name} eq lily
|
||||
// - cond ${requestPath} regexp .*\.png
|
||||
CondGroups []*shared.HTTPRequestCondGroup `yaml:"condGroups" json:"condGroups"` // 匹配条件 TODO
|
||||
Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 匹配条件 TODO
|
||||
|
||||
// 规则
|
||||
// 语法为:pattern regexp 比如:
|
||||
@@ -73,8 +73,8 @@ func (this *HTTPRewriteRule) Init() error {
|
||||
this.reg = reg
|
||||
|
||||
// 校验条件
|
||||
for _, condGroup := range this.CondGroups {
|
||||
err := condGroup.Init()
|
||||
if this.Conds != nil {
|
||||
err := this.Conds.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func (this *HTTPRewriteRule) Init() error {
|
||||
}
|
||||
|
||||
// 对某个请求执行规则
|
||||
func (this *HTTPRewriteRule) Match(requestPath string, formatter func(source string) string) (replace string, varMapping map[string]string, matched bool) {
|
||||
func (this *HTTPRewriteRule) MatchRequest(requestPath string, formatter func(source string) string) (replace string, varMapping map[string]string, matched bool) {
|
||||
if this.reg == nil {
|
||||
return "", nil, false
|
||||
}
|
||||
@@ -95,12 +95,8 @@ func (this *HTTPRewriteRule) Match(requestPath string, formatter func(source str
|
||||
}
|
||||
|
||||
// 判断条件
|
||||
if len(this.CondGroups) > 0 {
|
||||
for _, cond := range this.CondGroups {
|
||||
if !cond.Match(formatter) {
|
||||
return "", nil, false
|
||||
}
|
||||
}
|
||||
if this.Conds != nil && !this.Conds.MatchRequest(formatter) {
|
||||
return "", nil, false
|
||||
}
|
||||
|
||||
varMapping = map[string]string{}
|
||||
|
||||
@@ -2,8 +2,6 @@ package serverconfigs
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"github.com/iwind/TeaGo/utils/string"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -18,21 +16,19 @@ func TestHTTPRewriteRule(t *testing.T) {
|
||||
a.IsNil(rule.Init())
|
||||
|
||||
{
|
||||
_, _, b := rule.Match("/hello/worl", func(source string) string {
|
||||
replace, _, b := rule.MatchRequest("/hello/worl", func(source string) string {
|
||||
return source
|
||||
})
|
||||
a.IsFalse(b)
|
||||
a.Log("proxy:", rule.TargetProxy())
|
||||
a.Log("url:", rule.TargetURL())
|
||||
a.Log("url:", replace)
|
||||
}
|
||||
|
||||
{
|
||||
_, _, b := rule.Match("/hello/world", func(source string) string {
|
||||
replace, _, b := rule.MatchRequest("/hello/world", func(source string) string {
|
||||
return source
|
||||
})
|
||||
a.IsTrue(b)
|
||||
a.Log("proxy:", rule.TargetProxy())
|
||||
a.Log("url:", rule.TargetURL())
|
||||
a.Log("url:", replace)
|
||||
}
|
||||
|
||||
{
|
||||
@@ -43,7 +39,7 @@ func TestHTTPRewriteRule(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
u, _, b := r.Match("/hello", func(source string) string {
|
||||
u, _, b := r.MatchRequest("/hello", func(source string) string {
|
||||
return source
|
||||
})
|
||||
a.Log(b)
|
||||
@@ -63,7 +59,7 @@ func TestRewriteRule_NamedMatch(t *testing.T) {
|
||||
before := time.Now()
|
||||
count := 100
|
||||
for i := 0; i < count; i++ {
|
||||
s, _, b := r.Match("/hello/world/ni", func(source string) string {
|
||||
s, _, b := r.MatchRequest("/hello/world/ni", func(source string) string {
|
||||
return source
|
||||
})
|
||||
if i == 0 {
|
||||
@@ -77,53 +73,6 @@ func TestRewriteRule_NamedMatch(t *testing.T) {
|
||||
t.Log(float64(count) / (time.Since(before).Seconds()))
|
||||
}
|
||||
|
||||
func TestRewriteRule_NamedMatchConcurrent(t *testing.T) {
|
||||
r := &HTTPRewriteRule{}
|
||||
r.Replace = "http://127.0.0.1/${1}/${last}/${ni}"
|
||||
r.Pattern = "/(\\w+)/(?P<last>\\w+)/(?P<ni>\\w+)"
|
||||
err := r.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
threads := 1000
|
||||
count := 1000
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(threads * count)
|
||||
fails := 0
|
||||
var locker sync.Mutex
|
||||
for i := 0; i < threads; i++ {
|
||||
go func() {
|
||||
for j := 0; j < count; j++ {
|
||||
func() {
|
||||
defer wg.Done()
|
||||
|
||||
var randomString = stringutil.Rand(16)
|
||||
|
||||
replace, _, b := r.Match("/hello/world/"+randomString, func(source string) string {
|
||||
return source
|
||||
})
|
||||
if !b {
|
||||
locker.Lock()
|
||||
fails++
|
||||
locker.Unlock()
|
||||
} else if replace != "http://127.0.0.1/hello/world/"+randomString {
|
||||
locker.Lock()
|
||||
fails++
|
||||
locker.Unlock()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
if fails > 0 {
|
||||
t.Log("fail")
|
||||
} else {
|
||||
t.Log("success")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteRule_CaseInsensitive(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
@@ -134,12 +83,12 @@ func TestRewriteRule_CaseInsensitive(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _, ok := r.Match("/index.php", func(source string) string {
|
||||
_, _, ok := r.MatchRequest("/index.php", func(source string) string {
|
||||
return source
|
||||
})
|
||||
a.IsTrue(ok)
|
||||
|
||||
_, _, ok = r.Match("/INDEX.php", func(source string) string {
|
||||
_, _, ok = r.MatchRequest("/INDEX.php", func(source string) string {
|
||||
return source
|
||||
})
|
||||
a.IsTrue(ok)
|
||||
@@ -155,7 +104,7 @@ func TestRewriteRule_Slashes(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
replace, _, ok := r.Match("/index.php", func(source string) string {
|
||||
replace, _, ok := r.MatchRequest("/index.php", func(source string) string {
|
||||
return source
|
||||
})
|
||||
a.IsTrue(ok)
|
||||
@@ -167,14 +116,13 @@ func TestRewriteRuleProxy(t *testing.T) {
|
||||
|
||||
rule := &HTTPRewriteRule{
|
||||
Pattern: "/(hello)/(world)",
|
||||
Replace: "proxy://lb001/${1}/${2}",
|
||||
Replace: "/${1}/${2}",
|
||||
}
|
||||
a.IsNil(rule.Init())
|
||||
|
||||
replace, _, b := rule.Match("/hello/world", func(source string) string {
|
||||
replace, _, b := rule.MatchRequest("/hello/world", func(source string) string {
|
||||
return source
|
||||
})
|
||||
a.IsTrue(b)
|
||||
a.IsTrue(rule.TargetProxy() == "lb001")
|
||||
a.IsTrue(replace == "/hello/world")
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ import (
|
||||
|
||||
// 重写条件定义
|
||||
type HTTPRequestCond struct {
|
||||
Type string `yaml:"type" json:"type"` // 类型,在特殊条件时使用
|
||||
Type string `yaml:"type" json:"type"` // 类型,在特殊条件时使用
|
||||
IsRequest bool `yaml:"isRequest" json:"isRequest"` // 是否为请求的条件,用来区分在什么阶段执行
|
||||
|
||||
// 要测试的字符串
|
||||
// 其中可以使用跟请求相关的参数,比如:
|
||||
|
||||
@@ -7,26 +7,48 @@ type HTTPRequestCondGroup struct {
|
||||
Conds []*HTTPRequestCond `yaml:"conds" json:"conds"` // 条件列表
|
||||
IsReverse bool `yaml:"isReverse" json:"isReverse"` // 是否反向匹配
|
||||
Description string `yaml:"description" json:"description"` // 说明
|
||||
|
||||
requestConds []*HTTPRequestCond
|
||||
responseConds []*HTTPRequestCond
|
||||
}
|
||||
|
||||
// 初始化
|
||||
func (this *HTTPRequestCondGroup) Init() error {
|
||||
if len(this.Connector) == 0 {
|
||||
this.Connector = "or"
|
||||
}
|
||||
|
||||
if len(this.Conds) > 0 {
|
||||
for _, cond := range this.Conds {
|
||||
err := cond.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cond.IsRequest {
|
||||
this.requestConds = append(this.requestConds, cond)
|
||||
} else {
|
||||
this.responseConds = append(this.responseConds, cond)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *HTTPRequestCondGroup) Match(formatter func(source string) string) bool {
|
||||
if !this.IsOn {
|
||||
func (this *HTTPRequestCondGroup) MatchRequest(formatter func(source string) string) bool {
|
||||
return this.match(this.requestConds, formatter)
|
||||
}
|
||||
|
||||
func (this *HTTPRequestCondGroup) MatchResponse(formatter func(source string) string) bool {
|
||||
return this.match(this.responseConds, formatter)
|
||||
}
|
||||
|
||||
func (this *HTTPRequestCondGroup) match(conds []*HTTPRequestCond, formatter func(source string) string) bool {
|
||||
if !this.IsOn || len(conds) == 0 {
|
||||
return !this.IsReverse
|
||||
}
|
||||
for _, cond := range this.Conds {
|
||||
ok := false
|
||||
for _, cond := range conds {
|
||||
isMatched := cond.Match(formatter)
|
||||
if this.Connector == "or" && isMatched {
|
||||
return !this.IsReverse
|
||||
@@ -34,6 +56,13 @@ func (this *HTTPRequestCondGroup) Match(formatter func(source string) string) bo
|
||||
if this.Connector == "and" && !isMatched {
|
||||
return this.IsReverse
|
||||
}
|
||||
if isMatched {
|
||||
// 对于OR来说至少要有一个返回true
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
return !this.IsReverse
|
||||
if this.IsReverse {
|
||||
return !ok
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
141
pkg/serverconfigs/shared/http_request_cond_group_test.go
Normal file
141
pkg/serverconfigs/shared/http_request_cond_group_test.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHTTPRequestCondGroup_MatchRequest(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
group := &HTTPRequestCondGroup{}
|
||||
group.Connector = "or"
|
||||
group.IsOn = false
|
||||
err := group.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsTrue(group.MatchRequest(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
a.IsTrue(group.MatchResponse(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
}
|
||||
|
||||
{
|
||||
group := &HTTPRequestCondGroup{}
|
||||
group.IsOn = true
|
||||
err := group.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsTrue(group.MatchRequest(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
a.IsTrue(group.MatchResponse(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
}
|
||||
|
||||
{
|
||||
group := &HTTPRequestCondGroup{}
|
||||
group.IsOn = true
|
||||
group.Connector = "or"
|
||||
group.Conds = []*HTTPRequestCond{
|
||||
{
|
||||
IsRequest: true,
|
||||
Param: "456",
|
||||
Operator: "gt",
|
||||
Value: "123",
|
||||
},
|
||||
{
|
||||
IsRequest: false,
|
||||
Param: "123",
|
||||
Operator: "gt",
|
||||
Value: "456",
|
||||
},
|
||||
}
|
||||
err := group.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsTrue(group.MatchRequest(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
a.IsFalse(group.MatchResponse(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
}
|
||||
{
|
||||
group := &HTTPRequestCondGroup{}
|
||||
group.IsOn = true
|
||||
group.Connector = "or"
|
||||
group.Conds = []*HTTPRequestCond{
|
||||
{
|
||||
IsRequest: true,
|
||||
Param: "456",
|
||||
Operator: "gt",
|
||||
Value: "1234",
|
||||
},
|
||||
{
|
||||
IsRequest: true,
|
||||
Param: "456",
|
||||
Operator: "gt",
|
||||
Value: "123",
|
||||
},
|
||||
{
|
||||
IsRequest: false,
|
||||
Param: "123",
|
||||
Operator: "gt",
|
||||
Value: "456",
|
||||
},
|
||||
}
|
||||
err := group.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsTrue(group.MatchRequest(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
a.IsFalse(group.MatchResponse(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
}
|
||||
{
|
||||
group := &HTTPRequestCondGroup{}
|
||||
group.IsOn = true
|
||||
group.Connector = "and"
|
||||
group.Conds = []*HTTPRequestCond{
|
||||
{
|
||||
IsRequest: true,
|
||||
Param: "456",
|
||||
Operator: "gt",
|
||||
Value: "123",
|
||||
},
|
||||
{
|
||||
IsRequest: true,
|
||||
Param: "456",
|
||||
Operator: "gt",
|
||||
Value: "1234",
|
||||
},
|
||||
{
|
||||
IsRequest: false,
|
||||
Param: "123",
|
||||
Operator: "gt",
|
||||
Value: "456",
|
||||
},
|
||||
}
|
||||
err := group.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsFalse(group.MatchRequest(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
a.IsFalse(group.MatchResponse(func(source string) string {
|
||||
return source
|
||||
}))
|
||||
}
|
||||
}
|
||||
69
pkg/serverconfigs/shared/http_request_conds_config.go
Normal file
69
pkg/serverconfigs/shared/http_request_conds_config.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package shared
|
||||
|
||||
// 条件配置
|
||||
// 数据结构:conds -> []groups -> []cond
|
||||
type HTTPRequestCondsConfig struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
Connector string `yaml:"connector" json:"connector"`
|
||||
Groups []*HTTPRequestCondGroup `yaml:"groups" json:"groups"`
|
||||
}
|
||||
|
||||
// 初始化
|
||||
func (this *HTTPRequestCondsConfig) Init() error {
|
||||
if len(this.Connector) == 0 {
|
||||
this.Connector = "or"
|
||||
}
|
||||
|
||||
for _, group := range this.Groups {
|
||||
err := group.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 判断请求是否匹配
|
||||
func (this *HTTPRequestCondsConfig) MatchRequest(formatter func(s string) string) bool {
|
||||
if !this.IsOn && len(this.Groups) == 0 {
|
||||
return true
|
||||
}
|
||||
ok := false
|
||||
for _, group := range this.Groups {
|
||||
b := group.MatchRequest(formatter)
|
||||
if !b && this.Connector == "and" {
|
||||
return false
|
||||
}
|
||||
if b && this.Connector == "or" {
|
||||
return true
|
||||
}
|
||||
if b {
|
||||
// 对于 or 来说至少有一个分组要返回 true
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
// 判断响应是否匹配
|
||||
func (this *HTTPRequestCondsConfig) MatchResponse(formatter func(s string) string) bool {
|
||||
if !this.IsOn && len(this.Groups) == 0 {
|
||||
return true
|
||||
}
|
||||
ok := false
|
||||
for _, group := range this.Groups {
|
||||
b := group.MatchResponse(formatter)
|
||||
if !b && this.Connector == "and" {
|
||||
return false
|
||||
}
|
||||
if b && this.Connector == "or" {
|
||||
return true
|
||||
}
|
||||
if b {
|
||||
// 对于 or 来说至少有一个分组要返回 true
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
return ok
|
||||
}
|
||||
Reference in New Issue
Block a user