本文整理匯總了Java中io.netty.handler.codec.http.HttpHeaders.setHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders.setHeader方法的具體用法?Java HttpHeaders.setHeader怎麽用?Java HttpHeaders.setHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.handler.codec.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.setHeader方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleNonProxyRequest
import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
protected HttpResponse handleNonProxyRequest(FullHttpRequest req) {
String uri = req.getUri();
if ("/version".equals(uri)) {
if (HttpMethod.GET.equals(req.getMethod())) {
JsonObject jsonObj = new JsonObject();
jsonObj.addProperty("name", m_appConfig.getAppName());
jsonObj.addProperty("version", m_appConfig.getAppVersion());
byte[] content = jsonObj.toString().getBytes(CharsetUtil.UTF_8);
DefaultFullHttpResponse resp = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
Unpooled.copiedBuffer(content));
HttpHeaders.setKeepAlive(resp, false);
HttpHeaders.setHeader(resp, HttpHeaders.Names.CONTENT_TYPE,
"application/json");
HttpHeaders.setContentLength(resp, content.length);
return resp;
}
}
return RESPONSE_404;
}
示例2: addEventResultHeader
import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
private void addEventResultHeader(HttpResponse response) {
EventResult result = Context.requestScope().getExecutedEventResult();
if (result != null) {
String strExtResult = response.headers().get(Headers.CIBET_EVENTRESULT.name());
if (strExtResult != null) {
EventResult extResult = CibetUtil.decodeEventResult(strExtResult);
extResult.setParentResult(result);
result.getChildResults().add(extResult);
}
try {
String strResult = Base64.encodeBase64String(CibetUtil.encode(result));
HttpHeaders.setHeader(response, Headers.CIBET_EVENTRESULT.name(), strResult);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
}
示例3: createOfflineResponse
import io.netty.handler.codec.http.HttpHeaders; //導入方法依賴的package包/類
private HttpResponse createOfflineResponse() {
ByteBuf buffer = Unpooled.wrappedBuffer("Offline response".getBytes());
HttpResponse response = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buffer);
HttpHeaders.setContentLength(response, buffer.readableBytes());
HttpHeaders.setHeader(response, HttpHeaders.Names.CONTENT_TYPE,
"text/html");
return response;
}