Skip to content

Commit

Permalink
Drop depenency on base64 (#778)
Browse files Browse the repository at this point in the history
Co-authored-by: Tony Arcieri <[email protected]>
  • Loading branch information
Earlopain and tarcieri committed Jul 24, 2024
1 parent 54e42f7 commit ba0733e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion http.gemspec
Original file line number Diff line number Diff line change
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.2"
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
12 changes: 12 additions & 0 deletions lib/http/base64.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions lib/http/chainable.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/http/request.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -15,6 +15,7 @@ module HTTP
class Request
extend Forwardable

include HTTP::Base64
include HTTP::Headers::Mixin

# The method given was not understood
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ba0733e

Please sign in to comment.