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


Java HeaderMap.clear方法代码示例

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


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

示例1: testMatchOrigin

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
/**
 * Test of matchOrigin method, of class CorsUtil.
 */
@Test
public void testMatchOrigin() throws Exception {
    HeaderMap headerMap = new HeaderMap();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://localhost");
    HttpServerExchange exchange = new HttpServerExchange(null, headerMap, new HeaderMap(), 10);
    exchange.setRequestScheme("http");
    exchange.setRequestMethod(HttpString.EMPTY);
    Collection<String> allowedOrigins = null;
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
    allowedOrigins = Collections.singletonList("http://www.example.com:9990");
    //Default origin
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
    headerMap.clear();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://www.example.com:9990");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://www.example.com:9990"));
    headerMap.clear();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://www.example.com");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is(nullValue()));
    headerMap.addAll(ORIGIN, Arrays.asList("http://localhost:8080", "http://www.example.com:9990", "http://localhost"));
    allowedOrigins = Arrays.asList("http://localhost", "http://www.example.com:9990");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:29,代码来源:CorsUtilTest.java

示例2: testDefaultOrigin

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
/**
 * Test of defaultOrigin method, of class CorsUtil.
 */
@Test
public void testDefaultOrigin() {
    HeaderMap headerMap = new HeaderMap();
    headerMap.add(HOST, "localhost:80");
    HttpServerExchange exchange = new HttpServerExchange(null, headerMap, new HeaderMap(), 10);
    exchange.setRequestScheme("http");
    assertThat(CorsUtil.defaultOrigin(exchange), is("http://localhost"));
    headerMap.clear();
    headerMap.add(HOST, "www.example.com:8080");
    assertThat(CorsUtil.defaultOrigin(exchange), is("http://www.example.com:8080"));
    headerMap.clear();
    headerMap.add(HOST, "www.example.com:443");
    exchange.setRequestScheme("https");
    assertThat(CorsUtil.defaultOrigin(exchange), is("https://www.example.com"));
    headerMap.clear();
    exchange.setRequestScheme("http");
    headerMap.add(HOST, "[::1]:80");
    assertThat(CorsUtil.defaultOrigin(exchange), is("http://[::1]"));
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:23,代码来源:CorsUtilTest.java

示例3: testMatchOrigin

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
/**
 * Test of matchOrigin method, of class CorsUtil.
 */
@Test
public void testMatchOrigin() throws Exception {
    HeaderMap headerMap = new HeaderMap();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://localhost");
    HttpServerExchange exchange = new HttpServerExchange(null, headerMap, new HeaderMap(), 10);
    exchange.setRequestScheme("http");
    Collection<String> allowedOrigins = null;
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
    allowedOrigins = Collections.singletonList("http://www.example.com:9990");
    //Default origin
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
    headerMap.clear();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://www.example.com:9990");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://www.example.com:9990"));
    headerMap.clear();
    headerMap.add(HOST, "localhost:80");
    headerMap.add(ORIGIN, "http://www.example.com");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is(nullValue()));
    headerMap.addAll(ORIGIN, Arrays.asList("http://localhost:8080", "http://www.example.com:9990", "http://localhost"));
    allowedOrigins = Arrays.asList("http://localhost", "http://www.example.com:9990");
    assertThat(CorsUtil.matchOrigin(exchange, allowedOrigins), is("http://localhost"));
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:28,代码来源:CorsUtilTest.java

示例4: setResponseHeaders

import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Override
public void setResponseHeaders(final Map<String, List<String>> headers) {
    HeaderMap map = exchange.getRequestHeaders();
    map.clear();
    for (Map.Entry<String, List<String>> header : headers.entrySet()) {
        map.addAll(HttpString.tryFromString(header.getKey()), header.getValue());
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AsyncWebSocketHttpServerExchange.java


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