Class: Nonnative::Header
- Inherits:
-
Object
- Object
- Nonnative::Header
- Defined in:
- lib/nonnative/header.rb
Overview
Helper utilities for building request headers for HTTP and gRPC clients.
This class returns Ruby hashes suitable for passing into client libraries (for example RestClient for HTTP or gRPC call metadata).
Class Method Summary collapse
-
.auth_basic(credentials) ⇒ Hash{Symbol=>String}
Builds an HTTP Basic Authorization header.
-
.auth_bearer(token) ⇒ Hash{Symbol=>String}
Builds an HTTP Bearer Authorization header.
-
.grpc_user_agent(user_agent) ⇒ Hash{String=>String}
Builds gRPC metadata for setting the primary user agent.
-
.http_user_agent(user_agent) ⇒ Hash{Symbol=>String}
Builds an HTTP
User-Agentheader hash.
Class Method Details
.auth_basic(credentials) ⇒ Hash{Symbol=>String}
Builds an HTTP Basic Authorization header.
The credentials are base64-encoded using strict encoding. The credentials string should typically be in the form ‘“username:password”`.
54 55 56 |
# File 'lib/nonnative/header.rb', line 54 def auth_basic(credentials) { authorization: "Basic #{Base64.strict_encode64(credentials)}" } end |
.auth_bearer(token) ⇒ Hash{Symbol=>String}
Builds an HTTP Bearer Authorization header.
62 63 64 |
# File 'lib/nonnative/header.rb', line 62 def auth_bearer(token) { authorization: "Bearer #{token}" } end |
.grpc_user_agent(user_agent) ⇒ Hash{String=>String}
Builds gRPC metadata for setting the primary user agent.
43 44 45 |
# File 'lib/nonnative/header.rb', line 43 def grpc_user_agent(user_agent) { 'grpc.primary_user_agent' => user_agent } end |
.http_user_agent(user_agent) ⇒ Hash{Symbol=>String}
Builds an HTTP User-Agent header hash.
This uses the key style commonly used by RestClient (user_agent:).
35 36 37 |
# File 'lib/nonnative/header.rb', line 35 def http_user_agent(user_agent) { user_agent: } end |