Class: WEBrick::HTTPRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/gonzui/webapp/webrick.rb

Instance Method Summary collapse

Instance Method Details

#accept_languageObject



36
37
38
39
40
41
# File 'lib/gonzui/webapp/webrick.rb', line 36

def accept_language
  unless @accept_language
    parse_accept_language
  end
  return @accept_language
end

#gzip_encoding_supported?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/gonzui/webapp/webrick.rb', line 43

def gzip_encoding_supported?
  /\bgzip\b/.match(self["accept-encoding"])
end

#parse_accept_languageObject

FIXME: it should be deleted if WEBRick supports the method



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gonzui/webapp/webrick.rb', line 18

def parse_accept_language
  if self["Accept-Language"]
    tmp = []
    parts = self["Accept-Language"].split(/,\s*/)
    parts.each {|part|
      if m = /^([\w-]+)(?:;q=([\d]+(?:\.[\d]+)))?$/.match(part)
        lang = m[1]
        q = (m[2] or 1).to_f
        tmp.push([lang, q])
      end
    }
    @accept_language = 
      tmp.sort_by {|lang, q| q}.map {|lang, q| lang}.reverse
  else
    @accept_language = ["en"] # FIXME: should be customizable?
  end
end