• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 12288499988

12 Dec 2024 02:10AM UTC coverage: 37.517%. First build
12288499988

Pull #2471

github

web-flow
Merge 6f8d12229 into 22d107094
Pull Request #2471: core: use http instead of https

0 of 6 new or added lines in 1 file covered. (0.0%)

11159 of 29744 relevant lines covered (37.52%)

254.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.02
/src/mavsdk/core/http_loader.cpp
1
#include "http_loader.h"
2
#include "curl_wrapper.h"
3
#include "log.h"
4

5
namespace mavsdk {
6

7
#ifdef TESTING
8
HttpLoader::HttpLoader(const std::shared_ptr<ICurlWrapper>& curl_wrapper) :
9
    _curl_wrapper(curl_wrapper)
10
{
11
    start();
12
}
13
#endif
14

15
HttpLoader::HttpLoader() : _curl_wrapper(std::make_shared<CurlWrapper>())
1✔
16
{
17
    start();
1✔
18
}
1✔
19

20
HttpLoader::~HttpLoader()
1✔
21
{
22
    stop();
1✔
23
}
1✔
24

25
void HttpLoader::start()
1✔
26
{
27
    _should_exit = false;
1✔
28
    _work_thread = new std::thread(work_thread, this);
1✔
29
}
1✔
30

31
void HttpLoader::stop()
1✔
32
{
33
    _should_exit = true;
1✔
34
    _work_queue.stop();
1✔
35
    if (_work_thread != nullptr) {
1✔
36
        _work_thread->join();
1✔
37
        delete _work_thread;
1✔
38
        _work_thread = nullptr;
1✔
39
    }
40
}
1✔
41

42
bool HttpLoader::download_sync(const std::string& url, const std::string& local_path)
×
43
{
44
    auto work_item = std::make_shared<DownloadItem>(url, local_path, nullptr);
×
45
    bool success = do_download(work_item, _curl_wrapper);
×
46
    return success;
×
47
}
48

49
void HttpLoader::download_async(
×
50
    const std::string& url,
51
    const std::string& local_path,
52
    const ProgressCallback& progress_callback)
53
{
54
    auto work_item = std::make_shared<DownloadItem>(url, local_path, progress_callback);
×
55
    _work_queue.enqueue(work_item);
×
56
}
×
57

58
void HttpLoader::work_thread(HttpLoader* self)
2✔
59
{
60
    while (!self->_should_exit) {
2✔
61
        auto item = self->_work_queue.dequeue();
1✔
62
        auto curl_wrapper = self->_curl_wrapper;
1✔
63
        if (!item || curl_wrapper == nullptr) {
1✔
64
            continue;
1✔
65
        }
66
        do_item(item.value(), curl_wrapper);
×
67
    }
68
}
1✔
69

70
void HttpLoader::do_item(
×
71
    const std::shared_ptr<WorkItem>& item, const std::shared_ptr<ICurlWrapper>& curl_wrapper)
72
{
73
    auto download_item = std::dynamic_pointer_cast<DownloadItem>(item);
×
74
    if (nullptr != download_item) {
×
75
        do_download(download_item, curl_wrapper);
×
76
        return;
×
77
    }
78
}
79

80
bool HttpLoader::do_download(
×
81
    const std::shared_ptr<DownloadItem>& item, const std::shared_ptr<ICurlWrapper>& curl_wrapper)
82
{
83
    bool success = curl_wrapper->download_file_to_path(
×
84
        item->get_url(), item->get_local_path(), item->get_progress_callback());
×
85
    return success;
×
86
}
87

88
bool HttpLoader::download_text_sync(const std::string& url, std::string& content)
×
89
{
NEW
90
    std::string http_url(url);
×
91

92
    // We don't have https support in curl, so we try to use http for now.
93

NEW
94
    std::string https = "https";
×
NEW
95
    if (http_url.find(https, 0) == 0) {
×
NEW
96
        http_url.replace(0, https.size(), "http");
×
NEW
97
        LogWarn() << "Downloading over http instead of https";
×
98
    }
99

NEW
100
    bool success = _curl_wrapper->download_text(http_url, content);
×
101
    return success;
×
102
}
103

104
} // namespace mavsdk
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc