Commits

Anonymous committed ebb9af5

Refactoring a bit of digest code to not use side-effects

  • Participants
  • Parent commits 7e65265

Comments (0)

Files changed (1)

File lib/amp/support/support.rb

       # based on http://segment7.net/projects/ruby/snippets/digest_auth.rb
       @@nonce_count += 1
 
-      response['www-authenticate'] =~ /^(\w+) (.*)/
+      match = response['www-authenticate'].scan(/^(\w+) (.*)/).first
 
       params = {}
-      $2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
+      match[1].scan(/(\w+)="(.*?)"/) {|key, val| params[key] = val }
 
       a_1 = "#{user}:#{params['realm']}:#{password}"
       a_2 = "#{@method}:#{@path}"