如何强制apache以分块编码格式传送文件

时间:2013-04-29 18:05:44

标签: apache chunked-encoding

我正在验证我的应用程序是否处理通过分块编码模式传递的文件内容。我不确定对httpd.conf文件进行了哪些更改以通过Apache强制进行分块编码。是否可以使用Apache服务器执行此操作,如果不是更简单的解决方案?我使用的是Apache 2.4.2和HTTP 1.1。

默认情况下,在Apache中保持活动状态为On,并且在使用wireshark进行测试时,我看不到数据是分块的。

编辑:添加了更多信息:

3 个答案:

答案 0 :(得分:1)

我设法做到这一点的唯一方法就是启用deflate模块。 然后我配置我的客户端发送"Accept-Encoding: gzip, deflate"标头,apache将压缩并以分块模式发回文件。 我必须在模块中启用文件类型。 AddOutputFilterByType DEFLATE image/png

参见示例:

curl --raw -v --header "Accept-Encoding: gzip, deflate" http://localhost/image.png | more
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /image.png HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost
> Accept: */*
> Accept-Encoding: gzip, deflate
> 
< HTTP/1.1 200 OK
< Date: Mon, 13 Apr 2015 10:08:45 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< Last-Modified: Mon, 13 Apr 2015 09:48:53 GMT
< ETag: "3b5306-5139805976dae-gzip"
< Accept-Ranges: bytes
< Vary: Accept-Encoding
< Content-Encoding: gzip
< Transfer-Encoding: chunked
< Content-Type: image/png
< 

答案 1 :(得分:0)

我尝试过这种方法来在Ubuntu中获取HTTP块编码数据,这可能会有所帮助。

在apache服务器中,在目录页面(例如:theirs)所在的目录中创建文件ours,并粘贴在内容下方(应该已安装php):

index.php

然后尝试如下卷曲页面:

/var/www/html/

答案 2 :(得分:-1)

此资源会生成分块结果http://www.httpwatch.com/httpgallery/chunked/ 这对测试客户非常有用。你可以通过运行

来看到这一点
$ curl --raw -i http://www.httpwatch.com/httpgallery/chunked/
HTTP/1.1 200 OK
Cache-Control: private,Public
Transfer-Encoding: chunked
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 22 Jul 2013 09:41:04 GMT

7b
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

2d
<html xmlns="http://www.w3.org/1999/xhtml">
....