在过去两个月中,我在Chrome的开发者控制台上收到以下错误:
net::ERR_INCOMPLETE_CHUNKED_ENCODING
Run Code Online (Sandbox Code Playgroud)
症状:
服务器环境:
在我们内部的Apache服务器上发生了这种情况.它不会发生在任何其他人身上 - 即我们的用户都没有遇到这个问题 - 我们的开发团队也没有其他人.
其他人使用完全相同的Chrome版本访问完全相同的服务器.我还尝试禁用所有扩展程序并在隐身模式下浏览 - 无效.
我使用过Firefox并且发生了同样的事情.截断的文件和诸如此类的东西.唯一的问题是,Firefox不会引发任何控制台错误,因此您需要通过Firebug检查HTTP请求以查看问题.
来自Apache的响应标头:
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:close
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Mon, 27 Apr 2015 10:52:52 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:Apache/2.2.22 (Ubuntu)
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:PHP/5.3.10-1ubuntu3.8
Run Code Online (Sandbox Code Playgroud)
在测试时,我能够通过在我的htaccess文件中强制HTTP 1.0来解决问题:
SetEnv downgrade-1.0
Run Code Online (Sandbox Code Playgroud)
这摆脱了问题.但是,通过HTTP 1.1强制HTTP 1.0不是一个合适的解决方案.
更新:因为我是唯一一个遇到此问题的人,我认为我需要花更多的时间来调查它是否是客户端问题.如果我进入Chrome的设置并使用"恢复默认设置"选项,问题将消失大约10-20分钟.然后它返回.
我们正在使用RESTlet为我们的项目做一个小的REST服务器.我们在继承自的类中设置了一堆路由Application:
public static void createRestServer(ApplicationContext appCtx, String propertiesPath) throws Exception {
// Create a component
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8081);
component.getClients().add(Protocol.FILE);
component.getClients().add(Protocol.CLAP);
Context context = component.getContext().createChildContext();
RestServer application = new RestServer(context);
application.getContext().getParameters().add("useForwardedForHeader", "true");
application.getContext().getAttributes().put("appCtx", appCtx);
application.getContext().getAttributes().put("file", propertiesPath);
// Attach the application to the component and start it
component.getDefaultHost().attach(application);
component.start();
}
private RestServer(Context context) {
super(context);
}
public synchronized Restlet createInboundRoot() {
Router router = new Router(getContext());
// we then have a bunch of these
router.attach("/accounts/{accountId}", AccountFetcher.class); …Run Code Online (Sandbox Code Playgroud) 我试图权衡设置Content-LengthHTTP标头与使用分块编码从我的服务器返回[可能]大文件的优缺点.需要使用持久连接来满足HTTP 1.1规范中的一个或另一个.我看到Content-Length标题的优点是:
缺点是必须在返回对象之前计算大小,这并不总是实用并且可能会增加服务器/数据库利用率.分块编码的缺点是在每个块和下载进度条之前添加块大小的开销很小.有什么想法吗?我可能没有想到的两种方法的任何其他HTTP注意事项?
我试图让我的网络服务器正确gzip一个块响应编码的http响应.
我对非gzip响应的理解是它看起来像这样:
<the response headers>
Run Code Online (Sandbox Code Playgroud)
然后对于每个块,
<chunk length in hex>\r\n<chunk>\r\n
Run Code Online (Sandbox Code Playgroud)
最后,一个零长度的块:
0\r\n\r\n
Run Code Online (Sandbox Code Playgroud)
我试图让gzip压缩工作,我可以使用一些帮助找出实际应该返回的内容.此文档暗示整个响应应该被gzip压缩,而不是gzipping每个块:
HTTP servers sometimes use compression (gzip) or deflate methods to optimize transmission.
Chunked transfer encoding can be used to delimit parts of the compressed object.
In this case the chunks are not individually compressed. Instead, the complete payload
is compressed and the output of the compression process is chunk encoded.
Run Code Online (Sandbox Code Playgroud)
我尝试gzip整个事情并返回响应,即使没有分块,它没有工作.我尝试将Content-Encoding标头设置为"gzip".有人可以解释必须对上述方案进行哪些更改才能支持gzipping的大小调整?谢谢.
我搜索了这个问题,但没有答案.
我希望我的PHP脚本在chunked中生成HTTP响应(http://en.wikipedia.org/wiki/Chunked_transfer_encoding).怎么做?
更新:我明白了.我必须指定Transfer-encoding标头并刷新它.
header("Transfer-encoding: chunked");
flush();
Run Code Online (Sandbox Code Playgroud)
冲洗是必要的.否则,将生成Content-Length标头.
而且,我必须自己制作块.有了辅助功能,并不难.
function dump_chunk($chunk)
{
echo sprintf("%x\r\n", strlen($chunk));
echo $chunk;
echo "\r\n";
}
Run Code Online (Sandbox Code Playgroud) HTTP/1.1指定发送的响应Transfer-Encoding: chunked可以包括可选的预告片(即通常作为标题发送的内容,但出于任何原因无法在内容之前计算,因此它们可以附加到结尾),例如:
请求:
GET /trailers.html HTTP/1.1
TE: chunked, trailers
Run Code Online (Sandbox Code Playgroud)
响应:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Trailer: My-Test-Trailer
D\r\n
All your base\r\n
B\r\n;
are belong\r\n
6\r\n
to us\r\n
0\r\n
My-Test-Trailer: something\r\n
\r\n
Run Code Online (Sandbox Code Playgroud)
此请求在TE标头中指定它期望chunked响应,并将trailers在最后一个块之后查找.
响应在指定Trailer标题拖车它将被发送的列表(在这种情况下,只有一个:My-Test-Trailer)
每个块都发送为:
D= 13),然后是aCRLFAll your base),后跟一个CRLF零大小的块(0\r\n)表示身体的末端.
然后指定预告片(My-Test-Trailer: something\r\n),然后是决赛CRLF.
现在,从我到目前为止所阅读的所有内容来看,很少(如果有的话)使用预告片.这里和其他地方关于预告片的大多数讨论通常以"但你为什么还要使用预告片?"开头.
暂且不谈为什么,出于好奇,我一直试图模拟使用预告片的HTTP请求/响应交换; 但到目前为止,我还没有能够让它工作,我不确定我生成的响应是否有问题,或者是否(正如一些人所建议的那样)没有客户端寻找尾随的标题.
我试过的客户包括:curl,wfetch,Chrome + jQuery.
在所有情况下,客户端都会接收并正确地重建分块响应(All your base are …
我正在为透明代理编写HTTP解析器.什么让我感到困惑的是Trailer:规格中提到的Transfer-Encoding: chunked.它是什么样子的?
通常,HTTP chunked会像这样结束.
0\r\n
\r\n
Run Code Online (Sandbox Code Playgroud)
我感到困惑的是如果有某种尾随标题,如何检测块的结尾...
更新:我相信一个简单的\r\n\r\n即空行足以检测尾随标题的结尾......这是正确的吗?
我正在从客户端发送POST请求(使用curl和自定义nodejs脚本测试)并且没有正确地返回响应.整个过程适用于PHP 5.6.
整个事情尽可能减少:
--disable-all --enable-fpm我正在使用的最小nginx站点配置:
server {
listen 80;
server_name localhost;
location / {
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_pass unix:/var/run/php/php7.0-fpm-api.sock;
fastcgi_param SCRIPT_FILENAME /vagrant/index.php;
}
}
Run Code Online (Sandbox Code Playgroud)
示例PHP脚本来自/vagrant/index.php:
<?php
echo str_repeat('.', 512);
flush(); // not necessary, only due testing
Run Code Online (Sandbox Code Playgroud)
我正在使用的卷曲电话: curl -XPOST http://localhost/ -H "Transfer-Encoding: chunked" -d ''
我正在使用的NodeJS脚本:
'use strict';
var http = require('http');
var url = require('url');
var uri = url.parse(process.env.URL);
var options = …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个spring mvc方法,它可以接收multipart/form或transfer-encoding chunked文件上传.我可以编写一个单独的方法来处理每种类型,但我想用相同的方法来做,所以我可以使用相同的REST POST uri,例如:
http://host:8084/attachments/testupload
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我最好的尝试:
@RequestMapping(value = { "/testupload" }, method = RequestMethod.POST, produces =
"application/json")
public @ResponseBody
ResponseEntity<MessageResponseModel> testUpload(
@RequestParam(value = "filedata", required = false) MultipartFile filedata,
final HttpServletRequest request) throws IOException {
InputStream is = null;
if (filedata == null) {
is = request.getInputStream();
}
else {
is = filedata.getInputStream();
}
byte[] bytes = IOUtils.toByteArray(is);
System.out.println("read " + bytes.length + " bytes.");
return new ResponseEntity<MessageResponseModel>(null, null, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
使用上面的方法我可以上传一个多部分文件,但是如果我上传一个分块文件,我会从spring获得一个例外:
org.springframework.web.multipart.MultipartException: \
The current request is not …Run Code Online (Sandbox Code Playgroud) 有些专家可以解释两者之间的差异吗?是不是chunked是一个流协议而多部分不是?使用multipart有什么好处?
chunked-encoding ×10
http ×5
php ×3
chunked ×2
http-chunked ×2
ajax ×1
apache ×1
chunking ×1
file-upload ×1
gzip ×1
http-1.1 ×1
http-headers ×1
java ×1
json ×1
performance ×1
php-7 ×1
restlet ×1
sample ×1
spring-mvc ×1
trailing ×1