diff --git a/http.gemspec b/http.gemspec index cb98dddb..d11ee618 100644 --- a/http.gemspec +++ b/http.gemspec @@ -28,7 +28,6 @@ Gem::Specification.new do |gem| gem.required_ruby_version = ">= 3.0" gem.add_runtime_dependency "addressable", "~> 2.8" - gem.add_runtime_dependency "base64", "~> 0.1" gem.add_runtime_dependency "http-cookie", "~> 1.0" gem.add_runtime_dependency "http-form_data", "~> 2.2" gem.add_runtime_dependency "llhttp-ffi", "~> 0.5.0" diff --git a/lib/http/base64.rb b/lib/http/base64.rb new file mode 100644 index 00000000..2dfb2ad7 --- /dev/null +++ b/lib/http/base64.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module HTTP + module Base64 + module_function + + # Equivalent to Base64.strict_encode64 + def encode64(input) + [input].pack("m0") + end + end +end diff --git a/lib/http/chainable.rb b/lib/http/chainable.rb index acd534f6..8103af51 100644 --- a/lib/http/chainable.rb +++ b/lib/http/chainable.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require "base64" - +require "http/base64" require "http/headers" module HTTP module Chainable + include HTTP::Base64 + # Request a get sans response body # @param uri # @option options [Hash] @@ -215,7 +216,7 @@ def basic_auth(opts) pass = opts.fetch(:pass) creds = "#{user}:#{pass}" - auth("Basic #{Base64.strict_encode64(creds)}") + auth("Basic #{encode64(creds)}") end # Get options for HTTP diff --git a/lib/http/request.rb b/lib/http/request.rb index ff2dbb3b..ab0eb103 100644 --- a/lib/http/request.rb +++ b/lib/http/request.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require "forwardable" -require "base64" require "time" +require "http/base64" require "http/errors" require "http/headers" require "http/request/body" @@ -15,6 +15,7 @@ module HTTP class Request extend Forwardable + include HTTP::Base64 include HTTP::Headers::Mixin # The method given was not understood @@ -159,7 +160,7 @@ def include_proxy_authorization_header end def proxy_authorization_header - digest = Base64.strict_encode64("#{proxy[:proxy_username]}:#{proxy[:proxy_password]}") + digest = encode64("#{proxy[:proxy_username]}:#{proxy[:proxy_password]}") "Basic #{digest}" end