|
|
|
@ -8,8 +8,13 @@ namespace csoap {
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const HttpResponse& response) {
|
|
|
|
|
// TODO
|
|
|
|
|
os << response.status() << std::endl;
|
|
|
|
|
os << response.start_line();
|
|
|
|
|
|
|
|
|
|
for (const HttpHeader& h : response.headers_) {
|
|
|
|
|
os << h.name << ": " << h.value << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
os << std::endl;
|
|
|
|
|
|
|
|
|
|
// Pretty print the SOAP response XML.
|
|
|
|
|
if (!xml::PrettyPrintXml(os, response.content())) {
|
|
|
|
@ -66,9 +71,10 @@ const char CRLF[] = { '\r', '\n' };
|
|
|
|
|
std::vector<boost::asio::const_buffer> HttpResponse::ToBuffers() const {
|
|
|
|
|
std::vector<boost::asio::const_buffer> buffers;
|
|
|
|
|
|
|
|
|
|
// Status line
|
|
|
|
|
buffers.push_back(status_strings::ToBuffer(status_));
|
|
|
|
|
|
|
|
|
|
// Header fields
|
|
|
|
|
// Header fields (optional)
|
|
|
|
|
for (const HttpHeader& h : headers_) {
|
|
|
|
|
buffers.push_back(boost::asio::buffer(h.name));
|
|
|
|
|
buffers.push_back(boost::asio::buffer(misc_strings::NAME_VALUE_SEPARATOR));
|
|
|
|
@ -77,56 +83,22 @@ std::vector<boost::asio::const_buffer> HttpResponse::ToBuffers() const {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffers.push_back(boost::asio::buffer(misc_strings::CRLF));
|
|
|
|
|
buffers.push_back(boost::asio::buffer(content_));
|
|
|
|
|
|
|
|
|
|
// Content (optional)
|
|
|
|
|
if (IsContentLengthValid()) {
|
|
|
|
|
buffers.push_back(boost::asio::buffer(content_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Move to SoapResponse
|
|
|
|
|
static void CreateSoapFaultResponse(HttpStatus status,
|
|
|
|
|
std::string* xml_string) {
|
|
|
|
|
Namespace soapenv_ns{
|
|
|
|
|
"soap",
|
|
|
|
|
"http://schemas.xmlsoap.org/soap/envelope/"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pugi::xml_document xdoc;
|
|
|
|
|
pugi::xml_node xroot = xml::AddChild(xdoc, soapenv_ns.name, "Envelope");
|
|
|
|
|
|
|
|
|
|
xml::AddNSAttr(xroot, soapenv_ns.name, soapenv_ns.url);
|
|
|
|
|
|
|
|
|
|
// FIXME: Body
|
|
|
|
|
// See https://www.w3schools.com/XML/xml_soap.asp
|
|
|
|
|
|
|
|
|
|
pugi::xml_node xfault = xml::AddChild(xroot, soapenv_ns.name, "Fault");
|
|
|
|
|
|
|
|
|
|
pugi::xml_node xfaultcode = xfault.append_child("faultcode");
|
|
|
|
|
xfaultcode.text().set(std::to_string(HttpStatus::BAD_REQUEST).c_str()); // TODO
|
|
|
|
|
|
|
|
|
|
pugi::xml_node xfaultstring = xfault.append_child("faultstring");
|
|
|
|
|
xfaultstring.text().set("Bad Request"); // TODO
|
|
|
|
|
|
|
|
|
|
// TODO: faultactor
|
|
|
|
|
|
|
|
|
|
xml::XmlStrRefWriter writer(xml_string);
|
|
|
|
|
xdoc.save(writer, "\t", pugi::format_default, pugi::encoding_utf8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HttpResponse HttpResponse::Fault(HttpStatus status) {
|
|
|
|
|
assert(status != HttpStatus::OK);
|
|
|
|
|
|
|
|
|
|
HttpResponse response;
|
|
|
|
|
|
|
|
|
|
std::string content;
|
|
|
|
|
CreateSoapFaultResponse(status, &content);
|
|
|
|
|
|
|
|
|
|
response.set_content(content);
|
|
|
|
|
response.set_content_length(content.length());
|
|
|
|
|
response.set_content_type("text/xml");
|
|
|
|
|
|
|
|
|
|
response.set_status(status);
|
|
|
|
|
|
|
|
|
|
return response; // TODO: Output parameter?
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace csoap
|
|
|
|
|