Skip to content

Commit ba0733e

Browse files
Earlopaintarcieri
andauthored
Drop depenency on base64 (#778)
Co-authored-by: Tony Arcieri <[email protected]>
1 parent 54e42f7 commit ba0733e

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

http.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Gem::Specification.new do |gem|
2828
gem.required_ruby_version = ">= 3.0"
2929

3030
gem.add_runtime_dependency "addressable", "~> 2.8"
31-
gem.add_runtime_dependency "base64", "~> 0.2"
3231
gem.add_runtime_dependency "http-cookie", "~> 1.0"
3332
gem.add_runtime_dependency "http-form_data", "~> 2.2"
3433
gem.add_runtime_dependency "llhttp-ffi", "~> 0.5.0"

lib/http/base64.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
module HTTP
4+
module Base64
5+
module_function
6+
7+
# Equivalent to Base64.strict_encode64
8+
def encode64(input)
9+
[input].pack("m0")
10+
end
11+
end
12+
end

lib/http/chainable.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# frozen_string_literal: true
22

3-
require "base64"
4-
3+
require "http/base64"
54
require "http/headers"
65

76
module HTTP
87
module Chainable
8+
include HTTP::Base64
9+
910
# Request a get sans response body
1011
# @param uri
1112
# @option options [Hash]
@@ -215,7 +216,7 @@ def basic_auth(opts)
215216
pass = opts.fetch(:pass)
216217
creds = "#{user}:#{pass}"
217218

218-
auth("Basic #{Base64.strict_encode64(creds)}")
219+
auth("Basic #{encode64(creds)}")
219220
end
220221

221222
# Get options for HTTP

lib/http/request.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
require "forwardable"
4-
require "base64"
54
require "time"
65

6+
require "http/base64"
77
require "http/errors"
88
require "http/headers"
99
require "http/request/body"
@@ -15,6 +15,7 @@ module HTTP
1515
class Request
1616
extend Forwardable
1717

18+
include HTTP::Base64
1819
include HTTP::Headers::Mixin
1920

2021
# The method given was not understood
@@ -159,7 +160,7 @@ def include_proxy_authorization_header
159160
end
160161

161162
def proxy_authorization_header
162-
digest = Base64.strict_encode64("#{proxy[:proxy_username]}:#{proxy[:proxy_password]}")
163+
digest = encode64("#{proxy[:proxy_username]}:#{proxy[:proxy_password]}")
163164
"Basic #{digest}"
164165
end
165166

0 commit comments

Comments
 (0)