O Apache retorna Comprimento de Conteúdo inválido para resposta compactada por gzip 204

2

Quando o apache retorna uma resposta compactada gzip com 204 código de resposta e o servidor de corpo vazio retorna um cabeçalho inválido Content-Length: 20 em vez de Content-Length: 0 .

Sem compactação gzip (sem Accept-Encoding header) o servidor retorna um cabeçalho válido Content-Length: 0 .

Solicitação e resposta com compactação:

0 % curl -v http://mta.dev/api/wtf/\?id\=09102 --compressed
* Hostname was NOT found in DNS cache
*   Trying 172.17.0.2...
* Connected to mta.dev (172.17.0.2) port 80 (#0)
> GET /api/wtf/?id=09102 HTTP/1.1
> User-Agent: curl/7.38.0
> Host: mta.dev
> Accept: */*
> Accept-Encoding: deflate, gzip
> 
< HTTP/1.1 204 No Content
< Date: Thu, 09 Jun 2016 15:44:53 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.17
< P3P: policyref="/bitrix/p3p.xml", CP="NON DSP COR CUR ADM DEV PSA PSD OUR UNR BUS UNI COM NAV INT DEM STA"
< X-Powered-CMS: Bitrix Site Manager (d04cd2b3dbab106e7537af3767043172)
< Set-Cookie: PHPSESSID=8arlnd14t1k97bri56clb2qhh1; path=/; HttpOnly
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Set-Cookie: BITRIX_SM_GUEST_ID=2328047; expires=Sun, 04-Jun-2017 15:44:53 GMT; Max-Age=31104000; path=/
< Set-Cookie: BITRIX_SM_LAST_VISIT=09.06.2016+18%3A44%3A53; expires=Sun, 04-Jun-2017 15:44:53 GMT; Max-Age=31104000; path=/
< Content-Encoding: gzip
< Content-Length: 20
< Content-Type: application/json
< 
* Excess found in a non pipelined read: excess = 20 url = /api/wtf/?id=09102 (zero-length body)
* Connection #0 to host mta.dev left intact

Solicitação e resposta sem compactação:

0 % curl -v http://mta.dev/api/wtf/\?id\=09102
* Hostname was NOT found in DNS cache
*   Trying 172.17.0.2...
* Connected to mta.dev (172.17.0.2) port 80 (#0)
> GET /api/wtf/?id=09102 HTTP/1.1
> User-Agent: curl/7.38.0
> Host: mta.dev
> Accept: */*
> 
< HTTP/1.1 204 No Content
< Date: Thu, 09 Jun 2016 15:38:43 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.17
< P3P: policyref="/bitrix/p3p.xml", CP="NON DSP COR CUR ADM DEV PSA PSD OUR UNR BUS UNI COM NAV INT DEM STA"
< X-Powered-CMS: Bitrix Site Manager (d04cd2b3dbab106e7537af3767043172)
< Set-Cookie: PHPSESSID=ceqsuv4ie3fkq497uvk6e2gki1; path=/; HttpOnly
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Set-Cookie: BITRIX_SM_GUEST_ID=2328047; expires=Sun, 04-Jun-2017 15:38:43 GMT; Max-Age=31104000; path=/
< Set-Cookie: BITRIX_SM_LAST_VISIT=09.06.2016+18%3A38%3A43; expires=Sun, 04-Jun-2017 15:38:43 GMT; Max-Age=31104000; path=/
< Content-Length: 0
< Content-Type: application/json
< 
* Connection #0 to host mta.dev left intact

Configurar Content-Length: 0 header no aplicativo PHP manualmente não tem efeito porque o apache recalcula o tamanho após o gzipping.

Encontrei esse bug no link do bugtracker do Apache, onde o desenvolvedor diz que esse bug foi corrigido em 2.4 1 versão. Eu tenho a versão 2.4.7 instalada e esse bug ainda ocorre.

Como posso desabilitar a compactação gzip para 204 respostas ou para respostas com corpo vazio? Ou talvez haja uma maneira de desativar a substituição do Content-Length header pelo apache?

    
por Dmitry Gres 09.06.2016 / 18:27

1 resposta

0

Parece que o tamanho do conteúdo relatado está correto: Se o conteúdo estiver vazio, o algoritmo gzip comprime isso em 20 bytes. Tente na linha de comando:

gzip < /dev/null | wc -c
20
    
por 31.08.2017 / 15:18