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
5e64f82
commit 021210a
Showing
9 changed files
with
114 additions
and
2 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 | ||
auth.cpp | ||
bearer.cpp | ||
cookies.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,23 @@ | ||
#include "cpr/accept_encoding.h" | ||
|
||
namespace cpr { | ||
|
||
AcceptEncoding::AcceptEncoding(const std::initializer_list<AcceptEncodingMethods>& methods) : methods_{methods} {} | ||
|
||
bool AcceptEncoding::isEmpty() const { | ||
return methods_.empty(); | ||
} | ||
|
||
const std::string& AcceptEncoding::getString() const { | ||
std::string* accept_encoding = new std::string(); | ||
for (AcceptEncodingMethods method : methods_) { | ||
*accept_encoding += AcceptEncoding::MethodsString.at(method) + ", "; | ||
} | ||
if (!accept_encoding->empty()) { | ||
accept_encoding->pop_back(); | ||
accept_encoding->pop_back(); | ||
} | ||
return *accept_encoding; | ||
} | ||
|
||
} // 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,40 @@ | ||
#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, | ||
}; | ||
|
||
class AcceptEncoding { | ||
public: | ||
std::map<AcceptEncodingMethods, std::string> MethodsString { | ||
{AcceptEncodingMethods::identity, "identity"}, | ||
{AcceptEncodingMethods::deflate, "deflate"}, | ||
{AcceptEncodingMethods::zlib, "zlib"}, | ||
{AcceptEncodingMethods::gzip, "gzip"} | ||
}; | ||
|
||
AcceptEncoding() = default; | ||
AcceptEncoding(const std::initializer_list<AcceptEncodingMethods>& methods); | ||
|
||
bool isEmpty() const; | ||
const std::string& getString() const; | ||
|
||
private: | ||
std::vector<AcceptEncodingMethods> 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