本文整理汇总了Java中io.undertow.util.HeaderValues.element方法的典型用法代码示例。如果您正苦于以下问题:Java HeaderValues.element方法的具体用法?Java HeaderValues.element怎么用?Java HeaderValues.element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.util.HeaderValues
的用法示例。
在下文中一共展示了HeaderValues.element方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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));
}
}
示例4: getCacheKey
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
/**
* Creates a key for used for limit an request containing the
* requested url and the source host
*
* @param exchange The HttpServerExchange
* @return The key url + host
*/
private String getCacheKey(HttpServerExchange exchange) {
String host = null;
HeaderMap headerMap = exchange.getRequestHeaders();
if (headerMap != null) {
HeaderValues headerValues = headerMap.get(Header.X_FORWARDED_FOR.toHttpString());
if (headerValues != null) {
host = headerValues.element();
}
}
if (StringUtils.isBlank(host)) {
InetSocketAddress inetSocketAddress = exchange.getSourceAddress();
if (inetSocketAddress != null) {
host = inetSocketAddress.getHostString();
}
}
if (StringUtils.isNotBlank(host)) {
host = host.toLowerCase(Locale.ENGLISH);
}
String url = exchange.getRequestURL();
if (StringUtils.isNotBlank(url)) {
url = url.toLowerCase(Locale.ENGLISH);
}
return url + host;
}