mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	HTTP Header中支持设置非标Header
This commit is contained in:
		@@ -45,14 +45,14 @@ func (this *CreateDeletePopupAction) RunPost(params struct {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	policyConfig := &shared.HTTPHeaderPolicy{}
 | 
			
		||||
	var policyConfig = &shared.HTTPHeaderPolicy{}
 | 
			
		||||
	err = json.Unmarshal(policyConfigResp.HttpHeaderPolicyJSON, policyConfig)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	deleteHeaders := policyConfig.DeleteHeaders
 | 
			
		||||
	var deleteHeaders = policyConfig.DeleteHeaders
 | 
			
		||||
	deleteHeaders = append(deleteHeaders, params.Name)
 | 
			
		||||
	_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyDeletingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyDeletingHeadersRequest{
 | 
			
		||||
		HttpHeaderPolicyId: params.HeaderPolicyId,
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,67 @@
 | 
			
		||||
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"
 | 
			
		||||
	"github.com/iwind/TeaGo/actions"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type CreateNonStandardPopupAction struct {
 | 
			
		||||
	actionutils.ParentAction
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CreateNonStandardPopupAction) Init() {
 | 
			
		||||
	this.Nav("", "", "")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CreateNonStandardPopupAction) RunGet(params struct {
 | 
			
		||||
	HeaderPolicyId int64
 | 
			
		||||
	Type           string
 | 
			
		||||
}) {
 | 
			
		||||
	this.Data["headerPolicyId"] = params.HeaderPolicyId
 | 
			
		||||
	this.Data["type"] = params.Type
 | 
			
		||||
 | 
			
		||||
	this.Show()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *CreateNonStandardPopupAction) RunPost(params struct {
 | 
			
		||||
	HeaderPolicyId int64
 | 
			
		||||
	Name           string
 | 
			
		||||
 | 
			
		||||
	Must *actions.Must
 | 
			
		||||
}) {
 | 
			
		||||
	// 日志
 | 
			
		||||
	defer this.CreateLog(oplogs.LevelInfo, "添加非标的Header HeaderPolicyId: %d, Name: %s", params.HeaderPolicyId, params.Name)
 | 
			
		||||
 | 
			
		||||
	params.Must.
 | 
			
		||||
		Field("name", params.Name).
 | 
			
		||||
		Require("名称不能为空")
 | 
			
		||||
 | 
			
		||||
	policyConfigResp, err := this.RPC().HTTPHeaderPolicyRPC().FindEnabledHTTPHeaderPolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPHeaderPolicyConfigRequest{HttpHeaderPolicyId: params.HeaderPolicyId})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var policyConfig = &shared.HTTPHeaderPolicy{}
 | 
			
		||||
	err = json.Unmarshal(policyConfigResp.HttpHeaderPolicyJSON, policyConfig)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var nonStandardHeaders = policyConfig.NonStandardHeaders
 | 
			
		||||
	nonStandardHeaders = append(nonStandardHeaders, params.Name)
 | 
			
		||||
	_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyNonStandardHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyNonStandardHeadersRequest{
 | 
			
		||||
		HttpHeaderPolicyId: params.HeaderPolicyId,
 | 
			
		||||
		HeaderNames:        nonStandardHeaders,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.Success()
 | 
			
		||||
}
 | 
			
		||||
@@ -17,22 +17,22 @@ func (this *DeleteDeletingHeaderAction) RunPost(params struct {
 | 
			
		||||
	HeaderName     string
 | 
			
		||||
}) {
 | 
			
		||||
	// 日志
 | 
			
		||||
	defer this.CreateLog(oplogs.LevelInfo, "删除需要删除的请求Header,HeaderPolicyId:%d, HeaderName:%s", params.HeaderPolicyId, params.HeaderName)
 | 
			
		||||
	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
 | 
			
		||||
	}
 | 
			
		||||
	policyConfigJSON := policyConfigResp.HttpHeaderPolicyJSON
 | 
			
		||||
	policyConfig := &shared.HTTPHeaderPolicy{}
 | 
			
		||||
	var policyConfigJSON = policyConfigResp.HttpHeaderPolicyJSON
 | 
			
		||||
	var policyConfig = &shared.HTTPHeaderPolicy{}
 | 
			
		||||
	err = json.Unmarshal(policyConfigJSON, policyConfig)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		this.ErrorPage(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	headerNames := []string{}
 | 
			
		||||
	var headerNames = []string{}
 | 
			
		||||
	for _, h := range policyConfig.DeleteHeaders {
 | 
			
		||||
		if h == params.HeaderName {
 | 
			
		||||
			continue
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,52 @@
 | 
			
		||||
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()
 | 
			
		||||
}
 | 
			
		||||
@@ -18,6 +18,8 @@ func init() {
 | 
			
		||||
			GetPost("/updateSetPopup", new(UpdateSetPopupAction)).
 | 
			
		||||
			GetPost("/createDeletePopup", new(CreateDeletePopupAction)).
 | 
			
		||||
			Post("/deleteDeletingHeader", new(DeleteDeletingHeaderAction)).
 | 
			
		||||
			GetPost("/createNonStandardPopup", new(CreateNonStandardPopupAction)).
 | 
			
		||||
			Post("/deleteNonStandardHeader", new(DeleteNonStandardHeaderAction)).
 | 
			
		||||
			Post("/delete", new(DeleteAction)).
 | 
			
		||||
			GetPost("/updateCORSPopup", new(UpdateCORSPopupAction)).
 | 
			
		||||
			EndAll()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user