5

We have just migrated from Apache 2.0.53 to Apache 2.4 Everything works perfectly for html/js/css files etc.

But we have a number of endpoints on our servers which return plain text. For example - an endpoint would return -

RIL~Reliance Industries~1234~abcd

By default the response for these do not contain any "content-type" but I am expecting "text/plain"

In Apache 2.0.53 we were using

DefaultType text/plain

But in Apache 2.4 , this directive is disabled. (Ref:http://httpd.apache.org/docs/2.4/mod/core.html#defaulttype)

I have a large number of requests and want a generic solution that I can apply to my apache so that if there is no content-type provided, then it should send "text/plain"

Any suggestions please.

3

Found the solution.

ForceType text/plain

This worked for me....

  • 2
    As noted in the other answer, ForceType overrides the Content-Type header on all responses. So, you will probably want to use this with a condition of some kind. – MrWhite Oct 19 '18 at 0:40
  • This will probably break something else... css rss pdf video, etc... See my reply below – Antony Gibbs Nov 20 '18 at 7:06
2

One solution is to use ForceType text/plain to set the Content-Type header to text/plain. This will make all responses return text/plain, however.

A very specific problem in using ForceType is that it breaks mod_mime's file extension detection. For example, files requested with .css or .js extensions won't have their Content-Type set to text/css or application/javascript and will instead have it set to text/plain: probably not what you want.

As noted in a chain on the apache mailing list, the reason why DefaultType was removed is because they are now recommending that the browser do the sniffing to figure out the content-type. If you're upgrading from apache 2.2 to 2.4, then you should try to just use it without adding it back in.

0

This will probably break something else... css rss pdf video, etc...

Usually the problem happens on "files" with no extension.

This seems the easiest way I found to deal with this

<FilesMatch "^[^.]+$">
    ForceType text/html
</FilesMatch>`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.