分块字段的默认值-(setChunked)

时间:2019-01-27 05:26:29

标签: java vert.x

我看到了:

https://vertx.io/docs/kdoc/vertx/io.vertx.rxjava.core.http/-http-server-response/set-chunked.html

vertx.createHttpServer()
  .requestHandler(req -> {

    if (req.method() == HttpMethod.GET) {

      req.response().setChunked(true);

    }
 })

我认为默认情况下,chunked为true,但我在文档中找不到默认值。有人知道默认值是什么吗?

2 个答案:

答案 0 :(得分:2)

setChunkedtransfer-encoding标头设置为chunked

当您使用write方法向客户端发送一些内容时,Vert.x会验证是否设置了transfer-encodingcontent-length标头。

答案 1 :(得分:1)

添加前面的答案,您可以在此处查看实际代码:

https://github.com/eclipse-vertx/vert.x/blob/f68ae15171053d343590e54884ec377f095ba6b3/src/main/java/io/vertx/core/http/impl/HttpServerResponseImpl.java#L142

public HttpServerResponseImpl setChunked(boolean chunked) {
    synchronized (conn) {
      checkValid();
      // HTTP 1.0 does not support chunking so we ignore this if HTTP 1.0
      if (version != HttpVersion.HTTP_1_0) {
        headers.set(HttpHeaders.TRANSFER_ENCODING, chunked ? "chunked" : null);
      }
      return this;
    }
  }