MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / requestRemoteAddrs

Method requestRemoteAddrs

internal/nodes/http_request.go:1301–1343  ·  view source on GitHub ↗

获取请求的客户端地址列表

()

Source from the content-addressed store, hash-verified

1299
1300// 获取请求的客户端地址列表
1301func (this *HTTPRequest) requestRemoteAddrs() (result []string) {
1302 result = append(result, this.requestRemoteAddr(true))
1303
1304 // X-Forwarded-For
1305 var forwardedFor = this.RawReq.Header.Get("X-Forwarded-For")
1306 if len(forwardedFor) > 0 {
1307 commaIndex := strings.Index(forwardedFor, ",")
1308 if commaIndex > 0 && !lists.ContainsString(result, forwardedFor[:commaIndex]) {
1309 result = append(result, forwardedFor[:commaIndex])
1310 }
1311 }
1312
1313 // Real-IP
1314 {
1315 realIP, ok := this.RawReq.Header["X-Real-IP"]
1316 if ok && len(realIP) > 0 && !lists.ContainsString(result, realIP[0]) {
1317 result = append(result, realIP[0])
1318 }
1319 }
1320
1321 // Real-Ip
1322 {
1323 realIP, ok := this.RawReq.Header["X-Real-Ip"]
1324 if ok && len(realIP) > 0 && !lists.ContainsString(result, realIP[0]) {
1325 result = append(result, realIP[0])
1326 }
1327 }
1328
1329 // Remote-Addr
1330 {
1331 var remoteAddr = this.RawReq.RemoteAddr
1332 host, _, err := net.SplitHostPort(remoteAddr)
1333 if err == nil {
1334 if !lists.ContainsString(result, host) {
1335 result = append(result, host)
1336 }
1337 } else {
1338 result = append(result, remoteAddr)
1339 }
1340 }
1341
1342 return
1343}
1344
1345// 请求内容长度
1346func (this *HTTPRequest) requestLength() int64 {

Callers 3

FormatMethod · 0.95
checkWAFRemoteAddrMethod · 0.95
checkWAFRequestMethod · 0.95

Calls 2

requestRemoteAddrMethod · 0.95
GetMethod · 0.45

Tested by

no test coverage detected