org.jboss.netty.handler.codec.http.HttpResponse.isChunked()方法的使用及代码示例

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

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

HttpResponse.isChunked介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-druid

possiblySuspendReads(response);
if (!httpResponse.isChunked()) {
 finishRequest();

代码示例来源:origin: io.netty/netty

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  if (!readingChunks) {
    HttpResponse res = (HttpResponse) e.getMessage();
    if (res.getStatus().getCode() != HttpResponseStatus.OK.getCode()) {
      throw new ChannelException("Unexpected HTTP response status: " + res.getStatus());
    }
    if (res.isChunked()) {
      readingChunks = true;
    } else {
      ChannelBuffer content = res.getContent();
      if (content.readable()) {
        fireMessageReceived(HttpTunnelingClientSocketChannel.this, content);
      }
      // Reached to the end of response - close the request.
      closeReal(succeededFuture(virtualChannel));
    }
  } else {
    HttpChunk chunk = (HttpChunk) e.getMessage();
    if (!chunk.isLast()) {
      fireMessageReceived(HttpTunnelingClientSocketChannel.this, chunk.getContent());
    } else {
      readingChunks = false;
      // Reached to the end of response - close the request.
      closeReal(succeededFuture(virtualChannel));
    }
  }
}

代码示例来源:origin: io.netty/netty

private SpdySynReplyFrame createSynReplyFrame(HttpResponse httpResponse)
    throws Exception {
  boolean chunked = httpResponse.isChunked();
  // Get the Stream-ID from the headers
  int streamId = SpdyHttpHeaders.getStreamId(httpResponse);
  SpdyHttpHeaders.removeStreamId(httpResponse);
  // The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
  // headers are not valid and MUST not be sent.
  httpResponse.headers().remove(HttpHeaders.Names.CONNECTION);
  httpResponse.headers().remove("Keep-Alive");
  httpResponse.headers().remove("Proxy-Connection");
  httpResponse.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);
  SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamId);
  spdySynReplyFrame.setLast(!chunked && !httpResponse.getContent().readable());
  // Unfold the first line of the response into name/value pairs
  SpdyHeaders.setStatus(spdyVersion, spdySynReplyFrame, httpResponse.getStatus());
  SpdyHeaders.setVersion(spdyVersion, spdySynReplyFrame, httpResponse.getProtocolVersion());
  // Transfer the remaining HTTP headers
  for (Map.Entry<String, String> entry: httpResponse.headers()) {
    spdySynReplyFrame.headers().add(entry.getKey(), entry.getValue());
  }
  return spdySynReplyFrame;
}

代码示例来源:origin: webbit/webbit

private NettyHttpResponse content(ChannelBuffer content) {
  if (response.isChunked()) {
    throw new UnsupportedOperationException();
  }
  responseBuffer.writeBytes(content);
  return this;
}

代码示例来源:origin: webbit/webbit

@Override
public NettyHttpResponse write(String content) {
  if (response.isChunked()) {
    ctx.getChannel().write(new DefaultHttpChunk(wrappedBuffer(content.getBytes(CharsetUtil.UTF_8))));  
  } else {
    write(copiedBuffer(content, CharsetUtil.UTF_8));
  }    
  return this;
}

代码示例来源:origin: webbit/webbit

private void flushResponse() {
  try {
    // TODO: Shouldn't have to do this, but without it we sometimes seem to get two Content-Length headers in the response.
    header("Content-Length", (String) null);
    header("Content-Length", responseBuffer.readableBytes());
    ChannelFuture  future = response.isChunked() ? ctx.getChannel().write(new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER)) : write(responseBuffer);
    if (!isKeepAlive) {
      future.addListener(ChannelFutureListener.CLOSE);
    }
  } catch (Exception e) {
    exceptionHandler.uncaughtException(Thread.currentThread(),
        WebbitException.fromException(e, ctx.getChannel()));
  }
}

代码示例来源:origin: com.ning/async-http-client

private boolean exitAfterHandlingBody(Channel channel, NettyResponseFuture<?> future, HttpResponse response, AsyncHandler<?> handler)
    throws Exception {
  if (!response.isChunked()) {
    // no chunks expected, exiting
    if (response.getContent().readableBytes() > 0)
      // FIXME no need to notify an empty bodypart?
      updateBodyAndInterrupt(future, handler, new NettyResponseBodyPart(response, null, true));
    finishUpdate(future, channel, false);
    return true;
  }
  return false;
}

代码示例来源:origin: com.ning/async-http-client

if (future.isKeepAlive() && !HttpHeaders.isTransferEncodingChunked(response) && !response.isChunked()) {
  future.setConnectAllowed(true);
  future.setReuseChannel(true);

代码示例来源:origin: com.ning/async-http-client

if (future.isKeepAlive() && !HttpHeaders.isTransferEncodingChunked(response) && !response.isChunked()) {
  future.setReuseChannel(true);
} else {

代码示例来源:origin: org.webbitserver/webbit

private NettyHttpResponse content(ChannelBuffer content) {
  if (response.isChunked()) {
    throw new UnsupportedOperationException();
  }
  responseBuffer.writeBytes(content);
  return this;
}

代码示例来源:origin: com.ning/async-http-client

if (future.isKeepAlive() && !HttpHeaders.isTransferEncodingChunked(response) && !response.isChunked()) {

代码示例来源:origin: neilbeveridge/zuul-netty

LOG.debug("response is chunked: {} {}", ((HttpResponse) e.getMessage()).isChunked(), outboundNull() ? WENT_AWAY
      : outboundConnection.getId());
if (e.getMessage() instanceof HttpResponse && !((HttpResponse) e.getMessage()).isChunked()) {

代码示例来源:origin: org.webbitserver/webbit

@Override
public NettyHttpResponse write(String content) {
  if (response.isChunked()) {
    ctx.getChannel().write(new DefaultHttpChunk(wrappedBuffer(content.getBytes(CharsetUtil.UTF_8))));  
  } else {
    write(copiedBuffer(content, CharsetUtil.UTF_8));
  }    
  return this;
}

代码示例来源:origin: org.webbitserver/webbit

private void flushResponse() {
  try {
    // TODO: Shouldn't have to do this, but without it we sometimes seem to get two Content-Length headers in the response.
    header("Content-Length", (String) null);
    header("Content-Length", responseBuffer.readableBytes());
    ChannelFuture  future = response.isChunked() ? ctx.getChannel().write(new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER)) : write(responseBuffer);
    if (!isKeepAlive) {
      future.addListener(ChannelFutureListener.CLOSE);
    }
  } catch (Exception e) {
    exceptionHandler.uncaughtException(Thread.currentThread(),
        WebbitException.fromException(e, ctx.getChannel()));
  }
}

代码示例来源:origin: org.asynchttpclient/async-http-client-netty3-provider

private boolean exitAfterHandlingBody(Channel channel, NettyResponseFuture<?> future, HttpResponse response,
    AsyncHandler<?> handler) throws Exception {
  if (!response.isChunked()) {
    // no chunks expected, exiting
    if (response.getContent().readableBytes() > 0)
      // FIXME no need to notify an empty bodypart?
      updateBodyAndInterrupt(future, handler, new NettyResponseBodyPart(response, null, true));
    finishUpdate(future, channel, false);
    return true;
  }
  return false;
}

代码示例来源:origin: io.gatling/async-http-client

private boolean exitAfterHandlingBody(Channel channel, NettyResponseFuture<?> future, HttpResponse response,
    AsyncHandler<?> handler) throws Exception {
  if (!response.isChunked()) {
    // no chunks expected, exiting
    if (response.getContent().readableBytes() > 0)
      // FIXME no need to notify an empty bodypart?
      updateBodyAndInterrupt(future, handler, new NettyResponseBodyPart(response, null, true));
    finishUpdate(future, channel, false);
    return true;
  }
  return false;
}

代码示例来源:origin: org.asynchttpclient/async-http-client-netty3

private boolean exitAfterHandlingBody(Channel channel, NettyResponseFuture<?> future, HttpResponse response,
    AsyncHandler<?> handler) throws Exception {
  if (!response.isChunked()) {
    // no chunks expected, exiting
    if (response.getContent().readableBytes() > 0) {
      // no need to notify an empty bodypart
      updateBodyAndInterrupt(future, handler, new NettyResponseBodyPart(response, null, true));
    }
    finishUpdate(future, channel, false);
    return true;
  }
  return false;
}

代码示例来源:origin: landy8530/netty-file-parent

public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
    throws Exception {
  if (!this.readingChunks) {
    HttpResponse response = (HttpResponse) e.getMessage();
    LOGGER.info("STATUS: " + response.getStatus());
    if ((response.getStatus().getCode() == 200)
        && (response.isChunked())) {
      this.readingChunks = true;
    } else {
      ChannelBuffer content = response.getContent();
      if (content.readable())
        this.responseContent.append(content
            .toString(CharsetUtil.UTF_8));
    }
  } else {
    HttpChunk chunk = (HttpChunk) e.getMessage();
    if (chunk.isLast()) {
      this.readingChunks = false;
      this.responseContent.append(chunk.getContent().toString(
          CharsetUtil.UTF_8));
      String json = this.responseContent.toString();
      this.result = ((Result) JSONUtil.parseObject(json,Result.class));
    } else {
      this.responseContent.append(chunk.getContent().toString(
          CharsetUtil.UTF_8));
    }
  }
}

代码示例来源:origin: org.vert-x/vertx-core

conn.handleResponseChunk(new Buffer(content));
if (!response.isChunked() && (response.getStatus().getCode() != 100)) {
 conn.handleResponseEnd();

代码示例来源:origin: com.couchbase.client/couchbase-client

private void logResponse(HttpResponse response) {
 finerLog("STATUS: " + response.getStatus());
 finerLog("VERSION: " + response.getProtocolVersion());
 if (!response.getHeaderNames().isEmpty()) {
  for (String name : response.getHeaderNames()) {
   for (String value : response.getHeaders(name)) {
    finerLog("HEADER: " + name + " = " + value);
   }
  }
  finerLog(System.getProperty("line.separator"));
 }
 if (response.getStatus().getCode() == 200 && response.isChunked()) {
  readingChunks = true;
  finerLog("CHUNKED CONTENT {");
 } else if(response.getStatus().getCode() == 200) {
  ChannelBuffer content = response.getContent();
  if (content.readable()) {
   finerLog("CONTENT {");
   finerLog(content.toString(CharsetUtil.UTF_8));
   finerLog("} END OF CONTENT");
  }
 } else {
  throw new ConnectionException("Could not retrieve configuration chunk. "
   + "Response Code is: " + response.getStatus());
 }
}

相关文章