HTTP Header:实现请求方法、域名、状态码等限制,实现内容替换功能

This commit is contained in:
刘祥超
2021-12-14 21:26:32 +08:00
parent 8b5a21e593
commit a226eee6ef
15 changed files with 503 additions and 79 deletions

View File

@@ -19,8 +19,10 @@ func (this *CreateSetPopupAction) Init() {
func (this *CreateSetPopupAction) RunGet(params struct {
HeaderPolicyId int64
Type string
}) {
this.Data["headerPolicyId"] = params.HeaderPolicyId
this.Data["type"] = params.Type
this.Show()
}
@@ -30,6 +32,14 @@ func (this *CreateSetPopupAction) RunPost(params struct {
Name string
Value string
StatusListJSON []byte
MethodsJSON []byte
DomainsJSON []byte
ShouldAppend bool
DisableRedirect bool
ShouldReplace bool
ReplaceValuesJSON []byte
Must *actions.Must
}) {
// 日志
@@ -51,10 +61,57 @@ func (this *CreateSetPopupAction) RunPost(params struct {
return
}
// status list
var statusList = []int32{}
if len(params.StatusListJSON) > 0 {
err = json.Unmarshal(params.StatusListJSON, &statusList)
if err != nil {
this.ErrorPage(err)
return
}
}
// methods
var methods = []string{}
if len(params.MethodsJSON) > 0 {
err = json.Unmarshal(params.MethodsJSON, &methods)
if err != nil {
this.ErrorPage(err)
return
}
}
// domains
var domains = []string{}
if len(params.DomainsJSON) > 0 {
err = json.Unmarshal(params.DomainsJSON, &domains)
if err != nil {
this.ErrorPage(err)
return
}
}
// replace values
var replaceValues = []*shared.HTTPHeaderReplaceValue{}
if len(params.ReplaceValuesJSON) > 0 {
err = json.Unmarshal(params.ReplaceValuesJSON, &replaceValues)
if err != nil {
this.ErrorPage(err)
return
}
}
// 创建Header
createHeaderResp, err := this.RPC().HTTPHeaderRPC().CreateHTTPHeader(this.AdminContext(), &pb.CreateHTTPHeaderRequest{
Name: params.Name,
Value: params.Value,
Name: params.Name,
Value: params.Value,
Status: statusList,
Methods: methods,
Domains: domains,
ShouldAppend: params.ShouldAppend,
DisableRedirect: params.DisableRedirect,
ShouldReplace: params.ShouldReplace,
ReplaceValuesJSON: params.ReplaceValuesJSON,
})
if err != nil {
this.ErrorPage(err)