From 58f6b28d292896f014f35021e5b7a42d82a08b0e Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 27 Sep 2020 10:03:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8D=E5=90=91=E4=BB=A3=E7=90=86=E6=94=AF?= =?UTF-8?q?=E6=8C=81RequestPath=E3=80=81RequestURI=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/rpc/pb/service_reverse_proxy.pb.go | 182 ++++++++++++--------- pkg/rpc/protos/service_reverse_proxy.proto | 8 +- pkg/serverconfigs/http_root_config.go | 2 +- pkg/serverconfigs/reverse_proxy_config.go | 21 ++- 4 files changed, 127 insertions(+), 86 deletions(-) diff --git a/pkg/rpc/pb/service_reverse_proxy.pb.go b/pkg/rpc/pb/service_reverse_proxy.pb.go index fc53055..72fa321 100644 --- a/pkg/rpc/pb/service_reverse_proxy.pb.go +++ b/pkg/rpc/pb/service_reverse_proxy.pb.go @@ -499,17 +499,19 @@ func (x *UpdateReverseProxyBackupOriginsRequest) GetOriginsJSON() []byte { } // 修改是否启用 -type UpdateReverseProxyIsOnRequest struct { +type UpdateReverseProxyRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ReverseProxyId int64 `protobuf:"varint,1,opt,name=reverseProxyId,proto3" json:"reverseProxyId,omitempty"` - IsOn bool `protobuf:"varint,2,opt,name=isOn,proto3" json:"isOn,omitempty"` + ReverseProxyId int64 `protobuf:"varint,1,opt,name=reverseProxyId,proto3" json:"reverseProxyId,omitempty"` + RequestHost string `protobuf:"bytes,2,opt,name=requestHost,proto3" json:"requestHost,omitempty"` + RequestURI string `protobuf:"bytes,3,opt,name=requestURI,proto3" json:"requestURI,omitempty"` + StripPrefix string `protobuf:"bytes,4,opt,name=stripPrefix,proto3" json:"stripPrefix,omitempty"` } -func (x *UpdateReverseProxyIsOnRequest) Reset() { - *x = UpdateReverseProxyIsOnRequest{} +func (x *UpdateReverseProxyRequest) Reset() { + *x = UpdateReverseProxyRequest{} if protoimpl.UnsafeEnabled { mi := &file_service_reverse_proxy_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -517,13 +519,13 @@ func (x *UpdateReverseProxyIsOnRequest) Reset() { } } -func (x *UpdateReverseProxyIsOnRequest) String() string { +func (x *UpdateReverseProxyRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*UpdateReverseProxyIsOnRequest) ProtoMessage() {} +func (*UpdateReverseProxyRequest) ProtoMessage() {} -func (x *UpdateReverseProxyIsOnRequest) ProtoReflect() protoreflect.Message { +func (x *UpdateReverseProxyRequest) ProtoReflect() protoreflect.Message { mi := &file_service_reverse_proxy_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -535,23 +537,37 @@ func (x *UpdateReverseProxyIsOnRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use UpdateReverseProxyIsOnRequest.ProtoReflect.Descriptor instead. -func (*UpdateReverseProxyIsOnRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use UpdateReverseProxyRequest.ProtoReflect.Descriptor instead. +func (*UpdateReverseProxyRequest) Descriptor() ([]byte, []int) { return file_service_reverse_proxy_proto_rawDescGZIP(), []int{9} } -func (x *UpdateReverseProxyIsOnRequest) GetReverseProxyId() int64 { +func (x *UpdateReverseProxyRequest) GetReverseProxyId() int64 { if x != nil { return x.ReverseProxyId } return 0 } -func (x *UpdateReverseProxyIsOnRequest) GetIsOn() bool { +func (x *UpdateReverseProxyRequest) GetRequestHost() string { if x != nil { - return x.IsOn + return x.RequestHost } - return false + return "" +} + +func (x *UpdateReverseProxyRequest) GetRequestURI() string { + if x != nil { + return x.RequestURI + } + return "" +} + +func (x *UpdateReverseProxyRequest) GetStripPrefix() string { + if x != nil { + return x.StripPrefix + } + return "" } var File_service_reverse_proxy_proto protoreflect.FileDescriptor @@ -619,58 +635,62 @@ var file_service_reverse_proxy_proto_rawDesc = []byte{ 0x52, 0x0e, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x73, 0x4a, 0x53, 0x4f, 0x4e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x73, 0x4a, 0x53, - 0x4f, 0x4e, 0x22, 0x5b, 0x0a, 0x1d, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, - 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x49, 0x73, 0x4f, 0x6e, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0e, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, - 0x6f, 0x78, 0x79, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x72, 0x65, 0x76, - 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x69, - 0x73, 0x4f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x69, 0x73, 0x4f, 0x6e, 0x32, - 0xc2, 0x05, 0x0a, 0x13, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x53, 0x0a, 0x12, 0x63, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x1d, 0x2e, - 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, - 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x70, - 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, - 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x62, 0x0a, 0x17, - 0x66, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, 0x72, - 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x22, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e, + 0x4f, 0x4e, 0x22, 0xa7, 0x01, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, + 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x26, 0x0a, 0x0e, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x72, 0x65, 0x76, 0x65, 0x72, 0x73, + 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x72, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x48, 0x6f, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x72, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x55, 0x52, 0x49, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x55, 0x52, 0x49, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x74, + 0x72, 0x69, 0x70, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x73, 0x74, 0x72, 0x69, 0x70, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x32, 0xba, 0x05, 0x0a, + 0x13, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x53, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x12, 0x53, 0x0a, 0x12, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x12, 0x1d, 0x2e, 0x70, 0x62, 0x2e, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, + 0x78, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x70, 0x62, 0x2e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, + 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x62, 0x0a, 0x17, 0x66, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, - 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x70, 0x62, - 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, - 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x74, 0x0a, 0x1d, 0x66, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, + 0x72, 0x6f, 0x78, 0x79, 0x12, 0x22, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, + 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, + 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, + 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, + 0x50, 0x72, 0x6f, 0x78, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x74, 0x0a, + 0x1d, 0x66, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, + 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x28, + 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x12, 0x28, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, - 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x43, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x62, - 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, - 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, 0x1c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x53, 0x63, 0x68, 0x65, - 0x64, 0x75, 0x6c, 0x69, 0x6e, 0x67, 0x12, 0x27, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x53, 0x63, - 0x68, 0x65, 0x64, 0x75, 0x6c, 0x69, 0x6e, 0x67, 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, 0x12, 0x65, 0x0a, 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, - 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x69, 0x6d, 0x61, - 0x72, 0x79, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x73, 0x12, 0x2b, 0x2e, 0x70, 0x62, 0x2e, 0x55, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, - 0x79, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x73, 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, 0x12, 0x63, 0x0a, 0x1f, - 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, - 0x78, 0x79, 0x42, 0x61, 0x63, 0x6b, 0x75, 0x70, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x73, 0x12, - 0x2a, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, - 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x42, 0x61, 0x63, 0x6b, 0x75, 0x70, 0x4f, 0x72, 0x69, - 0x67, 0x69, 0x6e, 0x73, 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, 0x12, 0x51, 0x0a, 0x16, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, - 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x49, 0x73, 0x4f, 0x6e, 0x12, 0x21, 0x2e, 0x70, 0x62, - 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, - 0x6f, 0x78, 0x79, 0x49, 0x73, 0x4f, 0x6e, 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, + 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, + 0x6e, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, + 0x50, 0x72, 0x6f, 0x78, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, 0x1c, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, + 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x53, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, + 0x69, 0x6e, 0x67, 0x12, 0x27, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, + 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x53, 0x63, 0x68, 0x65, 0x64, + 0x75, 0x6c, 0x69, 0x6e, 0x67, 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, 0x12, 0x65, 0x0a, 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, + 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x4f, + 0x72, 0x69, 0x67, 0x69, 0x6e, 0x73, 0x12, 0x2b, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, + 0x69, 0x6d, 0x61, 0x72, 0x79, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x73, 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, 0x12, 0x63, 0x0a, 0x1f, 0x75, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x42, + 0x61, 0x63, 0x6b, 0x75, 0x70, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x73, 0x12, 0x2a, 0x2e, 0x70, + 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, + 0x72, 0x6f, 0x78, 0x79, 0x42, 0x61, 0x63, 0x6b, 0x75, 0x70, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, + 0x73, 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, 0x12, 0x49, + 0x0a, 0x12, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, + 0x72, 0x6f, 0x78, 0x79, 0x12, 0x1d, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x52, 0x65, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x78, 0x79, 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 ( @@ -696,7 +716,7 @@ var file_service_reverse_proxy_proto_goTypes = []interface{}{ (*UpdateReverseProxySchedulingRequest)(nil), // 6: pb.UpdateReverseProxySchedulingRequest (*UpdateReverseProxyPrimaryOriginsRequest)(nil), // 7: pb.UpdateReverseProxyPrimaryOriginsRequest (*UpdateReverseProxyBackupOriginsRequest)(nil), // 8: pb.UpdateReverseProxyBackupOriginsRequest - (*UpdateReverseProxyIsOnRequest)(nil), // 9: pb.UpdateReverseProxyIsOnRequest + (*UpdateReverseProxyRequest)(nil), // 9: pb.UpdateReverseProxyRequest (*ReverseProxy)(nil), // 10: pb.ReverseProxy (*RPCUpdateSuccess)(nil), // 11: pb.RPCUpdateSuccess } @@ -708,14 +728,14 @@ var file_service_reverse_proxy_proto_depIdxs = []int32{ 6, // 4: pb.ReverseProxyService.updateReverseProxyScheduling:input_type -> pb.UpdateReverseProxySchedulingRequest 7, // 5: pb.ReverseProxyService.updateReverseProxyPrimaryOrigins:input_type -> pb.UpdateReverseProxyPrimaryOriginsRequest 8, // 6: pb.ReverseProxyService.updateReverseProxyBackupOrigins:input_type -> pb.UpdateReverseProxyBackupOriginsRequest - 9, // 7: pb.ReverseProxyService.updateReverseProxyIsOn:input_type -> pb.UpdateReverseProxyIsOnRequest + 9, // 7: pb.ReverseProxyService.updateReverseProxy:input_type -> pb.UpdateReverseProxyRequest 1, // 8: pb.ReverseProxyService.createReverseProxy:output_type -> pb.CreateReverseProxyResponse 3, // 9: pb.ReverseProxyService.findEnabledReverseProxy:output_type -> pb.FindEnabledReverseProxyResponse 5, // 10: pb.ReverseProxyService.findEnabledReverseProxyConfig:output_type -> pb.FindEnabledReverseProxyConfigResponse 11, // 11: pb.ReverseProxyService.updateReverseProxyScheduling:output_type -> pb.RPCUpdateSuccess 11, // 12: pb.ReverseProxyService.updateReverseProxyPrimaryOrigins:output_type -> pb.RPCUpdateSuccess 11, // 13: pb.ReverseProxyService.updateReverseProxyBackupOrigins:output_type -> pb.RPCUpdateSuccess - 11, // 14: pb.ReverseProxyService.updateReverseProxyIsOn:output_type -> pb.RPCUpdateSuccess + 11, // 14: pb.ReverseProxyService.updateReverseProxy:output_type -> pb.RPCUpdateSuccess 8, // [8:15] is the sub-list for method output_type 1, // [1:8] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name @@ -840,7 +860,7 @@ func file_service_reverse_proxy_proto_init() { } } file_service_reverse_proxy_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*UpdateReverseProxyIsOnRequest); i { + switch v := v.(*UpdateReverseProxyRequest); i { case 0: return &v.state case 1: @@ -897,7 +917,7 @@ type ReverseProxyServiceClient interface { // 修改备用源站信息 UpdateReverseProxyBackupOrigins(ctx context.Context, in *UpdateReverseProxyBackupOriginsRequest, opts ...grpc.CallOption) (*RPCUpdateSuccess, error) // 修改是否启用 - UpdateReverseProxyIsOn(ctx context.Context, in *UpdateReverseProxyIsOnRequest, opts ...grpc.CallOption) (*RPCUpdateSuccess, error) + UpdateReverseProxy(ctx context.Context, in *UpdateReverseProxyRequest, opts ...grpc.CallOption) (*RPCUpdateSuccess, error) } type reverseProxyServiceClient struct { @@ -962,9 +982,9 @@ func (c *reverseProxyServiceClient) UpdateReverseProxyBackupOrigins(ctx context. return out, nil } -func (c *reverseProxyServiceClient) UpdateReverseProxyIsOn(ctx context.Context, in *UpdateReverseProxyIsOnRequest, opts ...grpc.CallOption) (*RPCUpdateSuccess, error) { +func (c *reverseProxyServiceClient) UpdateReverseProxy(ctx context.Context, in *UpdateReverseProxyRequest, opts ...grpc.CallOption) (*RPCUpdateSuccess, error) { out := new(RPCUpdateSuccess) - err := c.cc.Invoke(ctx, "/pb.ReverseProxyService/updateReverseProxyIsOn", in, out, opts...) + err := c.cc.Invoke(ctx, "/pb.ReverseProxyService/updateReverseProxy", in, out, opts...) if err != nil { return nil, err } @@ -986,7 +1006,7 @@ type ReverseProxyServiceServer interface { // 修改备用源站信息 UpdateReverseProxyBackupOrigins(context.Context, *UpdateReverseProxyBackupOriginsRequest) (*RPCUpdateSuccess, error) // 修改是否启用 - UpdateReverseProxyIsOn(context.Context, *UpdateReverseProxyIsOnRequest) (*RPCUpdateSuccess, error) + UpdateReverseProxy(context.Context, *UpdateReverseProxyRequest) (*RPCUpdateSuccess, error) } // UnimplementedReverseProxyServiceServer can be embedded to have forward compatible implementations. @@ -1011,8 +1031,8 @@ func (*UnimplementedReverseProxyServiceServer) UpdateReverseProxyPrimaryOrigins( func (*UnimplementedReverseProxyServiceServer) UpdateReverseProxyBackupOrigins(context.Context, *UpdateReverseProxyBackupOriginsRequest) (*RPCUpdateSuccess, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateReverseProxyBackupOrigins not implemented") } -func (*UnimplementedReverseProxyServiceServer) UpdateReverseProxyIsOn(context.Context, *UpdateReverseProxyIsOnRequest) (*RPCUpdateSuccess, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateReverseProxyIsOn not implemented") +func (*UnimplementedReverseProxyServiceServer) UpdateReverseProxy(context.Context, *UpdateReverseProxyRequest) (*RPCUpdateSuccess, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateReverseProxy not implemented") } func RegisterReverseProxyServiceServer(s *grpc.Server, srv ReverseProxyServiceServer) { @@ -1127,20 +1147,20 @@ func _ReverseProxyService_UpdateReverseProxyBackupOrigins_Handler(srv interface{ return interceptor(ctx, in, info, handler) } -func _ReverseProxyService_UpdateReverseProxyIsOn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateReverseProxyIsOnRequest) +func _ReverseProxyService_UpdateReverseProxy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateReverseProxyRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(ReverseProxyServiceServer).UpdateReverseProxyIsOn(ctx, in) + return srv.(ReverseProxyServiceServer).UpdateReverseProxy(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/pb.ReverseProxyService/UpdateReverseProxyIsOn", + FullMethod: "/pb.ReverseProxyService/UpdateReverseProxy", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ReverseProxyServiceServer).UpdateReverseProxyIsOn(ctx, req.(*UpdateReverseProxyIsOnRequest)) + return srv.(ReverseProxyServiceServer).UpdateReverseProxy(ctx, req.(*UpdateReverseProxyRequest)) } return interceptor(ctx, in, info, handler) } @@ -1174,8 +1194,8 @@ var _ReverseProxyService_serviceDesc = grpc.ServiceDesc{ Handler: _ReverseProxyService_UpdateReverseProxyBackupOrigins_Handler, }, { - MethodName: "updateReverseProxyIsOn", - Handler: _ReverseProxyService_UpdateReverseProxyIsOn_Handler, + MethodName: "updateReverseProxy", + Handler: _ReverseProxyService_UpdateReverseProxy_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/pkg/rpc/protos/service_reverse_proxy.proto b/pkg/rpc/protos/service_reverse_proxy.proto index 762f06d..9d256c5 100644 --- a/pkg/rpc/protos/service_reverse_proxy.proto +++ b/pkg/rpc/protos/service_reverse_proxy.proto @@ -26,7 +26,7 @@ service ReverseProxyService { rpc updateReverseProxyBackupOrigins (UpdateReverseProxyBackupOriginsRequest) returns (RPCUpdateSuccess); // 修改是否启用 - rpc updateReverseProxyIsOn (UpdateReverseProxyIsOnRequest) returns (RPCUpdateSuccess); + rpc updateReverseProxy (UpdateReverseProxyRequest) returns (RPCUpdateSuccess); } // 创建反向代理 @@ -77,7 +77,9 @@ message UpdateReverseProxyBackupOriginsRequest { } // 修改是否启用 -message UpdateReverseProxyIsOnRequest { +message UpdateReverseProxyRequest { int64 reverseProxyId = 1; - bool isOn = 2; + string requestHost = 2; + string requestURI = 3; + string stripPrefix = 4; } \ No newline at end of file diff --git a/pkg/serverconfigs/http_root_config.go b/pkg/serverconfigs/http_root_config.go index 0ec590a..1a4b55a 100644 --- a/pkg/serverconfigs/http_root_config.go +++ b/pkg/serverconfigs/http_root_config.go @@ -8,7 +8,7 @@ type HTTPRootConfig struct { IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用 Dir string `yaml:"dir" json:"dir"` // 目录 Indexes []string `yaml:"indexes" json:"indexes"` // 默认首页文件 - StripPrefix string `yaml:"stripPrefix" json:"stripPrefix"` // 去除前缀 + StripPrefix string `yaml:"stripPrefix" json:"stripPrefix"` // 去除URL前缀 DecodePath bool `yaml:"decodePath" json:"decodePath"` // 是否对请求路径进行解码 IsBreak bool `yaml:"isBreak" json:"isBreak"` // 找不到文件的情况下是否终止 diff --git a/pkg/serverconfigs/reverse_proxy_config.go b/pkg/serverconfigs/reverse_proxy_config.go index bfe6dad..9af51d0 100644 --- a/pkg/serverconfigs/reverse_proxy_config.go +++ b/pkg/serverconfigs/reverse_proxy_config.go @@ -1,6 +1,7 @@ package serverconfigs import ( + "github.com/TeaOSLab/EdgeCommon/pkg/configutils" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/schedulingconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "sync" @@ -16,7 +17,12 @@ type ReverseProxyConfig struct { BackupOriginRefs []*OriginRef `yaml:"backupOriginRefs" json:"backupOriginRefs"` // 备用源站引用 Scheduling *SchedulingConfig `yaml:"scheduling" json:"scheduling"` // 调度算法选项 - // TODO 可以设置同后端交互的主机名(Host),并支持变量 + StripPrefix string `yaml:"stripPrefix" json:"stripPrefix"` // 去除URL前缀 + RequestHost string `yaml:"requestHost" json:"requestHost"` // 请求Host,支持变量 + RequestURI string `yaml:"requestURI" json:"requestURI"` // 请求URI,支持变量,如果同时定义了StripPrefix,则先执行StripPrefix + + requestHostHasVariables bool + requestURIHasVariables bool hasPrimaryOrigins bool hasBackupOrigins bool @@ -27,6 +33,9 @@ type ReverseProxyConfig struct { // 初始化 func (this *ReverseProxyConfig) Init() error { + this.requestHostHasVariables = configutils.HasVariables(this.RequestHost) + this.requestURIHasVariables = configutils.HasVariables(this.RequestURI) + this.hasPrimaryOrigins = len(this.PrimaryOrigins) > 0 this.hasBackupOrigins = len(this.BackupOrigins) > 0 @@ -140,3 +149,13 @@ func (this *ReverseProxyConfig) FindSchedulingConfig() *SchedulingConfig { } return this.Scheduling } + +// 判断RequestHost是否有变量 +func (this *ReverseProxyConfig) RequestHostHasVariables() bool { + return this.requestHostHasVariables +} + +// 判断RequestURI是否有变量 +func (this *ReverseProxyConfig) RequestURIHasVariables() bool { + return this.requestURIHasVariables +}