MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / fetch_path_with_timeout_flag

Function fetch_path_with_timeout_flag

src/include/update.hpp:83–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83static std::string fetch_path_with_timeout_flag(HINTERNET hSession,
84 const wchar_t* host,
85 INTERNET_PORT port,
86 const std::wstring& path,
87 bool& out_timed_out)
88{
89 out_timed_out = false;
90 std::string body;
91
92 HINTERNET hConnect = WinHttpConnect(hSession, host, port, 0);
93 if (!hConnect) {
94 DWORD e = GetLastError();
95 if (is_timeout_error(e)) out_timed_out = true;
96 return body;
97 }
98
99 HINTERNET hRequest = WinHttpOpenRequest(hConnect, L"GET", path.c_str(),
100 NULL, WINHTTP_NO_REFERER,
101 WINHTTP_DEFAULT_ACCEPT_TYPES,
102 WINHTTP_FLAG_SECURE);
103 if (!hRequest) {
104 DWORD e = GetLastError();
105 if (is_timeout_error(e)) out_timed_out = true;
106 WinHttpCloseHandle(hConnect);
107 return body;
108 }
109
110 WinHttpAddRequestHeaders(hRequest, L"User-Agent: flm/1.0\r\n", (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD);
111
112 BOOL ok = WinHttpSendRequest(hRequest,
113 WINHTTP_NO_ADDITIONAL_HEADERS, 0,
114 WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
115 if (!ok) {
116 DWORD e = GetLastError();
117 if (is_timeout_error(e)) out_timed_out = true;
118 WinHttpCloseHandle(hRequest);
119 WinHttpCloseHandle(hConnect);
120 return body;
121 }
122
123 ok = WinHttpReceiveResponse(hRequest, NULL);
124 if (!ok) {
125 DWORD e = GetLastError();
126 if (is_timeout_error(e)) out_timed_out = true;
127 WinHttpCloseHandle(hRequest);
128 WinHttpCloseHandle(hConnect);
129 return body;
130 }
131
132 for (;;) {
133 DWORD dwSize = 0;
134 if (!WinHttpQueryDataAvailable(hRequest, &dwSize)) {
135 DWORD e = GetLastError();
136 if (is_timeout_error(e)) out_timed_out = true;
137 break;
138 }
139 if (dwSize == 0) break;
140 std::string buf; buf.resize(dwSize);

Callers 1

Calls 3

is_timeout_errorFunction · 0.85
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected