當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestInfo.getHeaders方法代碼示例

本文整理匯總了Java中com.nike.riposte.server.http.RequestInfo.getHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestInfo.getHeaders方法的具體用法?Java RequestInfo.getHeaders怎麽用?Java RequestInfo.getHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.nike.riposte.server.http.RequestInfo的用法示例。


在下文中一共展示了RequestInfo.getHeaders方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getClientVersion

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
/**
 * Get the value of the X-Cerberus-Client header or "Unknown" if not found.
 */
public static String getClientVersion(RequestInfo request) {
    final HttpHeaders headers = request.getHeaders();
    if (headers != null) {
        String value = headers.get(HEADER_X_CERBERUS_CLIENT);
        if (value != null) {
            return value;
        }
    }
    return UNKNOWN;
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:14,代碼來源:CerberusHttpHeaders.java

示例2: getXForwardedClientIp

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
/**
 * Get the first IP address from the Http header "X-Forwarded-For"
 *
 * E.g. "X-Forwarded-For: ip1, ip2, ip3" would return "ip1"
 */
public static String getXForwardedClientIp(RequestInfo request) {
    final HttpHeaders headers = request.getHeaders();
    if (headers != null) {
        String value = headers.get(HEADER_X_FORWARDED_FOR);
        if (value != null) {
            return StringUtils.substringBefore(value, ",").trim();
        }
    }
    return UNKNOWN;
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:16,代碼來源:CerberusHttpHeaders.java

示例3: combinedLogFormatPrefix

import com.nike.riposte.server.http.RequestInfo; //導入方法依賴的package包/類
/**
 * @param request
 *     The request to log; will not be null. This is the request that came into the application. WARNING: The
 *     content may have been released already, so you cannot rely on any of the methods that return the payload
 *     content in any form.
 * @param finalResponseObject
 *     The {@link HttpResponse} that was the actual final response object sent to the client; may be null. NOTE:
 *     This should be preferred over {@code responseInfo} whenever both have overlapping data since this argument
 *     may have been modified by outbound handlers after being initially populated by {@code responseInfo}.
 * @param responseInfo
 *     {@link com.nike.riposte.server.http.ResponseInfo} object that was initially used to build {@code
 *     finalResponseObject}; may be null. NOTE: {@code finalResponseObject} may have been modified by other outbound
 *     handlers (e.g. compression/gzip), so if it is non-null it should be preferred over this where possible.
 *
 * @return String representing the NCSA Combined log format for access logs plus the referrer and user agent: %h %l
 * %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}"
 */
protected String combinedLogFormatPrefix(RequestInfo<?> request,
                                         HttpResponse finalResponseObject,
                                         ResponseInfo responseInfo) {
    String ipAddress = "<unknown>";
    try {
        ipAddress = getLocalIpAddress();
    }
    catch (UnknownHostException ex) {
        logger.warn("Unable to retrieve local IP address.", ex);
    }

    String method = (request.getMethod() == null) ? "-" : String.valueOf(request.getMethod());
    String uriString = request.getUri();
    if (uriString == null)
        uriString = "-";
    String protocolVersion =
        (request.getProtocolVersion() == null) ? "-" : String.valueOf(request.getProtocolVersion());
    String url = method + " " + uriString + " " + protocolVersion;

    String referer = "-";
    String userAgent = "-";
    if (request.getHeaders() != null) {
        referer = request.getHeaders().get(REFERER);
        if (referer == null)
            referer = "-";
        userAgent = request.getHeaders().get(USER_AGENT);
        if (userAgent == null)
            userAgent = "-";
    }
    String httpStatusCode = "-";
    if (finalResponseObject != null && finalResponseObject.getStatus() != null)
        httpStatusCode = String.valueOf(finalResponseObject.getStatus().code());
    else if (responseInfo != null && responseInfo.getHttpStatusCode() != null)
        httpStatusCode = String.valueOf(responseInfo.getHttpStatusCode());

    String contentLength = "-";
    if (responseInfo != null) {
        if (responseInfo.getFinalContentLength() != null && responseInfo.getFinalContentLength() > 0)
            contentLength = String.valueOf(responseInfo.getFinalContentLength());
    }

    return ipAddress +
           " - - [" + // remote log name and remote user
           getFormattedDateTimeForNcsaCombinedLog(ZonedDateTime.now()) +
           "] \"" +
           url +
           "\" " +
           httpStatusCode +
           " " +
           contentLength +
           " \"" +
           referer +
           "\" \"" +
           userAgent +
           "\"";
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:74,代碼來源:AccessLogger.java


注:本文中的com.nike.riposte.server.http.RequestInfo.getHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。