Mercurial > hg > orthanc
diff Plugins/Engine/OrthancPlugins.cpp @ 2041:9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 Jun 2016 17:08:09 +0200 |
parents | d108412411e5 |
children | 21a8ca9ad928 |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp Tue Jun 21 16:34:30 2016 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Tue Jun 21 17:08:09 2016 +0200 @@ -1811,7 +1811,7 @@ client.SetClientCertificate(certificate, key, password); } - client.SetPkcs11Enabled(p.pkcs11 ? true : false); + client.SetPkcs11Enabled(p.pkcs11 ? true : false); for (uint32_t i = 0; i < p.headersCount; i++) { @@ -1848,19 +1848,33 @@ throw OrthancException(ErrorCode_ParameterOutOfRange); } - std::string s; - - if (!client.Apply(s)) + std::string body; + HttpClient::HttpHeaders headers; + + client.ApplyAndThrowException(body, headers); + + // The HTTP request has succeeded + *p.httpStatus = static_cast<uint16_t>(client.GetLastStatus()); + + // Copy the HTTP headers of the answer, if the plugin requested them + if (p.answerHeaders != NULL) { - *p.httpStatus = 0; - throw OrthancException(ErrorCode_NetworkProtocol); + Json::Value json = Json::objectValue; + + for (HttpClient::HttpHeaders::const_iterator + it = headers.begin(); it != headers.end(); ++it) + { + json[it->first] = it->second; + } + + std::string s = json.toStyledString(); + CopyToMemoryBuffer(*p.answerHeaders, s); } - *p.httpStatus = static_cast<uint16_t>(client.GetLastStatus()); - + // Copy the body of the answer if it makes sense if (p.method != OrthancPluginHttpMethod_Delete) { - CopyToMemoryBuffer(*p.target, s); + CopyToMemoryBuffer(*p.answerBody, body); } }