Collects counts statistics about the request: client ip address from the x-forwarded-for header;
ipv4 or ipv6 and  host name from the host header;

@param req
760786
public void collectRequestStats(HttpRequestInfo req) {
        // ipv4/ipv6 tracking
        String clientIp;
        final String xForwardedFor = req.getHeaders().getFirst(X_FORWARDED_FOR_HEADER);
        if (xForwardedFor == null) {
            clientIp = req.getClientIp();
        } else {
            clientIp = extractClientIpFromXForwardedFor(xForwardedFor);
        }

        final boolean isIPv6 = (clientIp != null) ? isIPv6(clientIp) : false;

        final String ipVersionKey = isIPv6 ? "ipv6" : "ipv4";
        incrementNamedCountingMonitor(ipVersionKey, ipVersionCounterMap);

        // host header
        String host = req.getHeaders().getFirst(HOST_HEADER);
        if (host != null) {
            int colonIdx;
            if (isIPv6) {
                // an ipv6 host might be a raw IP with 7+ colons
                colonIdx = host.lastIndexOf(":");
            } else {
                // strips port from host
                colonIdx = host.indexOf(":");
            }
            if (colonIdx > -1) host = host.substring(0, colonIdx);
            incrementNamedCountingMonitor(hostKey(host), this.hostCounterMap);
        }

        // http vs. https
        String protocol = req.getHeaders().getFirst(X_FORWARDED_PROTO_HEADER);
        if (protocol == null) protocol = req.getScheme();
        incrementNamedCountingMonitor(protocolKey(protocol), this.protocolCounterMap);


    }
517566
function hostnameof (req) {
  var host = req.headers.host

  if (!host) {
    return
  }

  var offset = host[0] === '['
    ? host.indexOf(']') + 1
    : 0
  var index = host.indexOf(':', offset)

  return index !== -1
    ? host.substring(0, index)
    : host
}
159304
public void processRequest(RequestEvent req) {
		
		if (tracer.isInfoEnabled()) {
			tracer.info("Received Request:\n"+req.getRequest());
		}

		// Restcomm Statistics
		final String method = req.getRequest().getMethod();
		if (Request.INVITE.equalsIgnoreCase(method)) {
			this.defaultUsageParameters.incrementCalls(1);
		}
		if (Request.MESSAGE.equalsIgnoreCase(method)) {
			this.defaultUsageParameters.incrementMessages(1);
		}

		// get dialog wrapper
		final Dialog d = req.getDialog();
		final DialogWrapper dw = getDialogWrapper(d);
		if (dw != null && req.getServerTransaction() == null) {
			if (tracer.isInfoEnabled()) {
				tracer.info("No server tx found, for in dialog request, assuming it as retransmission and dropping...");
			}
			return;
		}
		
		if (req.getRequest().getMethod().equals(Request.CANCEL)) {
			processCancelRequest(req,dw);
		} else {
			processNotCancelRequest(req,dw);
		}
	}
1182001
function (req, res, next) {
        var ip = IPAddressHelper.getClientIP(req)
            , route = req.miajs.route
            , key = ip + route.path + route.method;

        if (_.isEmpty(route.rateLimits)) {
            next();
            return;
        }

        RateLimiter.checkRateLimitsByKey(key, route.rateLimits).then(function (rateLimiterResult) {
            if (rateLimiterResult.remaining == -1) {
                _logInfo("Rate limit of " + rateLimiterResult.limit + "req/" + rateLimiterResult.timeInterval + "min requests exceeded " + route.requestmethod.toUpperCase() + " " + route.url + " for " + ip);
                res.header("X-Rate-Limit-Limit", rateLimiterResult.limit);
                res.header("X-Rate-Limit-Remaining", 0);
                res.header("X-Rate-Limit-Reset", rateLimiterResult.timeTillReset);
                next(new MiaError({
                    status: 429,
                    err: {
                        'code': 'RateLimitExceeded',
                        'msg': Translator('system', 'RateLimitExceeded')
                    }
                }));
            }
            else {
                res.header("X-Rate-Limit-Limit", rateLimiterResult.limit);
                res.header("X-Rate-Limit-Remaining", rateLimiterResult.remaining);
                res.header("X-Rate-Limit-Reset", rateLimiterResult.timeTillReset);
                next();
            }
        }).catch(function () {
            next();
        });
    }
1154502
public static protocolip_stats get(nitro_service service) throws Exception{
		protocolip_stats obj = new protocolip_stats();
		protocolip_stats[] response = (protocolip_stats[])obj.stat_resources(service);
		return response[0];
	}
913715
def my_address_string(self):
        
        addr = getattr(self, 'client_address', ('', None))[0]

        # If listed in proxy_ips, use the X-Forwarded-For header, if present.
        if addr in self.proxy_ips:
            return self.headers.getheader('x-forwarded-for', addr)
        return addr
392554
private static Map<String, String> __getRequestHeaderMap(HttpServletRequest req) {
        Map<String, String> reqHeaders = new LinkedHashMap<>();
        Enumeration<String> headerNames = req.getHeaderNames();
        if (headerNames != null) {
            while (headerNames.hasMoreElements()) {
                String headerName = headerNames.nextElement();
                Enumeration<String> headerValues = req.getHeaders(headerName);

                if (headerValues != null) {
                    StringBuilder headerValueBuilder = new StringBuilder();
                    int i = 0;
                    while (headerValues.hasMoreElements()) {
                        if (i > 0) {
                            headerValueBuilder.append(", ");
                        }

                        headerValueBuilder.append(headerValues.nextElement());
                        i++;
                    }

                    reqHeaders.put(headerName, headerValueBuilder.toString());
                } else {
                    reqHeaders.put(headerName, "");
                }
            }
        }
        return reqHeaders;
    }
894502
def process_request(self, req, resp):
        

        key = req.env['REMOTE_PORT'] + req.env['REMOTE_ADDR']
        val = self.cache.get(key, 0)

        if val == self.count:
            abort(exceptions.TooManyRequests(headers=self._error_headers))
        else:
            self.cache[key] = val + 1
871183
def x_forwarded_for(self):
        
        ip = self._request.META.get('REMOTE_ADDR')
        current_xff = self.headers.get('X-Forwarded-For')

        return '%s, %s' % (current_xff, ip) if current_xff else ip
1173233
public static String getIpAddr(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
      ip = request.getHeader("Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
      ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
      ip = request.getRemoteAddr();
    }
    return ip;
  }
697535
public static String getRemoteAddrFromRequest(Request request, Set<IpSubnet> trustedSubnets) {
        final String remoteAddr = request.getRemoteAddr();
        final String XForwardedFor = request.getHeader("X-Forwarded-For");
        if (XForwardedFor != null) {
            for (IpSubnet s : trustedSubnets) {
                try {
                    if (s.contains(remoteAddr)) {
                        // Request came from trusted source, trust X-Forwarded-For and return it
                        return XForwardedFor;
                    }
                } catch (UnknownHostException e) {
                    // ignore silently, probably not worth logging
                }
            }
        }

        // Request did not come from a trusted source, or the X-Forwarded-For header was not set
        return remoteAddr;
    }
1297192
def getClientIP(request):
    """"""
    forwardedfor = request.META.get('HTTP_X_FORWARDED_FOR')
    if forwardedfor:
        ip = forwardedfor.split(',')[0]
    else:
        ip = request.META.get('REMOTE_ADDR')

    return ip
385440
public int identifySite (HttpServletRequest req)
    {
        checkReloadSites();
        String serverName = req.getServerName();

        // scan for the mapping that matches the specified domain
        int msize = _mappings.size();
        for (int i = 0; i < msize; i++) {
            SiteMapping mapping = _mappings.get(i);
            if (serverName.endsWith(mapping.domain)) {
                return mapping.siteId;
            }
        }

        // if we matched nothing, return the default id
        return _defaultSiteId;
    }
1021903
def check_internal_ip(request):
    
    remote_addr = (request.META["HTTP_X_FORWARDED_FOR"] if "HTTP_X_FORWARDED_FOR" in request.META else request.META.get("REMOTE_ADDR", ""))
    return remote_addr in settings.INTERNAL_IPS
353990
def is_client_ip_address_blacklisted(request: AxesHttpRequest) -> bool:
    

    if is_ip_address_in_blacklist(request.axes_ip_address):
        return True

    if settings.AXES_ONLY_WHITELIST and not is_ip_address_in_whitelist(request.axes_ip_address):
        return True

    return False
162779
public GetDomainStatisticsResponse getDomainStatistics(GetDomainStatisticsRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");

        checkStringNotEmpty(request.getDomain(), "Domain should NOT be empty.");
        InternalRequest internalRequest = createRequest(HttpMethodName.GET, request, STATISTICS,
                LIVE_DOMAIN, request.getDomain());
        if (request.getStartDate() != null) {
            internalRequest.addParameter("startDate", request.getStartDate());
        }
        if (request.getEndDate() != null) {
            internalRequest.addParameter("endDate", request.getEndDate());
        }
        if (request.getAggregate() != null) {
            internalRequest.addParameter("aggregate", request.getAggregate().toString());
        }
        return invokeHttpClient(internalRequest, GetDomainStatisticsResponse.class);
    }
431650
def eff_request_host(request):
    
    erhn = req_host = request_host(request)
    if req_host.find(".") == -1 and not IPV4_RE.search(req_host):
        erhn = req_host + ".local"
    return req_host, erhn