Feature #2736
closedTest $HTTP["language"] for preferred language?
Description
Lighttpd can use $HTTP["language"] to test the Accept-Language header, but one often wants to test which language is preferred among a set of languages: i.e., should I rather serve the English version, the French version, or the Quenya version? This is very inconvenient to do with a regexp, so maybe it would make sense to have a specific feature for that?
Updated by gstrauss over 8 years ago
It sounds like you are asking for implementation of an entirely new module in lighttpd, similar to mod_negotiation in Apache https://httpd.apache.org/docs/current/en/mod/mod_negotiation.html or nginx try_files (more limited)
You are correct that there is currently no such feature in lighttpd. Patches welcome, though this involves writing an new module, so supporting this is not a trivial code change.
In the meantime, you can perform the content negotiation yourself in a CGI, FastCGI, or SCGI script. Yes, this can be slightly slower than doing it natively in lighttpd, but not much slower if you use FastCGI or SCGI and the response from the script sends lighttpd a special X-Sendfile response header.
Updated by a3nm over 8 years ago
Apropos patches, it's unlikely I will have the time to write such a module myself. I just wanted to make a suggestion.
In any case, thanks a lot for confirming that this does not exist, clarifying the situation, and even proposing a workaround!
Updated by gstrauss over 8 years ago
Here's a blog post made earlier this year which includes a script for use with nginx. I haven't looked closely at it for accuracy. http://www.guido-flohr.net/simple-content-negotiation-for-nginx/
Updated by gstrauss over 8 years ago
You can also do this in lighttpd today with mod_magnet and a snippet of custom lua code. I wonder if someone has already done this. I suggest looking around with your favorite search engine.
Updated by gstrauss almost 8 years ago
sample lua code which (minimally) processes Accept-Encoding was contributed in #2678 by darix: https://gist.github.com/darix/5025010490bb0ea70099
It might be a decent base if you wanted to modify the lua to process Accept-Language and then try files with different extensions for languages in order to serve a file of the preferred language
Updated by gstrauss almost 8 years ago
- Related to Feature #2678: New mod_precompress feature added
Updated by gstrauss almost 8 years ago
- Category changed from core to mod_magnet
- Target version changed from 1.4.x to 1.4.46
This is achievable using some custom lua code with lighttpd mod_magnet
See attachment to #2678
Updated by gstrauss almost 8 years ago
- Status changed from New to Fixed
Attached content-negotiation.lua to #2678 with code to handle Accept-Language and Accept-Encoding. Lightly tested. YMMV.
server.modules += ( "mod_magnet" ) magnet.attract-physical-path-to = ( "/path/to/content-negotiation.lua" )
Also available in: Atom