MCPcopy
hub / github.com/ampproject/amphtml / httpsRequest

Function httpsRequest

build-system/common/update-session-issues/index.js:91–111  ·  view source on GitHub ↗

* @param {string} url * @param {object} options * @param {string=} data * @return {!Promise<{res: *, body: string}>}

(url, options, data)

Source from the content-addressed store, hash-verified

89 * @return {!Promise<{res: *, body: string}>}
90 */
91function httpsRequest(url, options, data) {
92 return new Promise((resolve, reject) => {
93 const req = https.request(url, options, (res) => {
94 const chunks = [];
95 res.on('data', (chunk) => {
96 chunks.push(Buffer.from(chunk));
97 });
98 res.on('close', () => {
99 const body = Buffer.concat(chunks).toString('utf-8');
100 resolve({res, body});
101 });
102 });
103 req.on('error', (error) => {
104 reject(error);
105 });
106 if (data) {
107 req.write(data);
108 }
109 req.end();
110 });
111}
112
113/**
114 * @param {string} token

Callers 1

requestGithubFunction · 0.85

Calls 6

concatMethod · 0.80
resolveFunction · 0.50
onMethod · 0.45
pushMethod · 0.45
toStringMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected