當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpResponseStatus.MOVED_PERMANENTLY屬性代碼示例

本文整理匯總了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()));
}
 
開發者ID:iceize,項目名稱:netty-http-3.x,代碼行數:32,代碼來源:StaticActionDispatcher.java

示例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));
}
 
開發者ID:iceize,項目名稱:netty-http-3.x,代碼行數:11,代碼來源:Redirect.java


注:本文中的org.jboss.netty.handler.codec.http.HttpResponseStatus.MOVED_PERMANENTLY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。