Class: Rack::Auth::Digest::Params

Inherits:
Hash
  • Object
show all
Defined in:
lib/rack/auth/digest.rb

Constant Summary collapse

UNQUOTED =
['nc', 'stale']

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Params

Returns a new instance of Params.

Yields:

  • (_self)

Yield Parameters:



76
77
78
79
80
# File 'lib/rack/auth/digest.rb', line 76

def initialize
  super()

  yield self if block_given?
end

Class Method Details

.dequote(str) ⇒ Object

From WEBrick::HTTPUtils



66
67
68
69
70
# File 'lib/rack/auth/digest.rb', line 66

def self.dequote(str) # From WEBrick::HTTPUtils
  ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup
  ret.gsub!(/\\(.)/, "\\1")
  ret
end

.parse(str) ⇒ Object



59
60
61
62
63
64
# File 'lib/rack/auth/digest.rb', line 59

def self.parse(str)
  Params[*split_header_value(str).map do |param|
    k, v = param.split('=', 2)
    [k, dequote(v)]
  end.flatten]
end

.split_header_value(str) ⇒ Object



72
73
74
# File 'lib/rack/auth/digest.rb', line 72

def self.split_header_value(str)
  str.scan(/\w+\=(?:"[^\"]+"|[^,]+)/n)
end

Instance Method Details

#[](k) ⇒ Object



82
83
84
# File 'lib/rack/auth/digest.rb', line 82

def [](k)
  super k.to_s
end

#[]=(k, v) ⇒ Object



86
87
88
# File 'lib/rack/auth/digest.rb', line 86

def []=(k, v)
  super k.to_s, v.to_s
end

#quote(str) ⇒ Object

From WEBrick::HTTPUtils



98
99
100
# File 'lib/rack/auth/digest.rb', line 98

def quote(str) # From WEBrick::HTTPUtils
  '"' + str.gsub(/[\\\"]/o, "\\\1") + '"'
end

#to_sObject



92
93
94
95
96
# File 'lib/rack/auth/digest.rb', line 92

def to_s
  map do |k, v|
    "#{k}=#{(UNQUOTED.include?(k) ? v.to_s : quote(v))}"
  end.join(', ')
end