Sha256: fdd04c7543b0a6cfe7beb326b9d449341d2c02c749fea7f0b5797821f427f7a8

Contents?: true

Size: 674 Bytes

Versions: 1

Compression:

Stored size: 674 Bytes

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    #
    # This plugin adds helper methods to implement HTTP Basic Auth
    # https://tools.ietf.org/html/rfc7617
    #
    module BasicAuthentication
      def self.load_dependencies(klass, *)
        require "base64"
        klass.plugin(:authentication)
      end

      module InstanceMethods
        def basic_authentication(user, password)
          authentication("Basic #{Base64.strict_encode64("#{URI.escape(user)}:#{URI.escape(password)}")}")
        end
        alias_method :basic_auth, :basic_authentication
      end
    end
    register_plugin :basic_authentication, BasicAuthentication
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
httpx-0.4.0 lib/httpx/plugins/basic_authentication.rb