本文整理汇总了Java中io.undertow.util.HeaderMap.addAll方法的典型用法代码示例。如果您正苦于以下问题:Java HeaderMap.addAll方法的具体用法?Java HeaderMap.addAll怎么用?Java HeaderMap.addAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.util.HeaderMap
的用法示例。
在下文中一共展示了HeaderMap.addAll方法的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"));
}
示例2: 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"));
}
示例3: 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());
}
}
示例4: header
import io.undertow.util.HeaderMap; //导入方法依赖的package包/类
@Override
public Response header(String name, String... values) {
HeaderMap hm = this.exchange.getResponseHeaders();
hm.remove(name);
hm.addAll(new HttpString(name), Arrays.asList(values));
return this;
}