Sha256: b2fd493977080ebdfd250d227119aa55310ea178f705cad9bbd93d362b606868

Contents?: true

Size: 698 Bytes

Versions: 8

Compression:

Stored size: 698 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.
# Copyright, 2024, by Earlopain.

module Protocol
	module HTTP
		module Header
			# Used for basic authorization.
			#
			# ~~~ ruby
			# headers.add('authorization', Authorization.basic("my_username", "my_password"))
			# ~~~
			class Authorization < String
				# Splits the header and 
				# @return [Tuple(String, String)]
				def credentials
					self.split(/\s+/, 2)
				end
				
				def self.basic(username, password)
					strict_base64_encoded = ["#{username}:#{password}"].pack("m0")
					
					self.new(
						"Basic #{strict_base64_encoded}"
					)
				end
			end
		end
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
protocol-http-0.44.0 lib/protocol/http/header/authorization.rb
protocol-http-0.43.0 lib/protocol/http/header/authorization.rb
protocol-http-0.42.0 lib/protocol/http/header/authorization.rb
protocol-http-0.41.0 lib/protocol/http/header/authorization.rb
protocol-http-0.40.0 lib/protocol/http/header/authorization.rb
protocol-http-0.39.0 lib/protocol/http/header/authorization.rb
protocol-http-0.38.0 lib/protocol/http/header/authorization.rb
protocol-http-0.37.0 lib/protocol/http/header/authorization.rb