14
14
class CurlResponse {
15
15
private:
16
16
bool _success;
17
+ long _statusCode;
17
18
std::string _effectiveUrl;
18
19
curl_off_t _contentLength;
19
20
std::vector<char > _data;
20
21
21
22
public:
22
- CurlResponse (bool success, curl_off_t contentLength, std::vector<char > data)
23
- : _success(success)
24
- , _contentLength(contentLength)
25
- , _data(std::move(data)) {}
23
+ CurlResponse (bool success, long statusCode, curl_off_t contentLength, std::vector<char > data)
24
+ : _success(success)
25
+ , _statusCode(statusCode)
26
+ , _contentLength(contentLength)
27
+ , _data(std::move(data)) {}
26
28
27
29
[[nodiscard]] bool success () const {
28
30
return _success;
29
31
}
30
32
33
+ [[nodiscard]] auto statusCode () const {
34
+ return _statusCode;
35
+ }
36
+
31
37
[[nodiscard]] curl_off_t contentLength () const {
32
38
return _contentLength;
33
39
}
@@ -241,7 +247,12 @@ class GetRequest {
241
247
242
248
CurlResponse perform () {
243
249
auto result = curl_easy_perform (this ->_handle );
244
- return {result == CURLE_OK, getOption<curl_off_t >(CURLINFO_CONTENT_LENGTH_DOWNLOAD_T), _buffer};
250
+ return {
251
+ result == CURLE_OK,
252
+ getOption<long >(CURLINFO_RESPONSE_CODE),
253
+ getOption<curl_off_t >(CURLINFO_CONTENT_LENGTH_DOWNLOAD_T),
254
+ _buffer
255
+ };
245
256
}
246
257
};
247
258
@@ -257,6 +268,11 @@ bool fetch_runtime(char *arch, size_t *size, char **buffer, bool verbose) {
257
268
258
269
auto response = request.perform ();
259
270
271
+ if (response.statusCode () != 200 ) {
272
+ std::cerr << " Failed to download runtime: server returned status code " << response.statusCode () << std::endl;
273
+ return false ;
274
+ }
275
+
260
276
std::cerr << " Downloaded runtime binary of size " << response.contentLength () << std::endl;
261
277
262
278
if (!response.success ()) {
0 commit comments