MCPcopy Create free account
hub / github.com/acl-dev/acl / HttpGet

Function HttpGet

harmony/api9/acl_one/entry/src/main/cpp/hello.cpp:57–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55};
56
57static napi_value HttpGet(napi_env env, napi_callback_info info)
58{
59 log_info("%s: Started!", __func__);
60
61 size_t argc = 1;
62 napi_value args[1] = { nullptr };
63
64 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
65
66 char url[256];
67 size_t len;
68 napi_status res = napi_get_value_string_utf8(env, args[0], url, sizeof(url), &len);
69 if (res != napi_ok) {
70 log_info("%s: napi_get_value_string_utf8 error=%d", __func__, res);
71 return nullptr;
72 }
73
74 log_info( "%s: url=%s", __func__, url);
75
76 http_thread http(url);
77 http.set_detachable(false);
78 http.start();
79 http.wait();
80
81 const acl::string& body = http.get_body();
82 acl::string head = http.get_head();
83
84 if (body.empty() || head.empty()) {
85 log_info("%s: http reply body or head empty!", __func__);
86 return nullptr;
87 }
88
89 head.format_append("\r\nBody length: %zd\r\n", body.length());
90
91 napi_value result;
92 res = napi_create_string_utf8(env, head.c_str(), head.size(), &result);
93 if (res != napi_ok) {
94 log_info("%s: napi_create_string_utf8 error=%d", __func__, res);
95 return nullptr;
96 }
97
98 log_info("%s: At last, http body length=%zd", __func__, body.size());
99 return result;
100}
101
102static napi_value Add(napi_env env, napi_callback_info info)
103{

Callers

nothing calls this directly

Calls 8

log_infoFunction · 0.70
startMethod · 0.45
waitMethod · 0.45
get_bodyMethod · 0.45
emptyMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…