2020-09-16 20:29:13 +08:00
|
|
|
|
package headers
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"encoding/json"
|
2020-11-20 15:32:42 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
2020-09-16 20:29:13 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 删除Header
|
|
|
|
|
|
type DeleteAction struct {
|
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (this *DeleteAction) RunPost(params struct {
|
|
|
|
|
|
HeaderPolicyId int64
|
|
|
|
|
|
Type string
|
|
|
|
|
|
HeaderId int64
|
|
|
|
|
|
}) {
|
2020-11-20 15:32:42 +08:00
|
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "删除请求Header,HeaderPolicyId:%d, HeaderId:%d", params.HeaderPolicyId, params.HeaderId)
|
|
|
|
|
|
|
2020-09-16 20:29:13 +08:00
|
|
|
|
policyConfigResp, err := this.RPC().HTTPHeaderPolicyRPC().FindEnabledHTTPHeaderPolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPHeaderPolicyConfigRequest{
|
|
|
|
|
|
HeaderPolicyId: params.HeaderPolicyId,
|
|
|
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
policyConfig := &shared.HTTPHeaderPolicy{}
|
2020-09-21 19:51:50 +08:00
|
|
|
|
err = json.Unmarshal(policyConfigResp.HeaderPolicyJSON, policyConfig)
|
2020-09-16 20:29:13 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch params.Type {
|
|
|
|
|
|
case "setHeader":
|
2020-09-26 08:07:18 +08:00
|
|
|
|
result := []*shared.HTTPHeaderRef{}
|
|
|
|
|
|
for _, h := range policyConfig.SetHeaderRefs {
|
|
|
|
|
|
if h.HeaderId != params.HeaderId {
|
2020-09-16 20:29:13 +08:00
|
|
|
|
result = append(result, h)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
resultJSON, err := json.Marshal(result)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicySettingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicySettingHeadersRequest{
|
|
|
|
|
|
HeaderPolicyId: params.HeaderPolicyId,
|
|
|
|
|
|
HeadersJSON: resultJSON,
|
|
|
|
|
|
})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
|
}
|