Class: Protocol::HTTP::Header::Authorization

Inherits:
String
  • Object
show all
Defined in:
lib/protocol/http/header/authorization.rb

Overview

Used for basic authorization.

~~~ ruby headers.add(‘authorization’, Authorization.basic(“my_username”, “my_password”)) ~~~

TODO Support other authorization mechanisms, e.g. bearer token.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.basic(username, password) ⇒ Object

Generate a new basic authorization header, encoding the given username and password.



30
31
32
33
34
35
36
# File 'lib/protocol/http/header/authorization.rb', line 30

def self.basic(username, password)
  strict_base64_encoded = ["#{username}:#{password}"].pack("m0")
  
  self.new(
    "Basic #{strict_base64_encoded}"
  )
end

.trailer?Boolean

Whether this header is acceptable in HTTP trailers.



40
41
42
# File 'lib/protocol/http/header/authorization.rb', line 40

def self.trailer?
  false
end

Instance Method Details

#credentialsObject

Splits the header into the credentials.



21
22
23
# File 'lib/protocol/http/header/authorization.rb', line 21

def credentials
  self.split(/\s+/, 2)
end