mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 21:50:28 +08:00
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
|
|
package headers
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"encoding/json"
|
|||
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
|||
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|||
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|||
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
type DeleteNonStandardHeaderAction struct {
|
|||
|
|
actionutils.ParentAction
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (this *DeleteNonStandardHeaderAction) RunPost(params struct {
|
|||
|
|
HeaderPolicyId int64
|
|||
|
|
HeaderName string
|
|||
|
|
}) {
|
|||
|
|
// 日志
|
|||
|
|
defer this.CreateLog(oplogs.LevelInfo, "删除需要非标的Header,HeaderPolicyId:%d, HeaderName:%s", params.HeaderPolicyId, params.HeaderName)
|
|||
|
|
|
|||
|
|
policyConfigResp, err := this.RPC().HTTPHeaderPolicyRPC().FindEnabledHTTPHeaderPolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPHeaderPolicyConfigRequest{HttpHeaderPolicyId: params.HeaderPolicyId})
|
|||
|
|
if err != nil {
|
|||
|
|
this.ErrorPage(err)
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
var policyConfigJSON = policyConfigResp.HttpHeaderPolicyJSON
|
|||
|
|
var policyConfig = &shared.HTTPHeaderPolicy{}
|
|||
|
|
err = json.Unmarshal(policyConfigJSON, policyConfig)
|
|||
|
|
if err != nil {
|
|||
|
|
this.ErrorPage(err)
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var headerNames = []string{}
|
|||
|
|
for _, h := range policyConfig.NonStandardHeaders {
|
|||
|
|
if h == params.HeaderName {
|
|||
|
|
continue
|
|||
|
|
}
|
|||
|
|
headerNames = append(headerNames, h)
|
|||
|
|
}
|
|||
|
|
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyNonStandardHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyNonStandardHeadersRequest{
|
|||
|
|
HttpHeaderPolicyId: params.HeaderPolicyId,
|
|||
|
|
HeaderNames: headerNames,
|
|||
|
|
})
|
|||
|
|
if err != nil {
|
|||
|
|
this.ErrorPage(err)
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.Success()
|
|||
|
|
}
|