Sha256: 2d54320bbe84920232e29dc8d7d7749348bedd5165369fccd108ad6aac059e5f
Contents?: true
Size: 1.04 KB
Versions: 54
Compression:
Stored size: 1.04 KB
Contents
module Rack module Auth module Digest class Params < Hash def self.parse(str) Params[*split_header_value(str).map do |param| k, v = param.split('=', 2) [k, dequote(v)] end.flatten] end def self.dequote(str) # From WEBrick::HTTPUtils ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup ret.gsub!(/\\(.)/, "\\1") ret end def self.split_header_value(str) str.scan(/\w+\=(?:"[^\"]+"|[^,]+)/n) end def initialize super() yield self if block_given? end def [](k) super k.to_s end def []=(k, v) super k.to_s, v.to_s end UNQUOTED = ['nc', 'stale'] def to_s map do |k, v| "#{k}=" << (UNQUOTED.include?(k) ? v.to_s : quote(v)) end.join(', ') end def quote(str) # From WEBrick::HTTPUtils '"' << str.gsub(/[\\\"]/o, "\\\1") << '"' end end end end end
Version data entries
54 entries across 52 versions & 14 rubygems