本文整理汇总了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;
}