comparison Core/RestApi/RestApiOutput.cpp @ 2908:9d277f8ad698

new enumeration: MimeType
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Oct 2018 16:16:07 +0100
parents ae20fccdd867
children d924f9bb61cc
comparison
equal deleted inserted replaced
2907:0204af4ece6a 2908:9d277f8ad698
95 { 95 {
96 #if ORTHANC_ENABLE_PUGIXML == 1 96 #if ORTHANC_ENABLE_PUGIXML == 1
97 std::string s; 97 std::string s;
98 Toolbox::JsonToXml(s, value); 98 Toolbox::JsonToXml(s, value);
99 99
100 std::string mime = std::string(MIME_XML) + "; charset=utf-8"; 100 output_.SetContentType(MIME_XML_UTF8);
101 output_.SetContentType(mime.c_str());
102
103 output_.Answer(s); 101 output_.Answer(s);
104 #else 102 #else
105 LOG(ERROR) << "Orthanc was compiled without XML support"; 103 LOG(ERROR) << "Orthanc was compiled without XML support";
106 throw OrthancException(ErrorCode_InternalError); 104 throw OrthancException(ErrorCode_InternalError);
107 #endif 105 #endif
108 } 106 }
109 else 107 else
110 { 108 {
111 std::string mime = std::string(MIME_JSON) + "; charset=utf-8"; 109 Json::StyledWriter writer;
112 output_.SetContentType(mime.c_str()); 110 std::string s = writer.write(value);
113 111
114 Json::StyledWriter writer; 112 output_.SetContentType(MIME_JSON_UTF8);
115 output_.Answer(writer.write(value)); 113 output_.Answer(s);
116 } 114 }
117 115
118 alreadySent_ = true; 116 alreadySent_ = true;
119 } 117 }
120 118
121 void RestApiOutput::AnswerBuffer(const std::string& buffer, 119 void RestApiOutput::AnswerBuffer(const std::string& buffer,
122 const std::string& contentType) 120 MimeType contentType)
123 { 121 {
124 AnswerBuffer(buffer.size() == 0 ? NULL : buffer.c_str(), 122 AnswerBuffer(buffer.size() == 0 ? NULL : buffer.c_str(),
125 buffer.size(), contentType); 123 buffer.size(), contentType);
126 } 124 }
127 125
128 void RestApiOutput::AnswerBuffer(const void* buffer, 126 void RestApiOutput::AnswerBuffer(const void* buffer,
129 size_t length, 127 size_t length,
130 const std::string& contentType) 128 MimeType contentType)
131 { 129 {
132 CheckStatus(); 130 CheckStatus();
133 output_.SetContentType(contentType.c_str()); 131 output_.SetContentType(contentType);
134 output_.Answer(buffer, length); 132 output_.Answer(buffer, length);
135 alreadySent_ = true; 133 alreadySent_ = true;
136 } 134 }
137 135
138 void RestApiOutput::Redirect(const std::string& path) 136 void RestApiOutput::Redirect(const std::string& path)