7

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 Answers 3

4

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.

1
  • +1 for the extra context and suggestion to try removing DefaultType.
    – rinogo
    Apr 24, 2019 at 0:03
4

Using ForceType at global level (meaning on all requests) will probably break other things like css, js...

This is common problem when serving path with html content having-no-extension (.html)

Simplified as not having a dot in the name:

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

Could be smarter to only check on last 5 characters:

<FilesMatch "^[^.]{0,5}$">
    ForceType text/html
</FilesMatch>
3

Found the solution.

ForceType text/plain

This worked for me....

2
  • 3
    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, 2018 at 0:40
  • This will probably break something else... css rss pdf video, etc... See my reply below Nov 20, 2018 at 7:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .