Skip to content

Commit 55fc58b

Browse files
committed
Detect non-success HTTP status codes
1 parent 57b6a4e commit 55fc58b

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/appimagetool_fetch_runtime.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@
1414
class CurlResponse {
1515
private:
1616
bool _success;
17+
long _statusCode;
1718
std::string _effectiveUrl;
1819
curl_off_t _contentLength;
1920
std::vector<char> _data;
2021

2122
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)) {}
2628

2729
[[nodiscard]] bool success() const {
2830
return _success;
2931
}
3032

33+
[[nodiscard]] auto statusCode() const {
34+
return _statusCode;
35+
}
36+
3137
[[nodiscard]] curl_off_t contentLength() const {
3238
return _contentLength;
3339
}
@@ -241,7 +247,12 @@ class GetRequest {
241247

242248
CurlResponse perform() {
243249
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+
};
245256
}
246257
};
247258

@@ -257,6 +268,11 @@ bool fetch_runtime(char *arch, size_t *size, char **buffer, bool verbose) {
257268

258269
auto response = request.perform();
259270

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+
260276
std::cerr << "Downloaded runtime binary of size " << response.contentLength() << std::endl;
261277

262278
if (!response.success()) {

0 commit comments

Comments
 (0)