Apache2 not sending “Content-Type” in header

允我心安 提交于 2019-12-07 04:22:35

问题


I have a standard Apache2 installation on Ubuntu.

I was trying to get mod_deflate to work, which it does, but noticed it was not gzipping my .js files. A closer inspection revealed that apache isn't sending Content-Type: for anything other than .php files. For them it's sending "text/html," which is strange since DefaultType is "text/plain."

I have no clue why this is... mod_mime is enabled and I haven't touched the configs for it.

Here's an example response from my server for a .css file:

Date    Wed, 11 Mar 2009 04:48:12 GMT
Server  Apache/2.2.9 (Ubuntu)
Connection  Keep-Alive
Keep-Alive  timeout=15, max=96
Etag    "30478-4fb-464bec553a600"
Vary    Accept-Encoding

回答1:


It looks like this was a result of the item being cached using eTags, and my overlooking that fact.

What was happening was that this these items were in the browser cache, and were not actually being sent from the server, thus there was no Content-Type. However, the browser was receiving headers from the server while doing the cache lookup on the eTag.. this is what I was seeing.




回答2:


This happen some times when Content-Type default value is commented in httpd.conf.

In Ubuntu 8.04 it is set to text/html as I remember.




回答3:


It's a known problem. Which ubuntu version is it?

I just tried on ubuntu 8.10 and debian 5 installations where I havent touched the apache configuration. Both work fine:

HTTP/1.x 200 OK
Date: Wed, 11 Mar 2009 10:25:17 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4 with Suhosin-Patch mod_wsgi/2.3 Python/2.5.2
Last-Modified: Wed, 11 Mar 2009 10:19:41 GMT
Etag: "1544ae-12-464d534a6c940"
Accept-Ranges: bytes
Content-Length: 18
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/css


来源:https://stackoverflow.com/questions/633376/apache2-not-sending-content-type-in-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!