MCPcopy Create free account
hub / github.com/WallBreaker2/op / IsOcrServerHealthy

Function IsOcrServerHealthy

tests/test_support.cpp:102–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102bool IsOcrServerHealthy() {
103 std::wstring host;
104 INTERNET_PORT port = 0;
105 if (!GetConfiguredOcrHostPort(host, port))
106 return false;
107
108 HINTERNET hSession = WinHttpOpen(L"op-test-health/1.0", WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME,
109 WINHTTP_NO_PROXY_BYPASS, 0);
110 if (!hSession)
111 return false;
112
113 HINTERNET hConnect = WinHttpConnect(hSession, host.c_str(), port, 0);
114 if (!hConnect) {
115 WinHttpCloseHandle(hSession);
116 return false;
117 }
118
119 HINTERNET hRequest = WinHttpOpenRequest(hConnect, L"GET", L"/health", nullptr, WINHTTP_NO_REFERER,
120 WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
121 if (!hRequest) {
122 WinHttpCloseHandle(hConnect);
123 WinHttpCloseHandle(hSession);
124 return false;
125 }
126
127 WinHttpSetTimeouts(hRequest, 1000, 1000, 1000, 1000);
128
129 bool ok = false;
130 if (WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0) &&
131 WinHttpReceiveResponse(hRequest, nullptr)) {
132 DWORD status_code = 0;
133 DWORD size = sizeof(status_code);
134 if (WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
135 WINHTTP_HEADER_NAME_BY_INDEX, &status_code, &size, WINHTTP_NO_HEADER_INDEX)) {
136 ok = (status_code == 200);
137 }
138 }
139
140 WinHttpCloseHandle(hRequest);
141 WinHttpCloseHandle(hConnect);
142 WinHttpCloseHandle(hSession);
143 return ok;
144}
145
146std::wstring PtrToWString(const void *ptr, bool hex) {
147 std::wstringstream ss;

Callers 1

SetUpMethod · 0.85

Calls 1

GetConfiguredOcrHostPortFunction · 0.85

Tested by

no test coverage detected