【问题标题】:Is it possible to reduce the http response header size for a REST api?是否可以减少 REST api 的 http 响应标头大小?
【发布时间】:2014-05-19 09:57:34
【问题描述】:

我正在开发一个 REST api。这是响应标头之一

Date: Mon, 19 May 2014 08:31:04 GMT 
Server: Apache/2.2.26 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.6 PHP/5.5.10 mod_ssl/2.2.26 OpenSSL/0.9.8y DAV/2 mod_perl/2.0.8 Perl/v5.18.2 
X-Powered-By: PHP/5.5.10
Content-Length: 2207 
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json 

它有 318 个字节长。这意味着例如我的响应正文是 100 字节,它仅占其总长度的 25% 左右。所以我想知道是否可以减少响应头的大小? (我知道它可能对浏览器有用,但对于我的 REST 客户端,我认为它并不重要。)

【问题讨论】:

标签: apache http


【解决方案1】:

您可以缩短“Server”值并删除“X-Powered-By”标头(使用 Ubuntu 文件位置):

  • 在 /etc/apache2/conf.d/security 中设置“ServerTokens Prod”
  • 在 /etc/php5/apache2/php.ini 中设置“expose_php = Off”

编辑:对于小型实体,压缩会增加开销。要禁用它,请添加到您的 .htacces 或 apache 配置中,例如:

SetEnvIf Request_URI "/endpoint" no-gzip=1

【讨论】:

    猜你喜欢
    • 2018-02-22
    • 2011-05-21
    • 2017-05-11
    • 2011-02-24
    • 2015-05-14
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 2021-08-22
    相关资源
    最近更新 更多