Skip to content

Commit

Permalink
Remove dependency on base64
Browse files Browse the repository at this point in the history
Ruby 3.3 shows a warning when using base64 without declaring it in the gemspec.
Ruby 3.4 will remove base64 as a default gem.
  • Loading branch information
Earlopain committed Dec 23, 2023
1 parent 63940ac commit 835cc62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/webmock/util/headers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'base64'

module WebMock

module Util
Expand Down Expand Up @@ -59,7 +57,8 @@ def self.decode_userinfo_from_header(header)
end

def self.basic_auth_header(*credentials)
"Basic #{Base64.strict_encode64(credentials.join(':')).chomp}"
strict_base64_encoded = [credentials.join(':')].pack("m0")
"Basic #{strict_base64_encoded.chomp}"
end

def self.normalize_name(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def http_request(method, url, options = {}, &block)
end
end
headers.push(
['authorization', 'Basic ' + Base64.strict_encode64(options[:basic_auth].join(':'))]
['authorization', WebMock::Util::Headers.basic_auth_header(options[:basic_auth])]
) if options[:basic_auth]

body = options[:body]
Expand Down

0 comments on commit 835cc62

Please sign in to comment.