MCPcopy Create free account
hub / github.com/TGX-Android/Publisher / postHttp

Function postHttp

main.js:390–418  ·  view source on GitHub ↗
(url, jsonData, needBinary, httpOptions, method)

Source from the content-addressed store, hash-verified

388}
389
390function postHttp (url, jsonData, needBinary, httpOptions, method) {
391 return new Promise((accept, reject) => {
392 const parsed = new URL(url);
393 const protocol = (parsed.protocol === 'https:' ? https : http);
394 try {
395 const postData = JSON.stringify(jsonData);
396 const options = Object.assign({
397 host: parsed.host,
398 path: parsed.pathname + parsed.search,
399 method: (method || 'POST'),
400 headers: {
401 'Content-Type': 'application/json',
402 'Content-Length': Buffer.byteLength(postData),
403 }
404 }, httpOptions || {});
405
406 const req = protocol.request(options, (res) => {
407 toUtf8(res, (contentType, content) => {
408 accept({statusCode: res.statusCode, statusMessage: res.statusMessage, content, contentType});
409 }, needBinary);
410 }).on('error', reject);
411 req.write(postData);
412 req.end();
413 } catch (e) {
414 console.error('Cannot fetch', url, e);
415 reject(e);
416 }
417 });
418}
419
420function fetchHttp (url, needBinary, httpOptions) {
421 return new Promise((accept, reject) => {

Callers 6

obtainHuaweiAccessTokenFunction · 0.85
updateHuaweiAppFileInfoFunction · 0.85
submitHuaweiAppUpdateFunction · 0.85
createGitHubReleaseFunction · 0.85
updateGitHubReleaseFunction · 0.85

Calls 1

toUtf8Function · 0.85

Tested by

no test coverage detected