ClientSession: SetContentType()
This commit is contained in:
@@ -10,9 +10,8 @@
|
|||||||
|
|
||||||
BookClient::BookClient(const std::string& url, int timeout)
|
BookClient::BookClient(const std::string& url, int timeout)
|
||||||
: url_(url), session_(timeout) {
|
: url_(url), session_(timeout) {
|
||||||
// Default Content-Type for requests who have a body.
|
// Default Content-Type for requests with a body.
|
||||||
session_.set_media_type("application/json");
|
session_.SetContentType("application/json", "utf-8");
|
||||||
session_.set_charset("utf-8");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BookClient::Query(std::list<Book>* books) {
|
bool BookClient::Query(std::list<Book>* books) {
|
||||||
|
|||||||
@@ -38,11 +38,13 @@ public:
|
|||||||
headers_.Set(key, value);
|
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;
|
media_type_ = media_type;
|
||||||
}
|
|
||||||
|
|
||||||
void set_charset(const std::string& charset) {
|
|
||||||
charset_ = charset;
|
charset_ = charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user