mirror of
https://github.com/alibaba/higress.git
synced 2026-05-08 04:17:27 +08:00
optimization parseIP in xff (#1915)
This commit is contained in:
@@ -2,9 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/zmap/go-iptree/iptree"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// parseIPNets 解析Ip段配置
|
||||
@@ -24,7 +25,12 @@ func parseIPNets(array []gjson.Result) (*iptree.IPTree, error) {
|
||||
}
|
||||
|
||||
// parseIP 解析IP
|
||||
func parseIP(source string) string {
|
||||
func parseIP(source string, fromHeader bool) string {
|
||||
|
||||
if fromHeader {
|
||||
source = strings.Split(source, ",")[0]
|
||||
}
|
||||
source = strings.Trim(source, " ")
|
||||
if strings.Contains(source, ".") {
|
||||
// parse ipv4
|
||||
return strings.Split(source, ":")[0]
|
||||
|
||||
Reference in New Issue
Block a user