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


Java DefaultFullHttpResponse.headers方法代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.DefaultFullHttpResponse.headers方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultFullHttpResponse.headers方法的具體用法?Java DefaultFullHttpResponse.headers怎麽用?Java DefaultFullHttpResponse.headers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.codec.http.DefaultFullHttpResponse的用法示例。


在下文中一共展示了DefaultFullHttpResponse.headers方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: directHandleMethod

import io.netty.handler.codec.http.DefaultFullHttpResponse; //導入方法依賴的package包/類
private boolean directHandleMethod(ChannelHandlerContext ctx, FullHttpRequest request, HttpMethod method) {
	if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.POST)) {
		return false;
	}
	// 處理 OPTIONS 請求
	HttpResponseStatus status = HttpResponseStatus.OK;
	boolean invalid = false;
	if (!method.equals(HttpMethod.OPTIONS)) {
		invalid = true;
		status = HttpResponseStatus.METHOD_NOT_ALLOWED;
	}
	DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, status, Unpooled.EMPTY_BUFFER);
	HttpHeaders headers = response.headers();
	// headers.set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS,
	// "X-Requested-With, accept, origin, content-type");
	headers.set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, "X-Requested-With, content-type");
	headers.set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_METHODS, "GET,POST,OPTIONS");
	headers.set(HttpHeaderNames.SERVER, "Netty5");
	if (invalid) {
		headers.set("Client-Warning", "Invalid Method");
	}
	boolean keepAlive = HttpHeaderUtil.isKeepAlive(request);
	if (keepAlive) {
		response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
	}
	ctx.write(response);
	ChannelFuture future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
	if (!keepAlive) {
		future.addListener(ChannelFutureListener.CLOSE);
	}
	return true;
}
 
開發者ID:houkx,項目名稱:nettythrift,代碼行數:33,代碼來源:HttpThriftBufDecoder.java

示例2: wrapMessage

import io.netty.handler.codec.http.DefaultFullHttpResponse; //導入方法依賴的package包/類
@Override
public Object wrapMessage(ChannelHandlerContext ctx, ThriftMessage msg) {
	HttpResponseStatus status = HttpResponseStatus.OK;
	DefaultFullHttpResponse httpResp = new DefaultFullHttpResponse(HTTP_1_1, status, msg.getContent());
	HttpHeaders headers = httpResp.headers();
	headers.set(HttpHeaderNames.CONTENT_TYPE, "application/json");
	headers.set(HttpHeaderNames.SERVER, "Netty5");
	filterResponse(httpResp, msg);
	return httpResp;
}
 
開發者ID:houkx,項目名稱:nettythrift,代碼行數:11,代碼來源:HttpThriftBufDecoder.java


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