Sha256: eb7cf4c6c8fe52e0b503eb0ec8fb666acce6ab480259a5dded328e1ecf0cd1b7

Contents?: true

Size: 1.14 KB

Versions: 89

Compression:

Stored size: 1.14 KB

Contents

module Rack
  module Auth
    module Digest
      class Params < Hash

        def self.parse(str)
          split_header_value(str).inject(new) do |header, param|
            k, v = param.split('=', 2)
            header[k] = dequote(v)
            header
          end
        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 ).collect{ |v| v[0] }
        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 = ['qop', 'nc', 'stale']

        def to_s
          inject([]) do |parts, (k, v)|
            parts << "#{k}=" + (UNQUOTED.include?(k) ? v.to_s : quote(v))
            parts
          end.join(', ')
        end

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

      end
    end
  end
end

Version data entries

89 entries across 88 versions & 24 rubygems

Version Path
rango-0.1.pre vendor/rack/lib/rack/auth/digest/params.rb
passenger-2.2.7 vendor/rack-1.0.0-git/lib/rack/auth/digest/params.rb
passenger-2.2.6 vendor/rack-1.0.0-git/lib/rack/auth/digest/params.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rack-0.4.0/lib/rack/auth/digest/params.rb
middleman-0.10.17 vendor/gems/gems/rack-1.0.1/lib/rack/auth/digest/params.rb
middleman-0.10.16 vendor/gems/gems/rack-1.0.1/lib/rack/auth/digest/params.rb
middleman-0.10.15 vendor/gems/gems/rack-1.0.1/lib/rack/auth/digest/params.rb
rackjour-0.1.8 vendor/gems/gems/rack-1.0.1/lib/rack/auth/digest/params.rb
middleman-0.10.14 vendor/gems/gems/rack-1.0.1/lib/rack/auth/digest/params.rb
rack-1.0.1 lib/rack/auth/digest/params.rb
hiraku-rack-1.0.0.1 lib/rack/auth/digest/params.rb
passenger-2.2.5 vendor/rack-1.0.0-git/lib/rack/auth/digest/params.rb
webroar-0.2.2 src/admin_panel/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb
passenger-2.2.3 vendor/rack-1.0.0-git/lib/rack/auth/digest/params.rb
passenger-2.2.4 vendor/rack-1.0.0-git/lib/rack/auth/digest/params.rb
actionpack-2.3.2 lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb
mack-0.8.2 lib/gems/rack-0.4.0/lib/rack/auth/digest/params.rb
mack-0.8.3.1 lib/gems/rack-0.9.1/lib/rack/auth/digest/params.rb
mack-0.8.3 lib/gems/rack-0.9.1/lib/rack/auth/digest/params.rb
passenger-2.1.2 vendor/rack-0.9.1/lib/rack/auth/digest/params.rb