| 55 | }; |
| 56 | |
| 57 | static 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 | |
| 102 | static napi_value Add(napi_env env, napi_callback_info info) |
| 103 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…