Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method SetAcceptEncoding for customized Accept-Encoding header (#683
- Loading branch information
1 parent
2157a31
commit be9ece6
Showing
10 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
add_library(cpr | ||
accept_encoding.cpp | ||
async.cpp | ||
auth.cpp | ||
bearer.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "cpr/accept_encoding.h" | ||
|
||
#include <algorithm> | ||
#include <iterator> | ||
#include <numeric> | ||
|
||
namespace cpr { | ||
|
||
AcceptEncoding::AcceptEncoding(const std::initializer_list<AcceptEncodingMethods>& methods) { | ||
methods_.clear(); | ||
std::transform(methods.begin(), methods.end(), std::back_inserter(methods_), [&](cpr::AcceptEncodingMethods method) { return cpr::AcceptEncodingMethodsStringMap.at(method); }); | ||
} | ||
|
||
AcceptEncoding::AcceptEncoding(const std::initializer_list<std::string>& string_methods) : methods_{string_methods} {} | ||
|
||
bool AcceptEncoding::empty() const noexcept { | ||
return methods_.empty(); | ||
} | ||
|
||
const std::string AcceptEncoding::getString() const { | ||
std::string methodsString = std::accumulate(std::next(methods_.begin()), methods_.end(), methods_[0], [](std::string a, std::string b) { return std::move(a) + ", " + std::move(b); }); | ||
return methodsString; | ||
} | ||
|
||
} // namespace cpr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef CPR_ACCEPT_ENCODING_H | ||
#define CPR_ACCEPT_ENCODING_H | ||
|
||
#include <curl/curlver.h> | ||
#include <initializer_list> | ||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace cpr { | ||
|
||
enum class AcceptEncodingMethods { | ||
identity, | ||
deflate, | ||
zlib, | ||
gzip, | ||
}; | ||
|
||
static const std::map<AcceptEncodingMethods, std::string> AcceptEncodingMethodsStringMap{{AcceptEncodingMethods::identity, "identity"}, {AcceptEncodingMethods::deflate, "deflate"}, {AcceptEncodingMethods::zlib, "zlib"}, {AcceptEncodingMethods::gzip, "gzip"}}; | ||
|
||
class AcceptEncoding { | ||
public: | ||
AcceptEncoding() = default; | ||
AcceptEncoding(const std::initializer_list<AcceptEncodingMethods>& methods); | ||
AcceptEncoding(const std::initializer_list<std::string>& methods); | ||
|
||
bool empty() const noexcept; | ||
const std::string getString() const; | ||
|
||
private: | ||
std::vector<std::string> methods_; | ||
}; | ||
|
||
} // namespace cpr | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters