Mercurial > hg > orthanc
annotate Core/HttpClient.cpp @ 2922:40131f0c25b5
Orthanc configuration file can use environment variables
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 Nov 2018 13:06:59 +0100 |
parents | 807169f85ba9 |
children | d924f9bb61cc |
rev | line source |
---|---|
0 | 1 /** |
60
77aec9be0a51
renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
57
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1273
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2270
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
10 * License, or (at your option) any later version. |
0 | 11 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
13 * program give permission to link the code of its release with the |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
22 * in the program, then also delete it here. |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
23 * |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
27 * General Public License for more details. |
0 | 28 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 31 **/ |
32 | |
33 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
34 #include "PrecompiledHeaders.h" |
0 | 35 #include "HttpClient.h" |
36 | |
1404 | 37 #include "Toolbox.h" |
38 #include "OrthancException.h" | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
39 #include "Logging.h" |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
40 #include "ChunkedBuffer.h" |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
41 #include "SystemToolbox.h" |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
42 |
0 | 43 #include <string.h> |
44 #include <curl/curl.h> | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
45 #include <boost/algorithm/string/predicate.hpp> |
1989 | 46 #include <boost/thread/mutex.hpp> |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
47 |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
48 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
49 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 50 # include "Pkcs11.h" |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
51 #endif |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
52 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
53 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
54 extern "C" |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
55 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
56 static CURLcode GetHttpStatus(CURLcode code, CURL* curl, long* status) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
57 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
58 if (code == CURLE_OK) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
59 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
60 code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
61 return code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
62 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
63 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
64 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
65 *status = 0; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
66 return code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
67 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
68 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
69 |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
70 // This is a dummy wrapper function to suppress any OpenSSL-related |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
71 // problem in valgrind. Inlining is prevented. |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
72 #if defined(__GNUC__) || defined(__clang__) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
73 __attribute__((noinline)) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
74 #endif |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
75 static CURLcode OrthancHttpClientPerformSSL(CURL* curl, long* status) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
76 { |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
77 #if ORTHANC_ENABLE_SSL == 1 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
78 return GetHttpStatus(curl_easy_perform(curl), curl, status); |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
79 #else |
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
80 LOG(ERROR) << "Orthanc was compiled without SSL support, cannot make HTTPS request"; |
2474 | 81 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
82 #endif |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
83 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
84 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
85 |
0 | 86 |
87 | |
60
77aec9be0a51
renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
57
diff
changeset
|
88 namespace Orthanc |
0 | 89 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
90 class HttpClient::GlobalParameters |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
91 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
92 private: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
93 boost::mutex mutex_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
94 bool httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
95 std::string httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
96 std::string proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
97 long timeout_; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
98 bool verbose_; |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
99 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
100 GlobalParameters() : |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
101 httpsVerifyPeers_(true), |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
102 timeout_(0), |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
103 verbose_(false) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
104 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
105 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
106 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
107 public: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
108 // Singleton pattern |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
109 static GlobalParameters& GetInstance() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
110 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
111 static GlobalParameters parameters; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
112 return parameters; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
113 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
114 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
115 void ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
116 const std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
117 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
118 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
119 httpsVerifyPeers_ = httpsVerifyPeers; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
120 httpsCACertificates_ = httpsCACertificates; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
121 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
122 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
123 void GetSslConfiguration(bool& httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
124 std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
125 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
126 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
127 httpsVerifyPeers = httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
128 httpsCACertificates = httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
129 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
130 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
131 void SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
132 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
133 LOG(INFO) << "Setting the default proxy for HTTP client connections: " << proxy; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
134 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
135 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
136 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
137 proxy_ = proxy; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
138 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
139 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
140 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
141 void GetDefaultProxy(std::string& target) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
142 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
143 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
144 target = proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
145 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
146 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
147 void SetDefaultTimeout(long seconds) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
148 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
149 LOG(INFO) << "Setting the default timeout for HTTP client connections: " << seconds << " seconds"; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
150 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
151 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
152 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
153 timeout_ = seconds; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
154 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
155 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
156 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
157 long GetDefaultTimeout() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
158 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
159 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
160 return timeout_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
161 } |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
162 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
163 #if ORTHANC_ENABLE_PKCS11 == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
164 bool IsPkcs11Initialized() |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
165 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
166 boost::mutex::scoped_lock lock(mutex_); |
2025 | 167 return Pkcs11::IsInitialized(); |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
168 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
169 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
170 void InitializePkcs11(const std::string& module, |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
171 const std::string& pin, |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
172 bool verbose) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
173 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
174 boost::mutex::scoped_lock lock(mutex_); |
2025 | 175 Pkcs11::Initialize(module, pin, verbose); |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
176 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
177 #endif |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
178 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
179 bool IsDefaultVerbose() const |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
180 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
181 return verbose_; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
182 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
183 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
184 void SetDefaultVerbose(bool verbose) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
185 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
186 verbose_ = verbose; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
187 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
188 }; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
189 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
190 |
0 | 191 struct HttpClient::PImpl |
192 { | |
193 CURL* curl_; | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
194 struct curl_slist *defaultPostHeaders_; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
195 struct curl_slist *userHeaders_; |
0 | 196 }; |
197 | |
198 | |
2787
ad2c32082653
Fix OrthancPluginHttpClient() to return the HTTP status on errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2677
diff
changeset
|
199 void HttpClient::ThrowException(HttpStatus status) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
200 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
201 switch (status) |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
202 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
203 case HttpStatus_400_BadRequest: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
204 throw OrthancException(ErrorCode_BadRequest); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
205 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
206 case HttpStatus_401_Unauthorized: |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
207 case HttpStatus_403_Forbidden: |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
208 throw OrthancException(ErrorCode_Unauthorized); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
209 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
210 case HttpStatus_404_NotFound: |
2044 | 211 throw OrthancException(ErrorCode_UnknownResource); |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
212 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
213 default: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
214 throw OrthancException(ErrorCode_NetworkProtocol); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
215 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
216 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
217 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
218 |
0 | 219 static CURLcode CheckCode(CURLcode code) |
220 { | |
2025 | 221 if (code == CURLE_NOT_BUILT_IN) |
222 { | |
223 LOG(ERROR) << "Your libcurl does not contain a required feature, " | |
224 << "please recompile Orthanc with -DUSE_SYSTEM_CURL=OFF"; | |
225 throw OrthancException(ErrorCode_InternalError); | |
226 } | |
227 | |
0 | 228 if (code != CURLE_OK) |
229 { | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
230 LOG(ERROR) << "libCURL error: " + std::string(curl_easy_strerror(code)); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
231 throw OrthancException(ErrorCode_NetworkProtocol); |
0 | 232 } |
233 | |
234 return code; | |
235 } | |
236 | |
237 | |
2023 | 238 static size_t CurlBodyCallback(void *buffer, size_t size, size_t nmemb, void *payload) |
0 | 239 { |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
240 ChunkedBuffer& target = *(static_cast<ChunkedBuffer*>(payload)); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
241 |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
242 size_t length = size * nmemb; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
243 if (length == 0) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
244 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
245 return 0; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
246 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
247 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
248 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
249 target.AddChunk(buffer, length); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
250 return length; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
251 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
252 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
253 |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
254 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
255 /*static int CurlDebugCallback(CURL *handle, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
256 curl_infotype type, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
257 char *data, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
258 size_t size, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
259 void *userptr) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
260 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
261 switch (type) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
262 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
263 case CURLINFO_TEXT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
264 case CURLINFO_HEADER_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
265 case CURLINFO_HEADER_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
266 case CURLINFO_SSL_DATA_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
267 case CURLINFO_SSL_DATA_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
268 case CURLINFO_END: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
269 case CURLINFO_DATA_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
270 case CURLINFO_DATA_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
271 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
272 std::string s(data, size); |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
273 LOG(INFO) << "libcurl: " << s; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
274 break; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
275 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
276 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
277 default: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
278 break; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
279 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
280 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
281 return 0; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
282 }*/ |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
283 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
284 |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
285 struct CurlHeaderParameters |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
286 { |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
287 bool lowerCase_; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
288 HttpClient::HttpHeaders* headers_; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
289 }; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
290 |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
291 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
292 static size_t CurlHeaderCallback(void *buffer, size_t size, size_t nmemb, void *payload) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
293 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
294 CurlHeaderParameters& parameters = *(static_cast<CurlHeaderParameters*>(payload)); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
295 assert(parameters.headers_ != NULL); |
0 | 296 |
297 size_t length = size * nmemb; | |
298 if (length == 0) | |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
299 { |
0 | 300 return 0; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
301 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
302 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
303 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
304 std::string s(reinterpret_cast<const char*>(buffer), length); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
305 std::size_t colon = s.find(':'); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
306 std::size_t eol = s.find("\r\n"); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
307 if (colon != std::string::npos && |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
308 eol != std::string::npos) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
309 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
310 std::string tmp(s.substr(0, colon)); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
311 |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
312 if (parameters.lowerCase_) |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
313 { |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
314 Toolbox::ToLowerCase(tmp); |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
315 } |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
316 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
317 std::string key = Toolbox::StripSpaces(tmp); |
0 | 318 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
319 if (!key.empty()) |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
320 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
321 std::string value = Toolbox::StripSpaces(s.substr(colon + 1, eol)); |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
322 (*parameters.headers_) [key] = value; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
323 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
324 } |
0 | 325 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
326 return length; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
327 } |
0 | 328 } |
329 | |
330 | |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
331 void HttpClient::Setup() |
0 | 332 { |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
333 pimpl_->userHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
334 pimpl_->defaultPostHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
335 if ((pimpl_->defaultPostHeaders_ = curl_slist_append(pimpl_->defaultPostHeaders_, "Expect:")) == NULL) |
0 | 336 { |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
337 throw OrthancException(ErrorCode_NotEnoughMemory); |
0 | 338 } |
339 | |
340 pimpl_->curl_ = curl_easy_init(); | |
341 if (!pimpl_->curl_) | |
342 { | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
343 curl_slist_free_all(pimpl_->defaultPostHeaders_); |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
344 throw OrthancException(ErrorCode_NotEnoughMemory); |
0 | 345 } |
346 | |
2023 | 347 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlBodyCallback)); |
0 | 348 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0)); |
349 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1)); | |
350 | |
456 | 351 // This fixes the "longjmp causes uninitialized stack frame" crash |
352 // that happens on modern Linux versions. | |
353 // http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame | |
354 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); | |
355 | |
0 | 356 url_ = ""; |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
357 method_ = HttpMethod_Get; |
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
358 lastStatus_ = HttpStatus_200_Ok; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
359 SetVerbose(GlobalParameters::GetInstance().IsDefaultVerbose()); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
360 timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout(); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
361 GlobalParameters::GetInstance().GetDefaultProxy(proxy_); |
2219
262fcab24024
fix for HttpsCACertificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
362 GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_); |
0 | 363 } |
364 | |
365 | |
2020 | 366 HttpClient::HttpClient() : |
367 pimpl_(new PImpl), | |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
368 verifyPeers_(true), |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
369 pkcs11Enabled_(false), |
2107 | 370 headersToLowerCase_(true), |
371 redirectionFollowed_(true) | |
2020 | 372 { |
373 Setup(); | |
374 } | |
375 | |
376 | |
377 HttpClient::HttpClient(const WebServiceParameters& service, | |
378 const std::string& uri) : | |
379 pimpl_(new PImpl), | |
2049 | 380 verifyPeers_(true), |
2107 | 381 headersToLowerCase_(true), |
382 redirectionFollowed_(true) | |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
383 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
384 Setup(); |
2020 | 385 |
386 if (service.GetUsername().size() != 0 && | |
387 service.GetPassword().size() != 0) | |
388 { | |
389 SetCredentials(service.GetUsername().c_str(), | |
390 service.GetPassword().c_str()); | |
391 } | |
392 | |
393 if (!service.GetCertificateFile().empty()) | |
394 { | |
395 SetClientCertificate(service.GetCertificateFile(), | |
396 service.GetCertificateKeyFile(), | |
397 service.GetCertificateKeyPassword()); | |
398 } | |
399 | |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
400 SetPkcs11Enabled(service.IsPkcs11Enabled()); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
401 |
2020 | 402 SetUrl(service.GetUrl() + uri); |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
403 |
2823
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
404 for (WebServiceParameters::Dictionary::const_iterator |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
405 it = service.GetHttpHeaders().begin(); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
406 it != service.GetHttpHeaders().end(); ++it) |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
407 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
408 AddHeader(it->first, it->second); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
409 } |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
410 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
411 |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
412 |
0 | 413 HttpClient::~HttpClient() |
414 { | |
415 curl_easy_cleanup(pimpl_->curl_); | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
416 curl_slist_free_all(pimpl_->defaultPostHeaders_); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
417 ClearHeaders(); |
0 | 418 } |
419 | |
420 | |
421 void HttpClient::SetVerbose(bool isVerbose) | |
422 { | |
423 isVerbose_ = isVerbose; | |
424 | |
425 if (isVerbose_) | |
426 { | |
427 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 1)); | |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
428 //CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_DEBUGFUNCTION, &CurlDebugCallback)); |
0 | 429 } |
430 else | |
431 { | |
432 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 0)); | |
433 } | |
434 } | |
435 | |
436 | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
437 void HttpClient::AddHeader(const std::string& key, |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
438 const std::string& value) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
439 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
440 if (key.empty()) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
441 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
442 throw OrthancException(ErrorCode_ParameterOutOfRange); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
443 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
444 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
445 std::string s = key + ": " + value; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
446 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
447 if ((pimpl_->userHeaders_ = curl_slist_append(pimpl_->userHeaders_, s.c_str())) == NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
448 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
449 throw OrthancException(ErrorCode_NotEnoughMemory); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
450 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
451 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
452 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
453 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
454 void HttpClient::ClearHeaders() |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
455 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
456 if (pimpl_->userHeaders_ != NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
457 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
458 curl_slist_free_all(pimpl_->userHeaders_); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
459 pimpl_->userHeaders_ = NULL; |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
460 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
461 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
462 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
463 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
464 bool HttpClient::ApplyInternal(std::string& answerBody, |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
465 HttpHeaders* answerHeaders) |
0 | 466 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
467 answerBody.clear(); |
0 | 468 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
469 |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
470 CurlHeaderParameters headerParameters; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
471 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
472 if (answerHeaders == NULL) |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
473 { |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
474 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, NULL)); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
475 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, NULL)); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
476 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
477 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
478 { |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
479 headerParameters.lowerCase_ = headersToLowerCase_; |
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
480 headerParameters.headers_ = answerHeaders; |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
481 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, &CurlHeaderCallback)); |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
482 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, &headerParameters)); |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
483 } |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
484 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
485 #if ORTHANC_ENABLE_SSL == 1 |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
486 // Setup HTTPS-related options |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
487 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
488 if (verifyPeers_) |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
489 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
490 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CAINFO, caCertificates_.c_str())); |
1973
7bd4cb780feb
Option "HttpsVerifyPeers" can be used to connect against self-signed HTTPS certificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
491 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYHOST, 2)); // libcurl default is strict verifyhost |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
492 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 1)); |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
493 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
494 else |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
495 { |
1973
7bd4cb780feb
Option "HttpsVerifyPeers" can be used to connect against self-signed HTTPS certificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
496 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYHOST, 0)); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
497 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 0)); |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
498 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
499 #endif |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
500 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
501 // Setup the HTTPS client certificate |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
502 if (!clientCertificateFile_.empty() && |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
503 pkcs11Enabled_) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
504 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
505 LOG(ERROR) << "Cannot enable both client certificates and PKCS#11 authentication"; |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
506 throw OrthancException(ErrorCode_ParameterOutOfRange); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
507 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
508 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
509 if (pkcs11Enabled_) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
510 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
511 #if ORTHANC_ENABLE_PKCS11 == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
512 if (GlobalParameters::GetInstance().IsPkcs11Initialized()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
513 { |
2025 | 514 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLENGINE, Pkcs11::GetEngineIdentifier())); |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
515 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLKEYTYPE, "ENG")); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
516 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERTTYPE, "ENG")); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
517 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
518 else |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
519 { |
2025 | 520 LOG(ERROR) << "Cannot use PKCS#11 for a HTTPS request, because it has not been initialized"; |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
521 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
522 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
523 #else |
2025 | 524 LOG(ERROR) << "This version of Orthanc is compiled without support for PKCS#11"; |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
525 throw OrthancException(ErrorCode_InternalError); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
526 #endif |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
527 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
528 else if (!clientCertificateFile_.empty()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
529 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
530 #if ORTHANC_ENABLE_SSL == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
531 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERTTYPE, "PEM")); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
532 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERT, clientCertificateFile_.c_str())); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
533 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
534 if (!clientCertificateKeyPassword_.empty()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
535 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
536 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_KEYPASSWD, clientCertificateKeyPassword_.c_str())); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
537 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
538 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
539 // NB: If no "clientKeyFile_" is provided, the key must be |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
540 // prepended to the certificate file |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
541 if (!clientCertificateKeyFile_.empty()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
542 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
543 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLKEYTYPE, "PEM")); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
544 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLKEY, clientCertificateKeyFile_.c_str())); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
545 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
546 #else |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
547 LOG(ERROR) << "This version of Orthanc is compiled without OpenSSL support, cannot use HTTPS client authentication"; |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
548 throw OrthancException(ErrorCode_InternalError); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
549 #endif |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
550 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
551 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
552 // Reset the parameters from previous calls to Apply() |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
553 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->userHeaders_)); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
554 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
555 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
556 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
557 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, NULL)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
558 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
559 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0L)); |
1273
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
560 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, NULL)); |
0 | 561 |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
562 if (redirectionFollowed_) |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
563 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
564 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
565 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
566 else |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
567 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
568 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 0L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
569 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
570 |
1186
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
571 // Set timeouts |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
572 if (timeout_ <= 0) |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
573 { |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
574 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_TIMEOUT, 10)); /* default: 10 seconds */ |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
575 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CONNECTTIMEOUT, 10)); /* default: 10 seconds */ |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
576 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
577 else |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
578 { |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
579 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_TIMEOUT, timeout_)); |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
580 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CONNECTTIMEOUT, timeout_)); |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
581 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
582 |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
583 if (credentials_.size() != 0) |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
584 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
585 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_USERPWD, credentials_.c_str())); |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
586 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
587 |
1273
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
588 if (proxy_.size() != 0) |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
589 { |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
590 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, proxy_.c_str())); |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
591 } |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
592 |
0 | 593 switch (method_) |
594 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
595 case HttpMethod_Get: |
0 | 596 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); |
597 break; | |
598 | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
599 case HttpMethod_Post: |
0 | 600 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
601 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
602 if (pimpl_->userHeaders_ == NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
603 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
604 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->defaultPostHeaders_)); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
605 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
606 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
607 break; |
0 | 608 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
609 case HttpMethod_Delete: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
610 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
611 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
612 break; |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
613 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
614 case HttpMethod_Put: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
615 // http://stackoverflow.com/a/7570281/881731: Don't use |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
616 // CURLOPT_PUT if there is a body |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
617 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
618 // CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
619 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
620 curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "PUT"); /* !!! */ |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
621 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
622 if (pimpl_->userHeaders_ == NULL) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
623 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
624 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->defaultPostHeaders_)); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
625 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
626 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
627 break; |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
628 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
629 default: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
630 throw OrthancException(ErrorCode_InternalError); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
631 } |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
632 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
633 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
634 if (method_ == HttpMethod_Post || |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
635 method_ == HttpMethod_Put) |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
636 { |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
637 if (body_.size() > 0) |
0 | 638 { |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
639 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, body_.c_str())); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
640 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, body_.size())); |
0 | 641 } |
642 else | |
643 { | |
644 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); | |
645 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); | |
646 } | |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
647 } |
0 | 648 |
649 | |
650 // Do the actual request | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
651 CURLcode code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
652 long status = 0; |
0 | 653 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
654 ChunkedBuffer buffer; |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
655 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &buffer)); |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
656 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
657 if (boost::starts_with(url_, "https://")) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
658 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
659 code = OrthancHttpClientPerformSSL(pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
660 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
661 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
662 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
663 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
664 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
665 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
666 LOG(INFO) << "HTTP status code " << status << " after " |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
667 << EnumerationToString(method_) << " request on: " << url_; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
668 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
669 if (isVerbose_) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
670 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
671 LOG(INFO) << "cURL status code: " << code; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
672 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
673 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
674 CheckCode(code); |
0 | 675 |
676 if (status == 0) | |
677 { | |
678 // This corresponds to a call to an inexistent host | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
679 lastStatus_ = HttpStatus_500_InternalServerError; |
0 | 680 } |
681 else | |
682 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
683 lastStatus_ = static_cast<HttpStatus>(status); |
0 | 684 } |
685 | |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
686 bool success = (status >= 200 && status < 300); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
687 |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
688 if (success) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
689 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
690 buffer.Flatten(answerBody); |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
691 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
692 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
693 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
694 answerBody.clear(); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
695 LOG(INFO) << "Error in HTTP request, received HTTP status " << status |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
696 << " (" << EnumerationToString(lastStatus_) << ")"; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
697 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
698 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
699 return success; |
0 | 700 } |
701 | |
702 | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
703 bool HttpClient::ApplyInternal(Json::Value& answerBody, |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
704 HttpClient::HttpHeaders* answerHeaders) |
0 | 705 { |
706 std::string s; | |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
707 if (ApplyInternal(s, answerHeaders)) |
0 | 708 { |
709 Json::Reader reader; | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
710 return reader.parse(s, answerBody); |
0 | 711 } |
712 else | |
713 { | |
714 return false; | |
715 } | |
716 } | |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
717 |
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
718 |
468
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
719 void HttpClient::SetCredentials(const char* username, |
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
720 const char* password) |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
721 { |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
722 credentials_ = std::string(username) + ":" + std::string(password); |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
723 } |
457 | 724 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
725 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
726 void HttpClient::ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
727 const std::string& httpsVerifyCertificates) |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
728 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
729 #if ORTHANC_ENABLE_SSL == 1 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
730 if (httpsVerifyPeers) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
731 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
732 if (httpsVerifyCertificates.empty()) |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
733 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
734 LOG(WARNING) << "No certificates are provided to validate peers, " |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
735 << "set \"HttpsCACertificates\" if you need to do HTTPS requests"; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
736 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
737 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
738 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
739 LOG(WARNING) << "HTTPS will use the CA certificates from this file: " << httpsVerifyCertificates; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
740 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
741 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
742 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
743 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
744 LOG(WARNING) << "The verification of the peers in HTTPS requests is disabled"; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
745 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
746 #endif |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
747 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
748 GlobalParameters::GetInstance().ConfigureSsl(httpsVerifyPeers, httpsVerifyCertificates); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
749 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
750 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
751 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
752 void HttpClient::GlobalInitialize() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
753 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
754 #if ORTHANC_ENABLE_SSL == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
755 CheckCode(curl_global_init(CURL_GLOBAL_ALL)); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
756 #else |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
757 CheckCode(curl_global_init(CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL)); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
758 #endif |
457 | 759 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
760 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
761 |
457 | 762 void HttpClient::GlobalFinalize() |
763 { | |
764 curl_global_cleanup(); | |
2025 | 765 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
766 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 767 Pkcs11::Finalize(); |
768 #endif | |
457 | 769 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
770 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
771 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
772 void HttpClient::SetDefaultVerbose(bool verbose) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
773 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
774 GlobalParameters::GetInstance().SetDefaultVerbose(verbose); |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
775 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
776 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
777 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
778 void HttpClient::SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
779 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
780 GlobalParameters::GetInstance().SetDefaultProxy(proxy); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
781 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
782 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
783 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
784 void HttpClient::SetDefaultTimeout(long timeout) |
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
785 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
786 GlobalParameters::GetInstance().SetDefaultTimeout(timeout); |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
787 } |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
788 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
789 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
790 void HttpClient::ApplyAndThrowException(std::string& answerBody) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
791 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
792 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
793 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
794 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
795 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
796 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
797 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
798 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
799 void HttpClient::ApplyAndThrowException(Json::Value& answerBody) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
800 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
801 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
802 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
803 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
804 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
805 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
806 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
807 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
808 void HttpClient::ApplyAndThrowException(std::string& answerBody, |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
809 HttpHeaders& answerHeaders) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
810 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
811 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
812 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
813 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
814 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
815 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
816 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
817 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
818 void HttpClient::ApplyAndThrowException(Json::Value& answerBody, |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
819 HttpHeaders& answerHeaders) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
820 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
821 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
822 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
823 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
824 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
825 } |
2019
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
826 |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
827 |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
828 void HttpClient::SetClientCertificate(const std::string& certificateFile, |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
829 const std::string& certificateKeyFile, |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
830 const std::string& certificateKeyPassword) |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
831 { |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
832 if (certificateFile.empty()) |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
833 { |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
834 throw OrthancException(ErrorCode_ParameterOutOfRange); |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
835 } |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
836 |
2140 | 837 if (!SystemToolbox::IsRegularFile(certificateFile)) |
2019
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
838 { |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
839 LOG(ERROR) << "Cannot open certificate file: " << certificateFile; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
840 throw OrthancException(ErrorCode_InexistentFile); |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
841 } |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
842 |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
843 if (!certificateKeyFile.empty() && |
2140 | 844 !SystemToolbox::IsRegularFile(certificateKeyFile)) |
2019
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
845 { |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
846 LOG(ERROR) << "Cannot open key file: " << certificateKeyFile; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
847 throw OrthancException(ErrorCode_InexistentFile); |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
848 } |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
849 |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
850 clientCertificateFile_ = certificateFile; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
851 clientCertificateKeyFile_ = certificateKeyFile; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
852 clientCertificateKeyPassword_ = certificateKeyPassword; |
9c9332e486ca
HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2016
diff
changeset
|
853 } |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
854 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
855 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
856 void HttpClient::InitializePkcs11(const std::string& module, |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
857 const std::string& pin, |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
858 bool verbose) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
859 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
860 #if ORTHANC_ENABLE_PKCS11 == 1 |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
861 LOG(INFO) << "Initializing PKCS#11 using " << module |
2024 | 862 << (pin.empty() ? " (no PIN provided)" : " (PIN is provided)"); |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
863 GlobalParameters::GetInstance().InitializePkcs11(module, pin, verbose); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
864 #else |
2025 | 865 LOG(ERROR) << "This version of Orthanc is compiled without support for PKCS#11"; |
2022
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
866 throw OrthancException(ErrorCode_InternalError); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
867 #endif |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
868 } |
0 | 869 } |