Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
2040:6ea2e264ca50 | 2041:9f61ca1e3eb3 |
---|---|
1809 } | 1809 } |
1810 | 1810 |
1811 client.SetClientCertificate(certificate, key, password); | 1811 client.SetClientCertificate(certificate, key, password); |
1812 } | 1812 } |
1813 | 1813 |
1814 client.SetPkcs11Enabled(p.pkcs11 ? true : false); | 1814 client.SetPkcs11Enabled(p.pkcs11 ? true : false); |
1815 | 1815 |
1816 for (uint32_t i = 0; i < p.headersCount; i++) | 1816 for (uint32_t i = 0; i < p.headersCount; i++) |
1817 { | 1817 { |
1818 if (p.headersKeys[i] == NULL || | 1818 if (p.headersKeys[i] == NULL || |
1819 p.headersValues[i] == NULL) | 1819 p.headersValues[i] == NULL) |
1846 | 1846 |
1847 default: | 1847 default: |
1848 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1848 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1849 } | 1849 } |
1850 | 1850 |
1851 std::string s; | 1851 std::string body; |
1852 | 1852 HttpClient::HttpHeaders headers; |
1853 if (!client.Apply(s)) | 1853 |
1854 { | 1854 client.ApplyAndThrowException(body, headers); |
1855 *p.httpStatus = 0; | 1855 |
1856 throw OrthancException(ErrorCode_NetworkProtocol); | 1856 // The HTTP request has succeeded |
1857 } | |
1858 | |
1859 *p.httpStatus = static_cast<uint16_t>(client.GetLastStatus()); | 1857 *p.httpStatus = static_cast<uint16_t>(client.GetLastStatus()); |
1860 | 1858 |
1859 // Copy the HTTP headers of the answer, if the plugin requested them | |
1860 if (p.answerHeaders != NULL) | |
1861 { | |
1862 Json::Value json = Json::objectValue; | |
1863 | |
1864 for (HttpClient::HttpHeaders::const_iterator | |
1865 it = headers.begin(); it != headers.end(); ++it) | |
1866 { | |
1867 json[it->first] = it->second; | |
1868 } | |
1869 | |
1870 std::string s = json.toStyledString(); | |
1871 CopyToMemoryBuffer(*p.answerHeaders, s); | |
1872 } | |
1873 | |
1874 // Copy the body of the answer if it makes sense | |
1861 if (p.method != OrthancPluginHttpMethod_Delete) | 1875 if (p.method != OrthancPluginHttpMethod_Delete) |
1862 { | 1876 { |
1863 CopyToMemoryBuffer(*p.target, s); | 1877 CopyToMemoryBuffer(*p.answerBody, body); |
1864 } | 1878 } |
1865 } | 1879 } |
1866 | 1880 |
1867 | 1881 |
1868 void OrthancPlugins::ConvertPixelFormat(const void* parameters) | 1882 void OrthancPlugins::ConvertPixelFormat(const void* parameters) |