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


Java HeaderValues类代码示例

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


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

示例1: flushHeaderBuffer

import io.undertow.util.HeaderValues; //导入依赖的package包/类
private boolean flushHeaderBuffer(ByteBuffer buffer, String string, HeaderValues headerValues, int charIndex, long fiCookie, int valueIdx) throws IOException {
    int res;
    buffer.flip();
    do {
        res = next.write(buffer);
        if (res == 0) {
            this.string = string;
            this.headerValues = headerValues;
            this.charIndex = charIndex;
            this.fiCookie = fiCookie;
            this.valueIdx = valueIdx;
            return true;
        }
    } while (buffer.hasRemaining());
    buffer.clear();
    return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HttpResponseConduit.java

示例2: handleRequest

import io.undertow.util.HeaderValues; //导入依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.getRequestMethod().equals(Methods.TRACE)) {
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "message/http");
        StringBuilder body = new StringBuilder("TRACE ");
        body.append(exchange.getRequestURI());
        if(!exchange.getQueryString().isEmpty()) {
            body.append('?');
            body.append(exchange.getQueryString());
        }
        body.append(exchange.getProtocol().toString());
        body.append("\r\n");
        for(HeaderValues header : exchange.getRequestHeaders()) {
            for(String value : header) {
                body.append(header.getHeaderName());
                body.append(": ");
                body.append(value);
                body.append("\r\n");
            }
        }
        body.append("\r\n");
        exchange.getResponseSender().send(body.toString());
    } else {
        handler.handleRequest(exchange);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:HttpTraceHandler.java

示例3: handleRequest

import io.undertow.util.HeaderValues; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    String addr = exchange.getSourceAddress().getAddress().getHostAddress();

    List<String> locals = App.getConfig().getStringList("server.proxy.localhosts");
    for (String headerName : App.getConfig().getStringList("server.proxy.headers")) {
        if (locals.contains(addr)) {
            HeaderValues header = exchange.getRequestHeaders().get(headerName);
            if (header != null && !header.isEmpty()) {
                addr = header.element();
            }
        }
    }

    exchange.putAttachment(IP, addr);
    next.handleRequest(exchange);
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:18,代码来源:IPReader.java

示例4: validateHeader

import io.undertow.util.HeaderValues; //导入依赖的package包/类
private Status validateHeader(final HttpServerExchange exchange,
                              final SwaggerOperation swaggerOperation,
                              final Parameter headerParameter) {

    final HeaderValues headerValues = exchange.getRequestHeaders().get(headerParameter.getName());
    if ((headerValues == null || headerValues.isEmpty())) {
        if(headerParameter.getRequired()) {
            return new Status(VALIDATOR_REQUEST_PARAMETER_HEADER_MISSING, headerParameter.getName(), swaggerOperation.getPathString().original());
        }
    } else {

        Optional<Status> optional = headerValues
                .stream()
                .map((v) -> parameterValidators.validate(v, headerParameter))
                .filter(s -> s != null)
                .findFirst();
        if(optional.isPresent()) {
            return optional.get();
        }
    }
    return null;
}
 
开发者ID:networknt,项目名称:light-rest-4j,代码行数:23,代码来源:RequestValidator.java

示例5: validateHeader

import io.undertow.util.HeaderValues; //导入依赖的package包/类
private Status validateHeader(final HttpServerExchange exchange,
                              final OpenApiOperation openApiOperation,
                              final Parameter headerParameter) {

    final HeaderValues headerValues = exchange.getRequestHeaders().get(headerParameter.getName());
    if ((headerValues == null || headerValues.isEmpty())) {
        if(headerParameter.getRequired()) {
            return new Status(VALIDATOR_REQUEST_PARAMETER_HEADER_MISSING, headerParameter.getName(), openApiOperation.getPathString().original());
        }
    } else {

        Optional<Status> optional = headerValues
                .stream()
                .map((v) -> schemaValidator.validate(v, headerParameter.toJson()))
                .filter(s -> s != null)
                .findFirst();
        if(optional.isPresent()) {
            return optional.get();
        }
    }
    return null;
}
 
开发者ID:networknt,项目名称:light-rest-4j,代码行数:23,代码来源:RequestValidator.java

示例6: setCorsResponseHeaders

import io.undertow.util.HeaderValues; //导入依赖的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

示例7: validateHeader

import io.undertow.util.HeaderValues; //导入依赖的package包/类
private void validateHeader(final UaiHeader uaiHeader, final HeaderMap requestHeaderMap, final RequestValidatorFacade.RequestAnalysisResult result) {
    final HeaderValues headerValueList = requestHeaderMap.get(uaiHeader.getName());

    if (headerValueList == null) {
        Log.infoFormatted(OPTIONAL_HEADER_NOT_FOUND, uaiHeader.getName());
        result.setInvalid();
        return;
    }

    if (uaiHeader.isUsingWildCard()) {
        Log.infoFormatted(WILD_CARD_USED, uaiHeader.getName());
        return;
    }

    if (!headerValueList.containsAll(uaiHeader.getValueList())) {
        Log.warnFormatted(HEADER_VALUE_NOT_FOUND_MESSAGE, uaiHeader.getValueList(), uaiHeader.getName());
        result.abortTheRequest();
    }
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:20,代码来源:OptionalHeaderValidator.java

示例8: validateHeader

import io.undertow.util.HeaderValues; //导入依赖的package包/类
private void validateHeader(final UaiHeader uaiHeader, final HeaderMap requestHeaderMap, final RequestValidatorFacade.RequestAnalysisResult result) {
    final HeaderValues headerValueList = requestHeaderMap.get(uaiHeader.getName());

    if (headerValueList == null) {
        Log.warnFormatted(REQUIRED_HEADER_NOT_FOUND, uaiHeader.getName());
        result.setInvalid();
        return;
    }

    if (uaiHeader.isUsingWildCard()) {
        Log.infoFormatted(WILD_CARD_USED, uaiHeader.getName());
        return;
    }

    if (!headerValueList.containsAll(uaiHeader.getValueList())) {
        Log.warnFormatted(HEADER_VALUE_NOT_FOUND_MESSAGE, uaiHeader.getValueList(), uaiHeader.getName());
        result.setInvalid();
    }
}
 
开发者ID:uaihebert,项目名称:uaiMockServer,代码行数:20,代码来源:RequiredHeaderValidator.java

示例9: handleRequest

import io.undertow.util.HeaderValues; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    Locale locale = Locale.forLanguageTag(this.config.getApplicationLanguage());
    Attachment attachment = exchange.getAttachment(RequestHelper.ATTACHMENT_KEY);

    Cookie i18nCookie = exchange.getRequestCookies().get(this.config.getI18nCookieName());
    if (i18nCookie == null) {
        final HeaderValues headerValues = exchange.getRequestHeaders().get(Header.ACCEPT_LANGUAGE.toHttpString());
        if (headerValues != null) {
            String acceptLanguage = headerValues.element();
            if (StringUtils.isNotBlank(acceptLanguage)) {
                locale = LocaleUtils.getLocaleFromString(acceptLanguage);
            }
        }
    } else {
        locale = LocaleUtils.getLocaleFromString(i18nCookie.getValue());
    }

    attachment.getMessages().reload(locale);
    attachment.withLocale(locale);
    
    exchange.putAttachment(RequestHelper.ATTACHMENT_KEY, attachment);
    nextHandler(exchange);
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:25,代码来源:LocaleHandler.java

示例10: connected

import io.undertow.util.HeaderValues; //导入依赖的package包/类
@Override
public void connected(ServerSentEventConnection connection, String lastEventId) {
    if (this.hasAuthentication) {
        String header = null;
        HeaderValues headerValues = connection.getRequestHeaders().get(Header.COOKIE.toHttpString());
        if (headerValues != null) {
            header = headerValues.element();
        }

        if (this.requestHelper.hasValidAuthentication(header)) {
            Application.getInstance(ServerSentEventService.class).addConnection(connection);
            connection.addCloseTask(Application.getInstance(ServerSentEventCloseListener.class));
        } else {
            IOUtils.closeQuietly(connection);
        }
    } else {
        Application.getInstance(ServerSentEventService.class).addConnection(connection);
        connection.addCloseTask(Application.getInstance(ServerSentEventCloseListener.class));
    }
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:21,代码来源:ServerSentEventHandler.java

示例11: determineMimeType

import io.undertow.util.HeaderValues; //导入依赖的package包/类
private static String determineMimeType(OperationResponse.StreamEntry entry, HttpServerExchange exchange) {
    // We see if the type provided by the response "matches" the ACCEPT header; if yes, use it
    // If not, use application/octet-stream to trigger the browser to treat it as a download
    String entryType = entry.getMimeType();
    HeaderValues headerValues = exchange.getRequestHeaders().get(Headers.ACCEPT);
    if (headerValues == null || headerValues.size() == 0) {
        // The browser doesn't care
        return entryType;
    }
    String wildCard = null;
    int slash = entryType.indexOf('/');
    if (slash > 0) {
        wildCard = entryType.substring(0, slash) + "/*";
    }
    for (String acceptable : headerValues) {
        if ("*/*".equals(acceptable) || acceptable.contains(entryType) || (wildCard != null && acceptable.contains(wildCard))) {
            return entryType;
        }
    }

    return "application/octet-stream";
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:23,代码来源:DomainUtil.java

示例12: setCorsResponseHeaders

import io.undertow.util.HeaderValues; //导入依赖的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

示例13: handleRequest

import io.undertow.util.HeaderValues; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    if (forceCompression) {
        HeaderValues acceptedEncodings = exchange.getRequestHeaders().get(Headers.ACCEPT_ENCODING_STRING);

        for (String values : acceptedEncodings) {
            if (Arrays.stream(values.split(",")).anyMatch((v) -> Headers.GZIP.toString().equals(v))) {
                super.handleRequest(exchange);
                return;
            }
        }

        RequestContext errorContext = new RequestContext(exchange, "/", "_error");

        ResponseHelper.endExchangeWithMessage(
                exchange,
                errorContext,
                HttpStatus.SC_BAD_REQUEST,
                "Accept-Encoding header must include gzip");

        sender.handleRequest(exchange, errorContext);
    } else {
        super.handleRequest(exchange);
    }
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:26,代码来源:GzipEncodingHandler.java

示例14: getHeaders

import io.undertow.util.HeaderValues; //导入依赖的package包/类
@Override
public Collection<String> getHeaders(final String name) {
    HeaderValues headers = exchange.getResponseHeaders().get(name);
    if(headers == null) {
        return Collections.emptySet();
    }
    return new ArrayList<>(headers);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:HttpServletResponseImpl.java

示例15: SavedRequest

import io.undertow.util.HeaderValues; //导入依赖的package包/类
public SavedRequest(byte[] data, int dataLength, HttpString method, String requestPath, HeaderMap headerMap) {
    this.data = data;
    this.dataLength = dataLength;
    this.method = method;
    this.requestPath = requestPath;
    for(HeaderValues val : headerMap) {
        this.headerMap.put(val.getHeaderName(), new ArrayList<>(val));
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:SavedRequest.java


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