Revision f109c66a
Added by Marc Dequènes over 15 years ago
- ID f109c66a836ef7eed112a0e9337a4aea851392a9
lib/http_headers.rb | ||
---|---|---|
# RFC2616 Accept-Language field
|
||
# (also used in RFC2798 'preferredLanguage' LDAP attribute type)
|
||
class AcceptLanguage
|
||
LANG_RANGE_Q_PATTERN="([a-z]{1,8}(-[a-z]{1,8})*(;q=)|\*)"
|
||
ACCEPT_LANG_PATTERN="#{LANG_RANGE_Q_PATTERN}( *, *#{LANG_RANGE_Q_PATTERN})*"
|
||
LANG_RANGE_Q_PATTERN="([a-z]{1,8}(-[a-z]{1,8})*|\\*)(;q=(1|0\.\d+))?"
|
||
ACCEPT_LANG_PATTERN="#{LANG_RANGE_Q_PATTERN}([ ]*,[ ]*#{LANG_RANGE_Q_PATTERN})*"
|
||
|
||
attr_reader :sorted_language_list
|
||
|
||
private :new
|
||
|
||
def initialize(sorted_language_list)
|
||
# if no preference list, then assume that all languages are equally acceptable
|
||
@sorted_language_list = sorted_language_list.empty? ? ["*"] : sorted_language_list
|
||
... | ... | |
LanguageRange.new(l_tag, quality)
|
||
end
|
||
|
||
acceptable_tag_list = tag_list.select {|lt| lr.quality != 0 }
|
||
acceptable_tag_list = tag_list.select {|lr| lr.quality != 0 }
|
||
acceptable_tag_list.sort
|
||
end
|
||
end
|
||
|
||
class LanguageRange
|
||
include Sortable
|
||
include Comparable
|
||
|
||
attr_reader :quality
|
||
|
Also available in: Unified diff
[fix] HTTPHeaders: correct silly mistakes and broken regex for parsing