action

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

action_variable.go - variable name legality check and variable handlers

action_variable_inner.go - built-in variable value fetchers (header/ssl/client info)

Index

Constants

View Source
const (
	// connection actions
	ActionClose  = "CLOSE"  // close, close the connection directly
	ActionPass   = "PASS"   // pass, do nothing
	ActionFinish = "FINISH" // finish, close connection after reply

	// header actions
	ActionReqHeaderAdd = "REQ_HEADER_ADD" // add request header
	ActionReqHeaderSet = "REQ_HEADER_SET" // set request header
	ActionReqHeaderDel = "REQ_HEADER_DEL" // del request header

	// host actions
	ActionHostSetFromPathPrefix = "HOST_SET_FROM_PATH_PREFIX" // set host from path prefix
	ActionHostSet               = "HOST_SET"                  // set host
	ActionHostSuffixReplace     = "HOST_SUFFIX_REPLACE"       // set host replaced suffx

	// path actions
	ActionPathSet        = "PATH_SET"         // set path
	ActionPathPrefixAdd  = "PATH_PREFIX_ADD"  // add path prefix
	ActionPathPrefixTrim = "PATH_PREFIX_TRIM" // trim path prefix

	// query actions
	ActionQueryAdd          = "QUERY_ADD"            // add query
	ActionQueryDel          = "QUERY_DEL"            // del query
	ActionQueryRename       = "QUERY_RENAME"         // rename query
	ActionQueryDelAllExcept = "QUERY_DEL_ALL_EXCEPT" // del query except given query key
)
View Source
const (
	ParamTypeLiteral = iota
	ParamTypeVarLegacy
	ParamTypeVarNew
)
View Source
const HeaderPrefix = "X-BFE-"
View Source
const (
	UNKNOWN = "unknown"
)

Variables

View Source
var (
	VariableHandlers = map[string]HeaderValueHandler{

		"bfe_clientip":          getClientIp,
		"bfe_clientport":        getClientPort,
		"bfe_clientip_location": getClientIpLocationName,

		"bfe_cip":         getClientIp,
		"bfe_vip":         getBfeVip,
		"bfe_bip":         getBfeBip,
		"bfe_rip":         getBfeRip,
		"bfe_domain_auto": getBfeDomainAuto,
		"session_id":      getSessionId,
		"bfe_logid":       getBfeLogId,

		"bfe_server_name": getBfeServerName,

		"bfe_cluster":      getBfeCluster,
		"bfe_backend_info": getBfeBackendInfo,

		"bfe_ssl_info":                          getBfeSslInfo,
		"bfe_ssl_resume":                        getBfeSslResume,
		"bfe_ssl_cipher":                        getBfeSslCipher,
		"bfe_ssl_version":                       getBfeSslVersion,
		"bfe_protocol":                          getBfeProtocol,
		"client_cert_serial_number":             getClientCertSerialNumber,
		"client_cert_subject_title":             getClientCertSubjectTitle,
		"client_cert_subject_common_name":       getClientCertSubjectCommonName,
		"client_cert_subject_organization":      getClientCertSubjectOrganization,
		"client_cert_subject_organization_unit": getClientCertSubjectOrganizationalUnit,
		"client_cert_subject_province":          getClientCertSubjectProvince,
		"client_cert_subject_country":           getClientCertSubjectCountry,
		"client_cert_subject_locality":          getClientCertSubjectLocality,
		"client_cert_adu_car_role":              getClientCertAduCarRole,
		"client_cert_adu_reserve":               getClientCertAduReserve,
		"client_cert_pem":                       getClientCertPEM,
		"client_cert_subject_string":            getClientCertSubjectString,
		"client_cert_issuer_string":             getClientCertIssuerString,
		"client_cert_pub_key_algo":              getClientCertPublicKeyAlgorithm,
		"client_cert_sig_algo":                  getClientCertSignatureAlgorithm,

		"req_uri":  getReqUrI,
		"req_path": getReqPath,
	}
)

Functions

func ActionFileCheck

func ActionFileCheck(conf ActionFile) error

func EvalFormatStr added in v1.9.0

func EvalFormatStr(req *bfe_basic.Request, params []string) string

func GetReqQueryKey added in v1.9.0

func GetReqQueryKey(req *bfe_basic.Request, key string) string

GetReqQueryKey returns the value of given query key.

func IsLegalVarName added in v1.9.0

func IsLegalVarName(varName string) bool

func ParamType added in v1.9.0

func ParamType(param string) int

format string contains the following style substring: ParamTypeVarLegacy: eg:%bfe_cluster ParamTypeVarNew: --new not-param var: eg:%{bfe_cluster}, --new param var: eg:%{bfe_req_header::headername}, %{usr_variable::rname} ParamTypeLiteral:

func PreprocessFormatStr added in v1.9.0

func PreprocessFormatStr(param string) ([]string, error)

func PreprocessSetUsrVarParams added in v1.9.0

func PreprocessSetUsrVarParams(params []string) ([]string, error)

func ReqHostSet

func ReqHostSet(req *bfe_basic.Request, hostname string)

ReqHostSet sets hostname to request.

func ReqHostSetFromFirstPathSegment

func ReqHostSetFromFirstPathSegment(req *bfe_basic.Request)

ReqHostSetFromFirstPathSegment set hostname from first path segment.

example: if uri path pattern is /x.baidu.com/xxxx,

set host x.baidu.com
set uri path  /xxx

if do not match this pattern, do noting

func ReqHostSuffixReplace

func ReqHostSuffixReplace(req *bfe_basic.Request, originSuffix, newSuffix string)

ReqHostSuffixReplace replaces suffix of hostname.

func ReqPathPrefixAdd

func ReqPathPrefixAdd(req *bfe_basic.Request, prefix string)

ReqPathPrefixAdd adds prefix to path. e.g., path "/(.*)" => "/link?$1",

func ReqPathPrefixTrim

func ReqPathPrefixTrim(req *bfe_basic.Request, prefix string)

ReqPathPrefixTrim trims prefix of path e.g., path "/service/shortcut/(.*)" => "/$1",

func ReqPathSet

func ReqPathSet(req *bfe_basic.Request, path string)

ReqPathSet sets path to request.

func ReqQueryAdd

func ReqQueryAdd(req *bfe_basic.Request, params []string)

ReqQueryAdd adds some number of (key, value) to query.

func ReqQueryDel

func ReqQueryDel(req *bfe_basic.Request, keys []string)

ReqQueryDel deletes some keys from query

func ReqQueryDelAllExcept

func ReqQueryDelAllExcept(req *bfe_basic.Request, keys []string)

ReqQueryDelAllExcept deletes all keys from query, except some keys

func ReqQueryRename

func ReqQueryRename(req *bfe_basic.Request, oldName string, newName string)

ReqQueryRename renames query key from old name to new name.

func SetExprParamCompiler added in v1.9.0

func SetExprParamCompiler(c ExprParamCompiler)

SetExprParamCompiler 注入动作参数表达式编译器。 由 bfe_expr 包在 init 中调用,避免 bfe_basic/action 反向依赖 bfe_expr(依赖环)。 未注入时表达式参数按字面量处理,保持旧行为。

func SetUsrVariable added in v1.9.0

func SetUsrVariable(req *bfe_basic.Request, varName string, params []string)

Types

type Action

type Action struct {
	Cmd    string   // command of action
	Params []string // params of action
	// contains filtered or unexported fields
}

func (*Action) Check

func (ac *Action) Check(allowActions map[string]bool) error

func (*Action) Do

func (ac *Action) Do(req *bfe_basic.Request) error

Do process action for request

func (*Action) UnmarshalJSON

func (ac *Action) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes given data in json format

type ActionFile

type ActionFile struct {
	Cmd    *string // command of action
	Params []string
}

type ExprParamCompiler added in v1.9.0

type ExprParamCompiler func(params []string, indexes []int) (func(req *bfe_basic.Request) []string, error)

ExprParamCompiler 动作参数表达式编译器签名: 入参为参数列表与「可作为表达式的下标集合」,返回运行期求值闭包与加载期错误。

type HeaderValueHandler added in v1.9.0

type HeaderValueHandler func(req *bfe_basic.Request) string

type VarEvaluator added in v1.9.0

type VarEvaluator interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL