ClientSession: SetContentType()

This commit is contained in:
Chunting Gu
2020-08-18 09:37:52 +08:00
parent b38e6c153d
commit 8106da401e
2 changed files with 8 additions and 7 deletions
+2 -3
View File
@@ -10,9 +10,8 @@
BookClient::BookClient(const std::string& url, int timeout)
: url_(url), session_(timeout) {
// Default Content-Type for requests who have a body.
session_.set_media_type("application/json");
session_.set_charset("utf-8");
// Default Content-Type for requests with a body.
session_.SetContentType("application/json", "utf-8");
}
bool BookClient::Query(std::list<Book>* books) {
+6 -4
View File
@@ -38,11 +38,13 @@ public:
headers_.Set(key, value);
}
void set_media_type(const std::string& media_type) {
// Set `Content-Type` header, e.g., ("application/json", "utf-8").
// Only applied when:
// - the request to send has no `Content-Type` header, and
// - the request has a body.
void SetContentType(const std::string& media_type,
const std::string& charset = "") {
media_type_ = media_type;
}
void set_charset(const std::string& charset) {
charset_ = charset;
}