io.netty.handler.codec.http.HttpResponse.addHeader()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中io.netty.handler.codec.http.HttpResponse.addHeader()方法的一些代码示例,展示了HttpResponse.addHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.addHeader()方法的具体详情如下:
包路径:io.netty.handler.codec.http.HttpResponse
类名称:HttpResponse
方法名:addHeader

HttpResponse.addHeader介绍

暂无

代码示例

代码示例来源:origin: shuaiweili/Dubbo-Zookeeper-Netty-SpringMVC

@Override
public void messageReceived(ChannelHandlerContext ctx, HttpRequest request) throws Exception {
  if (!request.getDecoderResult().isSuccess()) {
    sendError(ctx, BAD_REQUEST);
    return;
  }
  MockHttpServletRequest servletRequest = createServletRequest(request);
  MockHttpServletResponse servletResponse = new MockHttpServletResponse();
  this.servlet.service(servletRequest, servletResponse);
  HttpResponseStatus status = HttpResponseStatus.valueOf(servletResponse.getStatus());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  for (String name : servletResponse.getHeaderNames()) {
    for (Object value : servletResponse.getHeaderValues(name)) {
      response.addHeader(name, value);
    }
  }
  // Write the initial line and the header.
  ctx.write(response);
  InputStream contentStream = new ByteArrayInputStream(servletResponse.getContentAsByteArray());
  // Write the content.
  ChannelFuture writeFuture = ctx.write(new ChunkedStream(contentStream));
  writeFuture.addListener(ChannelFutureListener.CLOSE);
}

代码示例来源:origin: linsongze/nettyholdspringmvc

@Override
public void messageReceived(ChannelHandlerContext ctx, HttpRequest request) throws Exception {
  if (!request.getDecoderResult().isSuccess()) {
    sendError(ctx, BAD_REQUEST);
    return;
  }
  MockHttpServletRequest servletRequest = createServletRequest(request);
  MockHttpServletResponse servletResponse = new MockHttpServletResponse();
  this.servlet.service(servletRequest, servletResponse);
  HttpResponseStatus status = HttpResponseStatus.valueOf(servletResponse.getStatus());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  for (String name : servletResponse.getHeaderNames()) {
    for (Object value : servletResponse.getHeaderValues(name)) {
      response.addHeader(name, value);
    }
  }
  // Write the initial line and the header.
  ctx.write(response);
  InputStream contentStream = new ByteArrayInputStream(servletResponse.getContentAsByteArray());
  // Write the content.
  ChannelFuture writeFuture = ctx.write(new ChunkedStream(contentStream));
  writeFuture.addListener(ChannelFutureListener.CLOSE);
}

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

cookieEncoder.addCookie(cookie);
response.addHeader(HttpHeaders.Names.SET_COOKIE, cookieEncoder
    .encode());

代码示例来源:origin: org.jboss.errai.io.netty/netty-example

cookieEncoder.addCookie(cookie);
response.addHeader(SET_COOKIE, cookieEncoder.encode());

相关文章