本文整理汇总了Java中io.undertow.server.HttpServerExchange.getRequestScheme方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.getRequestScheme方法的具体用法?Java HttpServerExchange.getRequestScheme怎么用?Java HttpServerExchange.getRequestScheme使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.HttpServerExchange
的用法示例。
在下文中一共展示了HttpServerExchange.getRequestScheme方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRedirect
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
static void sendRedirect(final HttpServerExchange exchange, final String location) {
// TODO - String concatenation to construct URLS is extremely error prone - switch to a URI which will better handle this.
String loc = exchange.getRequestScheme() + "://" + exchange.getHostAndPort() + location;
exchange.getResponseHeaders().put(Headers.LOCATION, loc);
}
示例2: redirect
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
/**
* Redirects to a new relative path. All other data from the exchange is preserved.
*
* @param exchange The HTTP server exchange
* @param newRelativePath The new relative path
* @param includeParameters If query and path parameters from the exchange should be included
* @return
*/
public static String redirect(final HttpServerExchange exchange, final String newRelativePath, final boolean includeParameters) {
try {
StringBuilder uri = new StringBuilder(exchange.getRequestScheme());
uri.append("://");
uri.append(exchange.getHostAndPort());
uri.append(encodeUrlPart(exchange.getResolvedPath()));
if (exchange.getResolvedPath().endsWith("/")) {
if (newRelativePath.startsWith("/")) {
uri.append(encodeUrlPart(newRelativePath.substring(1)));
} else {
uri.append(encodeUrlPart(newRelativePath));
}
} else {
if (!newRelativePath.startsWith("/")) {
uri.append('/');
}
uri.append(encodeUrlPart(newRelativePath));
}
if (includeParameters) {
if (!exchange.getPathParameters().isEmpty()) {
boolean first = true;
uri.append(';');
for (Map.Entry<String, Deque<String>> param : exchange.getPathParameters().entrySet()) {
for (String value : param.getValue()) {
if (first) {
first = false;
} else {
uri.append('&');
}
uri.append(URLEncoder.encode(param.getKey(), UTF_8));
uri.append('=');
uri.append(URLEncoder.encode(value, UTF_8));
}
}
}
if (!exchange.getQueryString().isEmpty()) {
uri.append('?');
uri.append(exchange.getQueryString());
}
}
return uri.toString();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}