mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
moves body to parser rather than response since requests can have bodies too.
This commit is contained in:
@@ -108,6 +108,18 @@ inline void parser::remove_header(const std::string &key) {
|
||||
m_headers.erase(key);
|
||||
}
|
||||
|
||||
inline void parser::set_body(const std::string& value) {
|
||||
if (value.size() == 0) {
|
||||
remove_header("Content-Length");
|
||||
m_body = "";
|
||||
return;
|
||||
}
|
||||
|
||||
std::stringstream foo;
|
||||
foo << value.size();
|
||||
replace_header("Content-Length", foo.str());
|
||||
m_body = value;
|
||||
}
|
||||
|
||||
inline bool parser::parse_headers(std::istream& s) {
|
||||
std::string header;
|
||||
|
||||
@@ -136,7 +136,7 @@ inline std::string request::raw() {
|
||||
std::stringstream raw;
|
||||
|
||||
raw << m_method << " " << m_uri << " " << get_version() << "\r\n";
|
||||
raw << raw_headers() << "\r\n";
|
||||
raw << raw_headers() << "\r\n" << m_body;
|
||||
|
||||
return raw.str();
|
||||
}
|
||||
|
||||
@@ -185,20 +185,6 @@ inline void response::set_status(status_code::value code, const std::string&
|
||||
m_status_code = code;
|
||||
m_status_msg = msg;
|
||||
}
|
||||
|
||||
inline void response::set_body(const std::string& value) {
|
||||
if (value.size() == 0) {
|
||||
remove_header("Content-Length");
|
||||
m_body = "";
|
||||
return;
|
||||
}
|
||||
|
||||
std::stringstream foo;
|
||||
foo << value.size();
|
||||
replace_header("Content-Length", foo.str());
|
||||
m_body = value;
|
||||
}
|
||||
|
||||
|
||||
inline void response::process(std::string::iterator begin,
|
||||
std::string::iterator end)
|
||||
|
||||
@@ -355,6 +355,11 @@ public:
|
||||
*/
|
||||
const std::string& get_header(const std::string& key) const;
|
||||
|
||||
/// Get the body string
|
||||
const std::string& get_body() const {
|
||||
return m_body;
|
||||
}
|
||||
|
||||
/// Get the HTTP header with name `key`
|
||||
/**
|
||||
*
|
||||
@@ -392,6 +397,17 @@ public:
|
||||
|
||||
/// Remove a header
|
||||
void remove_header(const std::string &key);
|
||||
|
||||
/// Set body content
|
||||
/**
|
||||
* Set the body content of the HTTP response to the parameter string. Note
|
||||
* set_body will also set the Content-Length HTTP header to the appropriate
|
||||
* value. If you want the Content-Length header to be something else, do so
|
||||
* via replace_header("Content-Length") after calling set_body()
|
||||
*
|
||||
* @param value String data to include as the body content.
|
||||
*/
|
||||
void set_body(const std::string& value);
|
||||
protected:
|
||||
/// DEPRECATED Read headers out of an istream
|
||||
bool parse_headers(std::istream& s);
|
||||
@@ -401,9 +417,10 @@ protected:
|
||||
|
||||
/// Return headers in raw string form.
|
||||
std::string raw_headers() const;
|
||||
private:
|
||||
|
||||
std::string m_version;
|
||||
header_list m_headers;
|
||||
std::string m_body;
|
||||
};
|
||||
|
||||
} // namespace parser
|
||||
|
||||
@@ -123,17 +123,6 @@ public:
|
||||
*/
|
||||
void set_status(status_code::value code, const std::string& msg);
|
||||
|
||||
/// Set response body content
|
||||
/**
|
||||
* Set the body content of the HTTP response to the parameter string. Note
|
||||
* set_body will also set the Content-Length HTTP header to the appropriate
|
||||
* value. If you want the Content-Length header to be something else set it
|
||||
* to something else after calling set_body
|
||||
*
|
||||
* @param value String data to include as the body content.
|
||||
*/
|
||||
void set_body(const std::string& value);
|
||||
|
||||
/// Return the response status code
|
||||
status_code::value get_status_code() const {
|
||||
return m_status_code;
|
||||
@@ -143,11 +132,6 @@ public:
|
||||
const std::string& get_status_msg() const {
|
||||
return m_status_msg;
|
||||
}
|
||||
|
||||
/// Return the body string
|
||||
const std::string& get_body() const {
|
||||
return m_body;
|
||||
}
|
||||
private:
|
||||
/// Helper function for consume. Process response line
|
||||
void process(std::string::iterator begin, std::string::iterator end);
|
||||
@@ -163,7 +147,6 @@ private:
|
||||
};
|
||||
|
||||
std::string m_status_msg;
|
||||
std::string m_body;
|
||||
size_t m_read;
|
||||
lib::shared_ptr<std::string> m_buf;
|
||||
status_code::value m_status_code;
|
||||
|
||||
Reference in New Issue
Block a user