Skip to content

Commit

Permalink
Merge pull request #1111 from libcpr/feature/curl-8.10.1
Browse files Browse the repository at this point in the history
Curl 8.10.1
  • Loading branch information
COM8 authored Sep 22, 2024
2 parents 678e326 + 0d1cae8 commit 1d45df8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ else()
cmake_policy(SET CMP0135 NEW)
endif()
FetchContent_Declare(curl
URL https://github.com/curl/curl/releases/download/curl-8_7_1/curl-8.7.1.tar.xz
URL_HASH SHA256=6fea2aac6a4610fbd0400afb0bcddbe7258a64c63f1f68e5855ebc0c659710cd # the file hash for curl-8.7.1.tar.xz
URL https://github.com/curl/curl/releases/download/curl-8_10_1/curl-8.10.1.tar.xz
URL_HASH SHA256=73a4b0e99596a09fa5924a4fb7e4b995a85fda0d18a2c02ab9cf134bebce04ee # the file hash for curl-8.10.1.tar.xz
USES_TERMINAL_DOWNLOAD TRUE) # <---- This is needed only for Ninja to show download progress
FetchContent_MakeAvailable(curl)

Expand Down
11 changes: 8 additions & 3 deletions cpr/multiperform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <cassert>
#include <cstddef>
#include <curl/curl.h>
#include <curl/multi.h>
#include <curl/curlver.h>
#include <curl/multi.h>
#include <functional>
#include <iosfwd>
#include <iostream>
Expand Down Expand Up @@ -68,14 +68,19 @@ void MultiPerform::AddSession(std::shared_ptr<Session>& session, HttpMethod meth
}

void MultiPerform::RemoveSession(const std::shared_ptr<Session>& session) {
// Has to be handled before calling curl_multi_remove_handle to avoid it returning something != CURLM_OK.
if (sessions_.empty()) {
throw std::invalid_argument("Failed to find session!");
}

// Remove easy handle from multihandle
const CURLMcode error_code = curl_multi_remove_handle(multicurl_->handle, session->curl_->handle);
if (error_code) {
if (error_code != CURLM_OK) {
std::cerr << "curl_multi_remove_handle() failed, code " << static_cast<int>(error_code) << '\n';
return;
}

// Unock session
// Unlock session
session->isUsedInMultiPerform = false;

// Remove session from sessions_
Expand Down
7 changes: 7 additions & 0 deletions test/get_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ using namespace cpr;

static HttpServer* server = new HttpServer();

TEST(BasicTests, XXXTest) {
Url url{"https://getsolara.dev/api/endpoint.json"};
Response response = cpr::Get(url);
EXPECT_EQ(200, response.status_code);
EXPECT_EQ(ErrorCode::OK, response.error.code);
}

TEST(BasicTests, HelloWorldTest) {
Url url{server->GetBaseUrl() + "/hello.html"};
Response response = cpr::Get(url);
Expand Down
11 changes: 10 additions & 1 deletion test/multiperform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,21 @@ TEST(MultiperformRemoveSessionTests, MultiperformRemoveMultipleSessionsTest) {
}
}

TEST(MultiperformRemoveSessionTests, MultiperformRemoveNonExistingSessionTest) {
TEST(MultiperformRemoveSessionTests, MultiperformRemoveNonExistingSessionEmptyTest) {
std::shared_ptr<Session> session = std::make_shared<Session>();
MultiPerform multiperform;
EXPECT_THROW(multiperform.RemoveSession(session), std::invalid_argument);
}

TEST(MultiperformRemoveSessionTests, MultiperformRemoveNonExistingSessionTest) {
MultiPerform multiperform;
std::shared_ptr<Session> session = std::make_shared<Session>();
multiperform.AddSession(session);

std::shared_ptr<Session> session2 = std::make_shared<Session>();
EXPECT_THROW(multiperform.RemoveSession(session2), std::invalid_argument);
}

TEST(MultiperformGetTests, MultiperformSingleSessionGetTest) {
Url url{server->GetBaseUrl() + "/hello.html"};
std::shared_ptr<Session> session = std::make_shared<Session>();
Expand Down

0 comments on commit 1d45df8

Please sign in to comment.