Java HttpServletResponse编写器在刷新时发送消息长度

Java HttpServletResponse编写器在刷新时发送消息长度,java,servlets,streaming,embedded-jetty,Java,Servlets,Streaming,Embedded Jetty,我对数据流有一些问题 在刷新常规数据块时,服务器会将其发送到实际损坏数据流的长度 (嵌入式jetty和嵌入式tomcat产生相同的结果。) 我使用netty作为客户端,它将数字记录为传入块的第一个字节(用\n\r分隔的常规行)。 还有jetty的记录器 DEBUG org.eclipse.jetty.io.WriteFlusher - write: WriteFlusher@ ... [HeapByteBuffer@ ... {<<<\r\n26\r\n>>>

我对数据流有一些问题 在刷新常规数据块时,服务器会将其发送到实际损坏数据流的长度

(嵌入式jetty和嵌入式tomcat产生相同的结果。)

我使用netty作为客户端,它将数字记录为传入块的第一个字节(用\n\r分隔的常规行)。 还有jetty的记录器

DEBUG org.eclipse.jetty.io.WriteFlusher - write: WriteFlusher@ ... [HeapByteBuffer@ ... {<<<\r\n26\r\n>>>...},DirectByteBuffer@...{<<<event: put\ndata:{...rty':'value'}\n\n>>>...}]
DEBUG org.eclipse.jetty.io.WriteFlusher-write:WriteFlusher@。。。[HeapByteBuffer@…{…},DirectByteBuffer@...{“+味精);
}
@凌驾
public void channelActive(ChannelHandlerContext上下文){
System.out.println(“活动!”);
HttpRequest请求=新的DefaultHttpRequest(HttpVersion.HTTP_1_1,HttpMethod.GET,uri.toString());
request.headers().add(HttpHeaders.Names.ACCEPT,“文本/事件流”);
request.headers().add(HttpHeaders.Names.HOST,uri.getHost());
request.headers().add(HttpHeaders.Names.ORIGIN,“http:/”+uri.getHost());
context.channel().writeAndFlush(请求);
}
});
}
})
.connect();
线程。睡眠(500_000);
}
}
依赖项:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.2</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.0.9</version>
    </dependency>

    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-all</artifactId>
      <version>5.0.0.Alpha1</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-servlet</artifactId>
      <version>9.4.2.v20170220</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

4.0.0
com.test
测试
1.0-快照
org.slf4j
slf4j api
1.7.2
回写
回归经典
1.0.9
伊奥·内蒂
讨厌的
5.0.0.1
朱尼特
朱尼特
4.12
org.eclipse.jetty
码头servlet
9.4.2.v20170220
maven编译器插件
1.8
1.8

这是您看到的标准HTTP/1.1分块传输编码

如果您的响应没有
内容长度
头,并且连接要保持持久性(根据HTTP/1.1规范),则会发生分块

如果您有HTTP/1.1客户端,并且不能在服务器端设置<代码>内容长度< /代码>头,请考虑设置<代码>连接:关闭< /COD>请求和/或响应头,因为这将取消触发分块传输编码的持久连接模式。 建议:支持分块传输编码是明智的,因为您可以从任意数量的位置(甚至代理)看到这一点

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.2</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.0.9</version>
    </dependency>

    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-all</artifactId>
      <version>5.0.0.Alpha1</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-servlet</artifactId>
      <version>9.4.2.v20170220</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>