diff --git a/examples/book_client/book_client.cc b/examples/book_client/book_client.cc index 2531a20..7e779a8 100644 --- a/examples/book_client/book_client.cc +++ b/examples/book_client/book_client.cc @@ -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* books) { diff --git a/webcc/client_session.h b/webcc/client_session.h index 04bfcd0..8e28baa 100644 --- a/webcc/client_session.h +++ b/webcc/client_session.h @@ -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; }