当前位置: 首页>>代码示例>>Java>>正文


Java HeaderMap.contains方法代码示例

本文整理汇总了Java中io.undertow.util.HeaderMap.contains方法的典型用法代码示例。如果您正苦于以下问题:Java HeaderMap.contains方法的具体用法?Java HeaderMap.contains怎么用?Java HeaderMap.contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.undertow.util.HeaderMap的用法示例。


在下文中一共展示了HeaderMap.contains方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCorsResponseHeaders

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
private void setCorsResponseHeaders(HttpServerExchange exchange) throws Exception {
    HeaderMap headers = exchange.getRequestHeaders();
    if (headers.contains(Headers.ORIGIN)) {
        if(matchOrigin(exchange, allowedOrigins) != null) {
            exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_ORIGIN, headers.get(Headers.ORIGIN));
            exchange.getResponseHeaders().add(Headers.VARY, Headers.ORIGIN_STRING);
        }
    }
    exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_METHODS, allowedMethods);
    HeaderValues requestedHeaders = headers.get(ACCESS_CONTROL_REQUEST_HEADERS);
    if (requestedHeaders != null && !requestedHeaders.isEmpty()) {
        exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_HEADERS, requestedHeaders);
    } else {
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.CONTENT_TYPE_STRING);
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.WWW_AUTHENTICATE_STRING);
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.AUTHORIZATION_STRING);
    }
    exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    exchange.getResponseHeaders().add(ACCESS_CONTROL_MAX_AGE, ONE_HOUR_IN_SECONDS);
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:21,代码来源:CorsHttpHandler.java

示例2: exchangeEvent

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Override
public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) {
    try {
        long end = System.currentTimeMillis();
        long duration = end - start;
        if (duration > this.timeThreshold) {
            String method = exchange.getRequestMethod().toString();
            String query = exchange.getQueryString();
            String request_url = exchange.getRequestURI() + (query.isEmpty() ? "" : ("?" + query));
            HeaderMap headers = exchange.getRequestHeaders();
            if (headers.contains(tenantHeader)) {
                String tenantId = headers.get(tenantHeader, 0);
                log.warnf("Request %s %s took: %d ms, exceeds %d ms threshold, tenant-id: %s",
                        method, request_url, duration, timeThreshold, tenantId);
            } else {
                log.warnf("Request %s %s took: %d ms, exceeds %d ms threshold, no tenant",
                        method, request_url, duration, timeThreshold);
            }

        }
    } finally {
        if (nextListener != null) {
            nextListener.proceed();
        }
    }
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:27,代码来源:RequestTimeLogger.java

示例3: setCorsResponseHeaders

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
private void setCorsResponseHeaders(HttpServerExchange exchange) throws Exception {
    HeaderMap headers = exchange.getRequestHeaders();
    if (headers.contains(Headers.ORIGIN)) {
        if(matchOrigin(exchange, allowedOrigins) != null) {
            exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_ORIGIN, headers.get(Headers.ORIGIN));
            exchange.getResponseHeaders().add(Headers.VARY, Headers.ORIGIN_STRING);
        }
    }
    HeaderValues requestedMethods = headers.get(ACCESS_CONTROL_REQUEST_METHOD);
    if (requestedMethods != null && !requestedMethods.isEmpty()) {
        exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_METHODS, requestedMethods);
    } else {
        exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_METHODS, Arrays.asList(new String[]{Methods.GET_STRING, Methods.POST_STRING}));
    }
    HeaderValues requestedHeaders = headers.get(ACCESS_CONTROL_REQUEST_HEADERS);
    if (requestedHeaders != null && !requestedHeaders.isEmpty()) {
        exchange.getResponseHeaders().addAll(ACCESS_CONTROL_ALLOW_HEADERS, requestedHeaders);
    } else {
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.CONTENT_TYPE_STRING);
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.WWW_AUTHENTICATE_STRING);
        exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_HEADERS, Headers.AUTHORIZATION_STRING);
    }
    exchange.getResponseHeaders().add(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    exchange.getResponseHeaders().add(ACCESS_CONTROL_MAX_AGE, ONE_HOUR_IN_SECONDS);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:26,代码来源:CorsHttpHandler.java

示例4: copyHeaders

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
static void copyHeaders(final HeaderMap to, final HeaderMap from) {
    long f = from.fastIterateNonEmpty();
    HeaderValues values;
    while (f != -1L) {
        values = from.fiCurrent(f);
        if(!to.contains(values.getHeaderName())) {
            //don't over write existing headers, normally the map will be empty, if it is not we assume it is not for a reason
            to.putAll(values.getHeaderName(), values);
        }
        f = from.fiNextNonEmpty(f);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:ProxyHandler.java

示例5: commonChecks

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
private boolean commonChecks(HttpServerExchange exchange) throws Exception {
    // AS7-2284 If we are starting or stopping, tell caller the service is unavailable and to try again
    // later. If "stopping" it's either a reload, in which case trying again will eventually succeed,
    // or it's a true process stop eventually the server will have stopped.
    @SuppressWarnings("deprecation")
    ControlledProcessState.State currentState = controlledProcessStateService.getCurrentState();
    if (currentState == ControlledProcessState.State.STARTING
            || currentState == ControlledProcessState.State.STOPPING) {
        exchange.getResponseHeaders().add(Headers.RETRY_AFTER, "2"); //  2 secs is just a guesstimate
        Common.SERVICE_UNAVAIABLE.handleRequest(exchange);
        return false;
    }

    /*
     * Completely disallow OPTIONS - if the browser suspects this is a cross site request just reject it.
     */
    final HttpString requestMethod = exchange.getRequestMethod();
    if (!Methods.POST.equals(requestMethod) && !Methods.GET.equals(requestMethod)) {
        if (Methods.OPTIONS.equals(requestMethod)) {
            ROOT_LOGGER.debug("Request rejected due to 'OPTIONS' method which is not supported.");
        } else {
            ROOT_LOGGER.debug("Request rejected as method not one of (GET,POST).");
        }
        Common.METHOD_NOT_ALLOWED_HANDLER.handleRequest(exchange);
        return false;
    }

    /*
     *  Origin check, if it is set the Origin header should match the Host otherwise reject the request.
     *
     *  This check is for cross site scripted GET and POST requests.
     */
    final HeaderMap headers = exchange.getRequestHeaders();
    if (headers.contains(Headers.ORIGIN)) {
       return matchOrigin(exchange, allowedOrigins) != null;
    }
    return true;
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:39,代码来源:DomainApiCheckHandler.java

示例6: isCoreRequest

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
public static boolean isCoreRequest(HeaderMap headers) {
    return headers.contains(ORIGIN)
            || headers.contains(ACCESS_CONTROL_REQUEST_HEADERS)
            || headers.contains(ACCESS_CONTROL_REQUEST_METHOD);
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:6,代码来源:CorsUtil.java

示例7: getHeader

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
private static Optional<String> getHeader(HttpServerExchange exchange, HttpString headerName) {
    HeaderMap requestHeaders = exchange.getRequestHeaders();
    return requestHeaders.contains(headerName) ?
            Optional.ofNullable(requestHeaders.get(headerName).getFirst()) :
            Optional.empty();
}
 
开发者ID:meridor,项目名称:perspective-backend,代码行数:7,代码来源:HandlerProviderImpl.java


注:本文中的io.undertow.util.HeaderMap.contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。