Module: Puma::Utils
- Defined in:
- lib/puma/utils.rb
Class Method Summary collapse
-
.escape(s) ⇒ Object
Performs URI escaping so that you can construct proper query strings faster.
-
.query_parse(qs, d = '&;') ⇒ Object
Parses a query string by breaking it up at the ‘&’ and ‘;’ characters.
-
.unescape(s) ⇒ Object
Unescapes a URI escaped string.
Class Method Details
.escape(s) ⇒ Object
Performs URI escaping so that you can construct proper query strings faster. Use this rather than the cgi.rb version since it’s faster. (Stolen from Camping).
6 7 8 9 10 |
# File 'lib/puma/utils.rb', line 6 def self.escape(s) s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) { '%'+$1.unpack('H2'*$1.size).join('%').upcase }.tr(' ', '+') end |
.query_parse(qs, d = '&;') ⇒ Object
Parses a query string by breaking it up at the ‘&’ and ‘;’ characters. You can also use this to parse cookies by changing the characters used in the second parameter (which defaults to ‘&;’.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puma/utils.rb', line 24 def self.query_parse(qs, d = '&;') params = {} qs.split(/[#{d}] */n).each do |p| k, v = unescape(p).split('=', 2) if cur = params[k] if cur.kind_of? Array params[k] << v else params[k] = [cur, v] end else params[k] = v end end return params end |
.unescape(s) ⇒ Object
Unescapes a URI escaped string. (Stolen from Camping).
14 15 16 17 18 |
# File 'lib/puma/utils.rb', line 14 def self.unescape(s) s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){ [$1.delete('%')].pack('H*') } end |