Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop depenency on base64 #778

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions 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
7 changes: 4 additions & 3 deletions 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]
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
@@ -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