Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Contributing to C++ Requests

Please fork this repository and contribute back using [pull requests](https://github.com/whoshuu/cpr/pulls). Features can be requested using [issues](https://github.com/whoshuu/cpr/issues). All code, comments, and critiques are greatly appreciated.
Please fork this repository and contribute back using [pull requests](https://github.com/libcpr/cpr/pulls). Features can be requested using [issues](https://github.com/libcpr/cpr/issues). All code, comments, and critiques are greatly appreciated.

## Formatting

To avoid unproductive debates on formatting, this project uses `clang-format` to ensure a consistent style across all source files. Currently, `clang-format` 3.8 is the version of `clang-format` we use. The format file can be found [here](https://github.com/whoshuu/cpr/blob/master/.clang-format). To install `clang-format` on Ubuntu, run this:
To avoid unproductive debates on formatting, this project uses `clang-format` to ensure a consistent style across all source files. Currently, `clang-format` 3.8 is the version of `clang-format` we use. The format file can be found [here](https://github.com/libcpr/cpr/blob/master/.clang-format). To install `clang-format` on Ubuntu, run this:

```
apt-get install clang-format-3.8
Expand All @@ -21,7 +21,7 @@ Note that `brew` might install a later version of `clang-format`, but it should
To run `clang-format` on every source file, run this in the root directory:

```
./format-check.sh
./scripts/run_clang_format.sh cpr include/cpr
```

This should indicate which files need formatting and also show a diff of the requested changes. More specific usage instructions can be found on the official [LLVM website](http://releases.llvm.org/3.8.0/tools/clang/docs/ClangFormat.html).
7 changes: 4 additions & 3 deletions cpr/error.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "cpr/error.h"
#include <curl/curlver.h>
#include <unordered_map>
#include <cstdint>
#include <curl/curl.h>
#include <curl/curlver.h>
#include <unordered_map>

namespace cpr {
static const std::unordered_map<std::int32_t, ErrorCode> curl_error_map = { // NOLINT - (needed because of static init)
static const std::unordered_map<std::int32_t, ErrorCode> curl_error_map = {
// NOLINT - (needed because of static init)
{CURLE_OK, ErrorCode::OK},
{CURLE_UNSUPPORTED_PROTOCOL, ErrorCode::UNSUPPORTED_PROTOCOL},
{CURLE_FAILED_INIT, ErrorCode::FAILED_INIT},
Expand Down
4 changes: 4 additions & 0 deletions cpr/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ void Session::UpdateHeader(const Header& header) {
}
}

Header& Session::GetHeader() {
return header_;
}

void Session::SetTimeout(const Timeout& timeout) {
curl_easy_setopt(curl_->handle, CURLOPT_TIMEOUT_MS, timeout.Milliseconds());
}
Expand Down
2 changes: 1 addition & 1 deletion include/cpr/async_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "cpr/response.h"

namespace cpr {
enum class [[nodiscard]] CancellationResult { failure, success, invalid_operation };
enum class [[nodiscard]] CancellationResult{failure, success, invalid_operation};

/**
* A class template intended to wrap results of async operations (instances of std::future<T>)
Expand Down
1 change: 1 addition & 0 deletions include/cpr/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Session : public std::enable_shared_from_this<Session> {
void SetParameters(Parameters&& parameters);
void SetHeader(const Header& header);
void UpdateHeader(const Header& header);
Header& GetHeader();
void SetTimeout(const Timeout& timeout);
void SetConnectTimeout(const ConnectTimeout& timeout);
void SetAuth(const Authentication& auth);
Expand Down
3 changes: 1 addition & 2 deletions include/cpr/timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class Timeout {
// Template constructor to accept any chrono duration type and convert it to milliseconds
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
template <typename Rep, typename Period>
Timeout(const std::chrono::duration<Rep, Period>& duration)
: ms{std::chrono::duration_cast<std::chrono::milliseconds>(duration)} {}
Timeout(const std::chrono::duration<Rep, Period>& duration) : ms{std::chrono::duration_cast<std::chrono::milliseconds>(duration)} {}

// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Timeout(const std::int32_t& milliseconds) : Timeout{std::chrono::milliseconds(milliseconds)} {}
Expand Down
15 changes: 14 additions & 1 deletion test/session_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,27 @@ TEST(MultipleGetTests, HeaderChangeMultipleGetTest) {
EXPECT_EQ(200, response.status_code);
EXPECT_EQ(ErrorCode::OK, response.error.code);
}
session.SetHeader(Header{{"key", "value"}});
session.SetHeader(Header{{"key", "value"}, {"lorem", "ipsum"}});
{
Response response = session.Get();
std::string expected_text{"Header reflect GET"};
EXPECT_EQ(expected_text, response.text);
EXPECT_EQ(url, response.url);
EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
EXPECT_EQ(std::string{"value"}, response.header["key"]);
EXPECT_EQ(std::string{"ipsum"}, response.header["lorem"]);
EXPECT_EQ(200, response.status_code);
EXPECT_EQ(ErrorCode::OK, response.error.code);
}
Header& headerMap = session.GetHeader();
headerMap.erase("key");
{
Response response = session.Get();
std::string expected_text{"Header reflect GET"};
EXPECT_EQ(expected_text, response.text);
EXPECT_EQ(url, response.url);
EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
EXPECT_EQ(std::string{"ipsum"}, response.header["lorem"]);
EXPECT_EQ(200, response.status_code);
EXPECT_EQ(ErrorCode::OK, response.error.code);
}
Expand Down
Loading