【问题标题】:How do I force apache to deliver a file in chunked encoded format如何强制 apache 以分块编码格式提供文件
【发布时间】:2013-04-23 12:19:51
【问题描述】:

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

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

编辑:添加更多信息:

【问题讨论】:

  • 你还有更多的上下文吗?
  • 同样的问题。我想让 Apache 以分块编码模式处理一些文件,以便我可以验证客户端是否正常工作。或者是否有一个服务器可以分块提供各种大小的文件?

标签: apache chunked-encoding


【解决方案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
< 

【讨论】:

    【解决方案2】:

    此资源产生分块结果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">
    ....
    

    【讨论】:

    • 对测试有用,但不以任何方式回答问题。
    • 网址已更改,请改用curl --raw -v http://www.httpwatch.com/httpgallery/chunked/chunkedimage.aspx | more
    【解决方案3】:

    我尝试过这种方式在 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>
    ...
    ...
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 2012-03-03
      • 2019-05-06
      • 2012-08-20
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      相关资源
      最近更新 更多