Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add parse_http_accept_header utility method to simplify accept_encodi…

…ng and accept_language
  • Loading branch information...
commit 9798ae21327a7511d5cfe0340edfbfd3df4bc5be 1 parent 3a8bd8b
@craic craic authored
Showing with 13 additions and 16 deletions.
  1. +13 −16 lib/rack/request.rb
View
29 lib/rack/request.rb
@@ -337,25 +337,11 @@ def fullpath
end
def accept_encoding
- @env["HTTP_ACCEPT_ENCODING"].to_s.split(/\s*,\s*/).map do |part|
- encoding, parameters = part.split(/\s*;\s*/, 2)
- quality = 1.0
- if parameters and /\Aq=([\d.]+)/ =~ parameters
- quality = $1.to_f
- end
- [encoding, quality]
- end
+ parse_http_accept_header(@env["HTTP_ACCEPT_ENCODING"])
end
def accept_language
- @env["HTTP_ACCEPT_LANGUAGE"].to_s.split(/\s*,\s*/).map do |part|
- language, parameters = part.split(/\s*;\s*/, 2)
- quality = 1.0
- if parameters and /\Aq=([\d.]+)/ =~ parameters
- quality = $1.to_f
- end
- [language, quality]
- end
+ parse_http_accept_header(@env["HTTP_ACCEPT_LANGUAGE"])
end
def trusted_proxy?(ip)
@@ -395,5 +381,16 @@ def parse_query(qs)
def parse_multipart(env)
Rack::Multipart.parse_multipart(env)
end
+
+ def parse_http_accept_header(header)
+ header.to_s.split(/\s*,\s*/).map do |part|
+ attribute, parameters = part.split(/\s*;\s*/, 2)
+ quality = 1.0
+ if parameters and /\Aq=([\d.]+)/ =~ parameters
+ quality = $1.to_f
+ end
+ [attribute, quality]
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.