Skip to content

Commit

Permalink
Drop depenency on base64
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Feb 8, 2024
1 parent 017f8a6 commit 557a1bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion http.gemspec
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions lib/http/chainable.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "base64"

require "http/encoder"
require "http/headers"

module HTTP
Expand Down Expand Up @@ -215,7 +214,7 @@ def basic_auth(opts)
pass = opts.fetch(:pass)
creds = "#{user}:#{pass}"

auth("Basic #{Base64.strict_encode64(creds)}")
auth("Basic #{Encoder.to_base64(creds)}")
end

# Get options for HTTP
Expand Down
10 changes: 10 additions & 0 deletions lib/http/encoder.rb
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module HTTP
module Encoder
# Equivalent to Base64.strict_encode64
def self.to_base64(input)
[input].pack("m0")
end
end
end
4 changes: 2 additions & 2 deletions lib/http/request.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require "forwardable"
require "base64"
require "time"

require "http/encoder"
require "http/errors"
require "http/headers"
require "http/request/body"
Expand Down Expand Up @@ -159,7 +159,7 @@ def include_proxy_authorization_header
end

def proxy_authorization_header
digest = Base64.strict_encode64("#{proxy[:proxy_username]}:#{proxy[:proxy_password]}")
digest = Encoder.to_base64("#{proxy[:proxy_username]}:#{proxy[:proxy_password]}")
"Basic #{digest}"
end

Expand Down

0 comments on commit 557a1bc

Please sign in to comment.