From 385edf1e5c6dd5465067bae293844e640e9887a2 Mon Sep 17 00:00:00 2001 From: gotoyuzo Date: Tue, 12 Oct 2004 12:26:39 +0000 Subject: * lib/webrick/config.rb: add WEBrick::Config::FileHandler[:AcceptableLanguages]. * lib/webrick/httpservlet/filehandler.rb (WEBrick::HTTPServlet::FileHandler#set_filename): search files having suffix of language-name which Accept-Language header field includes if :AcceptableLanguages options is present. * lib/webrick/httpservlet/filehandler.rb (WEBrick::HTTPServlet::FileHandler#get_servlet): new method to search servlet correspond to the suffix of filename. * lib/webrick/httprequest.rb: add attributes access methods: accept, accept_charset, accept_encoding, accept_language, content_length and content_type. * lib/webrick/httpresponse.rb: add attribute access methods: content_length, content_length=, content_type and content_type=. * lib/webrick/httputils.rb (WEBrick::HTTPUtils.mime_types): use the second suffix to detect media type. (the first suffix may be a language name.) * lib/webrick/httputils.rb (WEBrick::HTTPUtils.parse_qvalues): add method to parse Accept header field. it returns an Array of values sorted by the qvalues. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7033 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/httputils.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'lib/webrick/httputils.rb') diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb index bae281ca1a..18e3e25887 100644 --- a/lib/webrick/httputils.rb +++ b/lib/webrick/httputils.rb @@ -115,10 +115,9 @@ module WEBrick module_function :load_mime_types def mime_type(filename, mime_tab) - if suffix = (/\.(\w+)$/ =~ filename && $1) - mtype = mime_tab[suffix.downcase] - end - mtype || "application/octet-stream" + suffix1 = (/\.(\w+)$/ =~ filename && $1.downcase) + suffix2 = (/\.(\w+)\.[\w\-]+$/ =~ filename && $1.downcase) + mime_tab[suffix1] || mime_tab[suffix2] || "application/octet-stream" end module_function :mime_type @@ -175,6 +174,24 @@ module WEBrick end module_function :parse_range_header + def parse_qvalues(value) + tmp = [] + if value + parts = value.split(/,\s*/) + parts.each {|part| + if m = %r{^([^\s,]+?)(?:;\s*q=([\d]+(?:\.[\d]+)))?$}.match(part) + lang = m[1] + q = (m[2] or 1).to_f + tmp.push([lang, q]) + end + } + tmp = tmp.sort_by{|lang, q| -q} + tmp.collect!{|lang, q| lang} + end + return tmp + end + module_function :parse_qvalues + ##### def dequote(str) -- cgit v1.2.3