MCPcopy Create free account
hub / github.com/aliyun/openapi-core-nodejs-sdk / request

Method request

lib/roa.js:180–281  ·  view source on GitHub ↗
(method, uriPattern, query = {}, body = '', headers = {}, opts = {})

Source from the content-addressed store, hash-verified

178 }
179
180 async request(method, uriPattern, query = {}, body = '', headers = {}, opts = {}) {
181 const credentials = await this.credentialsProvider.getCredentials();
182
183 const now = new Date();
184 var defaultHeaders = {
185 accept: 'application/json',
186 date: now.toGMTString(),
187 host: this.host,
188 'x-acs-signature-nonce': kitx.makeNonce(),
189 'x-acs-version': this.apiVersion,
190 'user-agent': helper.DEFAULT_UA,
191 'x-sdk-client': helper.DEFAULT_CLIENT
192 };
193 if (credentials && credentials.accessKeyId && credentials.accessKeySecret) {
194 defaultHeaders['x-acs-signature-method'] = 'HMAC-SHA1';
195 defaultHeaders['x-acs-signature-version'] = '1.0';
196 if (credentials.securityToken) {
197 defaultHeaders['x-acs-accesskey-id'] = credentials.accessKeyId;
198 defaultHeaders['x-acs-security-token'] = credentials.securityToken;
199 }
200 }
201
202 var mixHeaders = Object.assign(defaultHeaders, keyLowerify(headers));
203
204 var postBody = null;
205
206 postBody = Buffer.from(body, 'utf8');
207 mixHeaders['content-md5'] = kitx.md5(postBody, 'base64');
208 mixHeaders['content-length'] = postBody.length;
209
210 var url = `${this.endpoint}${uriPattern}`;
211 if (Object.keys(query).length) {
212 url += `?${querystring.stringify(query)}`;
213 }
214
215 if (credentials && credentials.accessKeyId && credentials.accessKeySecret) {
216 const stringToSign = buildStringToSign(method, uriPattern, mixHeaders, query);
217 debug('stringToSign: %s', stringToSign);
218 const utf8Buff = Buffer.from(stringToSign, 'utf8');
219 const signature = kitx.sha1(utf8Buff, credentials.accessKeySecret, 'base64');
220 mixHeaders['authorization'] = `acs ${credentials.accessKeyId}:${signature}`;
221 }
222
223 const options = Object.assign({
224 method,
225 agent: this.keepAliveAgent,
226 headers: mixHeaders,
227 data: postBody
228 }, this.opts, opts);
229
230 const response = await httpx.request(url, options);
231 const responseBody = await httpx.read(response, 'utf8');
232
233 // Retrun raw body
234 if (opts.rawBody) {
235 return responseBody;
236 }
237

Callers 4

putMethod · 0.95
postMethod · 0.95
getMethod · 0.95
deleteMethod · 0.95

Calls 3

keyLowerifyFunction · 0.85
buildStringToSignFunction · 0.85
parseXMLFunction · 0.85

Tested by

no test coverage detected