Project

General

Profile

Feature #2736

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

Added by a3nm about 1 year ago. Updated 7 months ago.

Status:
Fixed
Priority:
Normal
Assignee:
-
Category:
mod_magnet
Target version:
Start date:
2016-07-18
Due date:
% Done:

0%

Estimated time:
Missing in 1.5.x:

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?


Related issues

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

History

#1 Updated by gstrauss about 1 year 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.

#2 Updated by a3nm about 1 year 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!

#3 Updated by gstrauss about 1 year 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/

#4 Updated by gstrauss about 1 year 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.

#5 Updated by gstrauss 8 months 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

#6 Updated by gstrauss 7 months ago

#7 Updated by gstrauss 7 months 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

#8 Updated by gstrauss 7 months 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