Class: Protocol::HTTP::Header::Authorization
- Inherits:
-
String
- Object
- String
- Protocol::HTTP::Header::Authorization
- 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
-
.basic(username, password) ⇒ Object
Generate a new basic authorization header, encoding the given username and password.
-
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
-
.parse(value) ⇒ Object
Parses a raw header value.
-
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
Instance Method Summary collapse
-
#credentials ⇒ Object
Splits the header into the credentials.
Class Method Details
.basic(username, password) ⇒ Object
Generate a new basic authorization header, encoding the given username and password.
46 47 48 49 50 51 52 |
# File 'lib/protocol/http/header/authorization.rb', line 46 def self.basic(username, password) strict_base64_encoded = ["#{username}:#{password}"].pack("m0") self.new( "Basic #{strict_base64_encoded}" ) end |
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
30 31 32 |
# File 'lib/protocol/http/header/authorization.rb', line 30 def self.coerce(value) self.new(value.to_s) end |
.parse(value) ⇒ Object
Parses a raw header value.
22 23 24 |
# File 'lib/protocol/http/header/authorization.rb', line 22 def self.parse(value) self.new(value) end |
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
56 57 58 |
# File 'lib/protocol/http/header/authorization.rb', line 56 def self.trailer? false end |
Instance Method Details
#credentials ⇒ Object
Splits the header into the credentials.
37 38 39 |
# File 'lib/protocol/http/header/authorization.rb', line 37 def credentials self.split(/\s+/, 2) end |