Feature #2736


Test $HTTP["language"] for preferred language?

Added by a3nm almost 8 years ago. Updated over 7 years ago.

Target version:


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?

Related issues 1 (0 open1 closed)

Related to Feature #2678: New mod_precompress featureFixed2015-10-18Actions
Actions #1

Updated by gstrauss almost 8 years ago

It sounds like you are asking for implementation of an entirely new module in lighttpd, similar to mod_negotiation in Apache 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.

Actions #2

Updated by a3nm almost 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!

Actions #3

Updated by gstrauss almost 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.

Actions #4

Updated by gstrauss almost 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.

Actions #5

Updated by gstrauss over 7 years ago

sample lua code which (minimally) processes Accept-Encoding was contributed in #2678 by darix:

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

Actions #6

Updated by gstrauss over 7 years ago

Actions #7

Updated by gstrauss over 7 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

Actions #8

Updated by gstrauss over 7 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