Bug 60619 - Negotiate precompressed files
Summary: Negotiate precompressed files
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_negotiation (show other bugs)
Version: 2.4.25
Hardware: PC Linux
: P2 enhancement with 3 votes (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-20 21:08 UTC by Martin von Gagern
Modified: 2017-03-02 11:23 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin von Gagern 2017-01-20 21:08:09 UTC
There should be a way to configure the server so that if files “foo” and “foo.gz” exist, then “foo.gz” gets served if “Accept-Encoding: gzip” is specified in the request, and otherwise foo gets served. All of this with proper negotiation, “Varies” header, handling of “;q=0”, and so on.

http://httpd.apache.org/docs/2.4/mod/mod_deflate.html#precompressed is a workaround, but doing content negotiation using mod_rewrite is hardly a proper solution.

The key point here is the fact that the MultiViews option only has an effect if the named file does not exist as such.
https://github.com/apache/httpd/blob/fbc5e20ead005fd3a2bec05924f9e90dfd195406/modules/mappers/mod_negotiation.c#L3081-L3082

One solution might be a way to enforce MultiViews even if the file exists. Such a setting could be either for specific files, or for all files. Or perhaps depending on some environment variable.

If you can't agree to this, then another (less comfortable) solution would be implementing special handling of the identity encoding. That way, users could store files “foo.id” and “foo.gz”, could “AddEncoding identity .id”, the absence of “foo” itself would trigger MultiViews, and the negotiation code would know to fall back to the “identity” version if it couldn't find a better fit. Having to rename all files would be annoying, but it's still better than the mod_rewrite hack, I think.

I realize that you might consider type-map files the best (i.e. most performant) solution. But I think generating the appropriate type maps is far more work than renaming a bunch of files, so I hope for a simpler alternative.

There are a number of discussions of this issue on Stack Exchange:
http://stackoverflow.com/q/75482/1468366
http://stackoverflow.com/q/9076752/1468366
http://stackoverflow.com/q/16883241/1468366
http://serverfault.com/q/131452/129921
So I would say this is a common enough problem. Many of the options suggest adding “MultiViews” and “AddEncoding”, despite the fact that this doesn't work as intended (and judging from the age of the relevant line it never did work).
Comment 1 Eric Covener 2017-01-24 16:36:05 UTC
> One solution might be a way to enforce MultiViews even if the file exists.
> Such a setting could be either for specific files, or for all files. Or
> perhaps depending on some environment variable.

FWIW I think this would be reasonable