MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Parse

Method Parse

internal/stats/user_agent_parser.go:72–110  ·  view source on GitHub ↗

Parse 解析UserAgent

(userAgent string)

Source from the content-addressed store, hash-verified

70
71// Parse 解析UserAgent
72func (this *UserAgentParser) Parse(userAgent string) (result UserAgentParserResult) {
73 // 限制长度
74 if len(userAgent) == 0 || len(userAgent) > 256 {
75 return
76 }
77
78 var userAgentKey = fnv.HashString(userAgent)
79 var shardingIndex = int(userAgentKey % userAgentShardingCount)
80
81 this.mu.RLock(shardingIndex)
82 cacheResult, ok := this.cacheMaps[shardingIndex][userAgentKey]
83 if ok {
84 this.mu.RUnlock(shardingIndex)
85 return cacheResult
86 }
87 this.mu.RUnlock(shardingIndex)
88
89 var parser = this.pool.Get().(*useragent.UserAgent)
90 parser.Parse(userAgent)
91 result.OS = parser.OSInfo()
92 result.BrowserName, result.BrowserVersion = parser.Browser()
93 result.IsMobile = parser.Mobile()
94 this.pool.Put(parser)
95
96 // 忽略特殊字符
97 if len(result.BrowserName) > 0 {
98 for _, r := range result.BrowserName {
99 if r == '$' || r == '"' || r == '\'' || r == '<' || r == '>' || r == ')' {
100 return
101 }
102 }
103 }
104
105 this.mu.Lock(shardingIndex)
106 this.cacheMaps[shardingIndex][userAgentKey] = result
107 this.mu.Unlock(shardingIndex)
108
109 return
110}
111
112// MaxCacheItems 读取能容纳的缓存最大数量
113func (this *UserAgentParser) MaxCacheItems() int {

Callers 15

TestParseDSNFunction · 0.80
CleanMatchKeyMethod · 0.80
CleanMatchPrefixMethod · 0.80
CleanMatchKeyMethod · 0.80
CleanMatchPrefixMethod · 0.80
FormatMethod · 0.80
doWebsocketMethod · 0.80
handleChangeAPINodeMethod · 0.80
doOriginRequestMethod · 0.80
doCheckReferersMethod · 0.80
httpParseHostFunction · 0.80
prettyAddressMethod · 0.80

Calls 7

HashStringFunction · 0.92
RLockMethod · 0.80
RUnlockMethod · 0.80
GetMethod · 0.45
PutMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45