我自己的答案,经过研究。
第一部分:似乎没有办法说服我测试的应用程序服务器在“提交”阶段之后将错误放到线路上。以下 Servlet 代码会在套接字上生成合法的 HTTP 块传输标头。有趣的是,在 WebSphere 的情况下,一条错误消息被附加到流的末尾,位于结束标记之前。
public class Servlet extends HttpServlet {
public static final int ARRAY_SIZE = 65536;
private static final int SEND_COUNT = 100000;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
String testData = "This is a fairly long piece of test text, running on and on and on, over and over.";
final ServletOutputStream outputStream = response.getOutputStream();
for (int i = 0; i < SEND_COUNT; ++i) {
outputStream.println(testData);
}
throw new ServletException("Break it now");
}
}
第二部分:即使应用程序服务器愿意将虚假数据写入线路或关闭套接字而不关闭零长度块,普通客户端也不会报告错误。IE7、FF3 和 cURL 不会报告块编码错误。这使得 HTTP 下载本质上是不可靠的,如果不是 HTTP 1.1 RFC 的文字,这也违背了精神。