Add getter and setter for Content-Type header

Fixes #296
Closes #305
This commit is contained in:
Donny Lawrence 2018-04-20 22:25:01 -05:00 committed by rdb
parent 1ac351d594
commit 574000aedd
3 changed files with 23 additions and 1 deletions

View File

@ -426,6 +426,23 @@ get_max_updates_per_second() const {
return _max_updates_per_second;
}
/**
* Specifies the Content-Type header, useful for applications that require
* different types of content, such as JSON.
*/
INLINE void HTTPChannel::
set_content_type(string content_type) {
_content_type = content_type;
}
/**
* Returns the value of the Content-Type header.
*/
INLINE string HTTPChannel::
get_content_type() const {
return _content_type;
}
/**
* This may be called immediately after a call to get_document() or some
* related function to specify the expected size of the document we are

View File

@ -100,6 +100,7 @@ HTTPChannel(HTTPClient *client) :
_response_type = RT_none;
_http_version = _client->get_http_version();
_http_version_string = _client->get_http_version_string();
_content_type = "application/x-www-form-urlencoded";
_state = S_new;
_done_state = S_new;
_started_download = false;
@ -3624,7 +3625,7 @@ make_header() {
if (!_body.empty()) {
stream
<< "Content-Type: application/x-www-form-urlencoded\r\n"
<< "Content-Type: " << _content_type << "\r\n"
<< "Content-Length: " << _body.length() << "\r\n";
}

View File

@ -143,6 +143,9 @@ PUBLISHED:
INLINE void set_max_updates_per_second(double max_updates_per_second);
INLINE double get_max_updates_per_second() const;
INLINE void set_content_type(string content_type);
INLINE string get_content_type() const;
INLINE void set_expected_file_size(size_t file_size);
streamsize get_file_size() const;
INLINE bool is_file_size_known() const;
@ -336,6 +339,7 @@ private:
string request_path;
string _header;
string _body;
string _content_type;
bool _want_ssl;
bool _proxy_serves_document;
bool _proxy_tunnel_now;