本文整理匯總了Java中org.jboss.netty.handler.codec.http.HttpResponseStatus.MOVED_PERMANENTLY屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponseStatus.MOVED_PERMANENTLY屬性的具體用法?Java HttpResponseStatus.MOVED_PERMANENTLY怎麽用?Java HttpResponseStatus.MOVED_PERMANENTLY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.jboss.netty.handler.codec.http.HttpResponseStatus
的用法示例。
在下文中一共展示了HttpResponseStatus.MOVED_PERMANENTLY屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dispatch
@Override
public void dispatch(ChannelHandlerContext context, Action action, Request request, Response response) {
StaticAction staticAction = (StaticAction) action;
if (staticAction.contents() == null) {
response.status = HttpResponseStatus.MOVED_PERMANENTLY;
response.headers.put(HttpHeaders.Names.LOCATION, new Header(HttpHeaders.Names.LOCATION, staticAction.path() + Context.PATH_DELIMITER));
}
if (!settings.isCache()) {
response.output = staticAction.contents();
response.contentType = Context.getContentType(staticAction.path());
return;
}
if (needCache(request, staticAction)) {
response.status = HttpResponseStatus.NOT_MODIFIED;
response.header(HttpHeaders.Names.DATE, FastDateFormat.getInstance(HTTP_DATE_FORMAT, TimeZone.getTimeZone("GMT"), Locale.US).format(Calendar.getInstance()));
return;
}
response.output = staticAction.contents();
response.contentType = Context.getContentType(staticAction.path());
Calendar calendar = Calendar.getInstance();
FastDateFormat dateFormat = FastDateFormat.getInstance(HTTP_DATE_FORMAT, TimeZone.getTimeZone("GMT"), Locale.US);
response.header(HttpHeaders.Names.DATE, dateFormat.format(calendar));
calendar.add(Calendar.SECOND, settings.getCacheTtl());
response.header(HttpHeaders.Names.EXPIRES, dateFormat.format(calendar));
response.header(HttpHeaders.Names.CACHE_CONTROL, "private, max-age=" + settings.getCacheTtl());
response.header(HttpHeaders.Names.LAST_MODIFIED, dateFormat.format(staticAction.timestamp()));
}
示例2: apply
@Override
public void apply(Object result, Request request, Response response) {
String url = result.toString();
if (!StringUtils.startsWith(url, "http")) {
url = "http://" + request.host + ":" + request.port + url;
}
response.status = HttpResponseStatus.MOVED_PERMANENTLY;
response.headers.put(HttpHeaders.Names.LOCATION, new Header(HttpHeaders.Names.LOCATION, url));
}