@abo
php, javascript, mysql

Сервер отдает gzip, а браузер принимает text. В чем проблема?

Браузер Chrome. Отправляем 2 идентичных запроса на сервер с разными User-Agent, Apache возвращает идентичные ответы, а в Chrome DevTools получаем разные результаты, в одном случает результат сжат gzip, а в другом нет. В Firefox аналогичная ситуация.
Как должно быть:
Request:
GET /min/g=css&1451385332 HTTP/1.1
Host: domain.ru:8080
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4

Response:
HTTP/1.1 200 OK
Date: Wed, 30 Dec 2015 10:26:44 GMT
Server: Apache
Expires: Thu, 29 Dec 2016 10:26:44 GMT
Vary: Accept-Encoding
Last-Modified: Tue, 29 Dec 2015 10:35:32 GMT
ETag: "pub1451385332;gz"
Cache-Control: max-age=31536000
Content-Length: 26530
Content-Encoding: gzip
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/css; charset=utf-8

Server log:
[rewrite:trace] mod_rewrite.c(475): - - [domain.ru/sid#7fe35e520f98][rid#7fe3
[filter:trace4] mod_filter.c(169): Content-Type 'text/css; charset=utf-8' ...
[filter:trace4] mod_filter.c(181): ... did not match 'application/xml'
[filter:trace2] mod_filter.c(188): Content-Type condition for 'deflate' did not match
[filter:trace4] mod_filter.c(169): Content-Type 'text/css; charset=utf-8' ...
[filter:trace4] mod_filter.c(181): ... did not match 'application/rss+xml'
[filter:trace2] mod_filter.c(188): Content-Type condition for 'deflate' did not match
[filter:trace4] mod_filter.c(169): Content-Type 'text/css; charset=utf-8' ...
[filter:trace4] mod_filter.c(181): ... did not match 'application/x-javascript'
[filter:trace4] mod_filter.c(181): ... did not match 'application/javascript'
[filter:trace4] mod_filter.c(181): ... did not match 'application/ecmascript'
[filter:trace2] mod_filter.c(188): Content-Type condition for 'deflate' did not match
[filter:trace4] mod_filter.c(169): Content-Type 'text/css; charset=utf-8' ...
[filter:trace4] mod_filter.c(175): ... matched 'text/css'
[filter:trace2] mod_filter.c(188): Content-Type condition for 'deflate' matched
[deflate:trace1] mod_deflate.c(677): Not compressing (content-encoding already  set: gzip)
[http:trace3] http_filters.c(1003): Response sent with status 200, headers:
[http:trace5] http_filters.c(1010):   Date: Wed, 30 Dec 2015 10:34:25 GMT
[http:trace5] http_filters.c(1013):   Server: Apache
[http:trace4] http_filters.c(832):   Expires: Thu, 29 Dec 2016 10:34:25 GMT
[http:trace4] http_filters.c(832):   Vary: Accept-Encoding
[http:trace4] http_filters.c(832):   Last-Modified: Tue, 29 Dec 2015 10:35:32 GMT
[http:trace4] http_filters.c(832):   ETag: \\"pub1451385332;gz\\"
[http:trace4] http_filters.c(832):   Cache-Control: max-age=31536000
[http:trace4] http_filters.c(832):   Content-Length: 26530
[http:trace4] http_filters.c(832):   Content-Encoding: gzip
[http:trace4] http_filters.c(832):   Keep-Alive: timeout=5, max=100
[http:trace4] http_filters.c(832):   Connection: Keep-Alive
[http:trace4] http_filters.c(832):   Content-Type: text/css; charset=utf-8

Запрос с обычным User-Agent:
Request:
GET /min/g=css&1451385332 HTTP/1.1
Host: domain.ru:8080
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4

Response:
HTTP/1.1 200 OK
Date: Wed, 30 Dec 2015 10:40:15 GMT
Server: Apache
Expires: Thu, 29 Dec 2016 10:40:15 GMT
Vary: Accept-Encoding
Last-Modified: Tue, 29 Dec 2015 10:35:32 GMT
ETag: "pub1451385332;gz"
Cache-Control: max-age=31536000
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/css; charset=utf-8
Transfer-Encoding: chunked

Server log:
[rewrite:trace1] mod_rewrite.c(475):  - - [domain.ru/sid#7fe35e520f98][rid#7fe3
[filter:trace4] mod_filter.c(169):  Content-Type 'text/css; charset=utf-8' ...
[filter:trace4] mod_filter.c(181):  ... did not match 'application/xml'
[filter:trace2] mod_filter.c(188):  Content-Type condition for 'deflate' did not match
[filter:trace4] mod_filter.c(169):  Content-Type 'text/css; charset=utf-8' ...
[filter:trace4] mod_filter.c(181):  ... did not match 'application/rss+xml'
[filter:trace2] mod_filter.c(188):  Content-Type condition for 'deflate' did not match
[filter:trace4] mod_filter.c(169):  Content-Type 'text/css; charset=utf-8' ...
[filter:trace4] mod_filter.c(181):  ... did not match 'application/x-javascript'
[filter:trace4] mod_filter.c(181):  ... did not match 'application/javascript'
[filter:trace4] mod_filter.c(181):  ... did not match 'application/ecmascript'
[filter:trace2] mod_filter.c(188):  Content-Type condition for 'deflate' did not match
[filter:trace4] mod_filter.c(169):  Content-Type 'text/css; charset=utf-8' ...
[filter:trace4] mod_filter.c(175):  ... matched 'text/css'
[filter:trace2] mod_filter.c(188):  Content-Type condition for 'deflate' matched
[deflate:trace1] mod_deflate.c(677):  Not compressing (content-encoding already  set: gzip)
[http:trace3] http_filters.c(1003):  Response sent with status 200, headers:
[http:trace5] http_filters.c(1010):    Date: Wed, 30 Dec 2015 10:40:15 GMT
[http:trace5] http_filters.c(1013):    Server: Apache
[http:trace4] http_filters.c(832):    Expires: Thu, 29 Dec 2016 10:40:15 GMT
[http:trace4] http_filters.c(832):    Vary: Accept-Encoding
[http:trace4] http_filters.c(832):    Last-Modified: Tue, 29 Dec 2015 10:35:32 GMT
[http:trace4] http_filters.c(832):    ETag: \\"pub1451385332;gz\\"
[http:trace4] http_filters.c(832):    Cache-Control: max-age=31536000
[http:trace4] http_filters.c(832):    Content-Length: 26530
[http:trace4] http_filters.c(832):    Content-Encoding: gzip
[http:trace4] http_filters.c(832):    Keep-Alive: timeout=5, max=100
[http:trace4] http_filters.c(832):    Connection: Keep-Alive
[http:trace4] http_filters.c(832):    Content-Type: text/css; charset=utf-8
  • Вопрос задан
  • 1291 просмотр
Пригласить эксперта
Ответы на вопрос 2
Ivanq
@Ivanq
Знаю php, js, html, css
На сервере стоит проверка на браузер. Дело в том, что некоторые браузеры, возможно даже отправляющие Accept-Encoding, сам gzip не поддерживают. Тогда решили определять по User-Agent. Браузер видит в User-Agent определенное слово и отключает gzip.
Ответ написан
Комментировать
@abo Автор вопроса
php, javascript, mysql
Поставил wireshark, показывает что приходит gzip. Видимо это просто проблема отображения в DevTools, но все же хотелось бы ее исправить
Вот пример, DevTools тоже показывает 128 кб без gzip habracdn.net/toster/frontend.946529c4-a992-11e5-81...
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы