Class: Aliyun::Opensearch::ClientExt::Traffic::Header
- Inherits:
-
Object
- Object
- Aliyun::Opensearch::ClientExt::Traffic::Header
- Includes:
- Credentials
- Defined in:
- lib/aliyun/opensearch/client_ext/traffic/header.rb,
lib/aliyun/opensearch/client_ext/traffic/header/credentials.rb
Overview
流量API HTTP请求header
Defined Under Namespace
Modules: Credentials
Constant Summary collapse
- DEFAULT_CONTENT_TYPE =
默认 conten-type
'application/json'
- DEFAULT_UA =
默认 user-agent, 内容参考阿里云官方openapi sdk: github.com/aliyun/openapi-core-ruby-sdk/blob/master/lib/aliyunsdkcore.rb
"AlibabaCloud (#{Gem::Platform.local.os}; #{Gem::Platform.local.cpu}) Ruby/#{RUBY_VERSION} Core/ALiyunOpensearchClient-#{Aliyun::Opensearch::VERSION}"
- NONCE_SUFFIX_MIN =
nonce后缀最小长度
100_000
- NONCE_SUFFIX_MAX =
nonce后缀最大长度
999_999
Constants included from Credentials
Instance Method Summary collapse
-
#content_md5 ⇒ String
生成 header中 Content-MD5的值.
-
#content_type ⇒ String
hearder中 Content-Type的值.
-
#date ⇒ String
生成 header中 Date的值.
-
#generate ⇒ Hash
生成Header的Hash结构.
-
#initialize(request_method, path, api_params: nil, access_key_id: nil, access_key_secret: nil) ⇒ Header
constructor
创建实例.
-
#x_opensearch_headers ⇒ Hash
以X-Opensearch开头的header.
-
#x_opensearch_nonce ⇒ String
生成 header中 X-Opensearch-Nonce的值.
Methods included from Credentials
#authorization, #canonicalized_open_search_headers, #canonicalized_resource, #signature
Constructor Details
#initialize(request_method, path, api_params: nil, access_key_id: nil, access_key_secret: nil) ⇒ Header
创建实例
41 42 43 44 45 46 47 48 49 |
# File 'lib/aliyun/opensearch/client_ext/traffic/header.rb', line 41 def initialize(request_method, path, api_params: nil, access_key_id: nil, access_key_secret: nil) @request_method = request_method.to_s.upcase @path = path @api_params = api_params @access_key_id = access_key_id || Configuration.access_key_id @access_key_secret = access_key_secret || Configuration.access_key_secret end |
Instance Method Details
#content_md5 ⇒ String
生成 header中 Content-MD5的值
124 125 126 |
# File 'lib/aliyun/opensearch/client_ext/traffic/header.rb', line 124 def content_md5 Digest::MD5.hexdigest(@api_params.to_json) if @request_method == 'POST' && @api_params end |
#content_type ⇒ String
hearder中 Content-Type的值
89 90 91 |
# File 'lib/aliyun/opensearch/client_ext/traffic/header.rb', line 89 def content_type @content_type ||= DEFAULT_CONTENT_TYPE end |
#date ⇒ String
生成 header中 Date的值
113 114 115 |
# File 'lib/aliyun/opensearch/client_ext/traffic/header.rb', line 113 def date @date ||= time_now.utc.strftime('%Y-%m-%dT%H:%M:%SZ') end |
#generate ⇒ Hash
生成Header的Hash结构
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/aliyun/opensearch/client_ext/traffic/header.rb', line 58 def generate result = { 'User-Agent' => DEFAULT_UA, 'Content-Type' => content_type, 'Date' => date, }.merge(x_opensearch_headers) result.merge!('Content-Md5' => content_md5) if content_md5 result.merge!('Authorization' => ) result end |
#x_opensearch_headers ⇒ Hash
以X-Opensearch开头的header
76 77 78 79 80 |
# File 'lib/aliyun/opensearch/client_ext/traffic/header.rb', line 76 def x_opensearch_headers { 'X-Opensearch-Nonce' => x_opensearch_nonce, } end |
#x_opensearch_nonce ⇒ String
生成 header中 X-Opensearch-Nonce的值
102 103 104 |
# File 'lib/aliyun/opensearch/client_ext/traffic/header.rb', line 102 def x_opensearch_nonce @x_opensearch_nonce ||= "#{time_now.to_i}#{rand(NONCE_SUFFIX_MIN..NONCE_SUFFIX_MAX)}" end |