6

我正在验证我的应用程序是否处理通过分块编码模式传递的文件内容。我不确定要对 httpd.conf 文件进行什么更改以强制通过 Apache 进行分块编码。甚至可以使用 Apache 服务器来做到这一点,如果不是,那将是一个更简单的解决方案吗?我正在使用 Apache 2.4.2 和 HTTP 1.1。

默认情况下,Apache 中的 keep-alive 处于打开状态,并且在使用 wireshark 进行测试时,我没有看到数据被分块。

编辑:添加了更多信息:

4

3 回答 3

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
< 
于 2015-04-13T10:12:13.023 回答
0

此资源生成分块结果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">
....
于 2013-07-22T09:43:09.160 回答
0

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

在 apache 服务器index.php中,在索引页面所在的目录中创建一个文件(例如:)/var/www/html/并粘贴以下内容(应该安装 php):

<?php phpinfo(); ?>

然后尝试如下卷曲页面:

root@ubuntu-16:~# curl -v http://10.11.0.230:2222/index.php
*   Trying 10.11.0.230...
* Connected to 10.11.0.230 (10.11.0.230) port 2222 (#0)
> GET /index.php HTTP/1.1
> Host: 10.11.0.230:2222
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 01 Jul 2020 07:51:24 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
<!DOCTYPE html>
<html>
<body>
...
...
...
于 2020-07-02T07:24:11.720 回答