Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpClient.cpp @ 4564:5a0adc1c19a9 db-changes
avoid copy of objects in ServerIndex
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Mar 2021 11:08:03 +0100 |
parents | 017ab543e6ef |
children | 9804d6490872 |
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 |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
5 * Copyright (C) 2017-2021 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 |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the 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 * 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
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
0 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
0 | 20 **/ |
21 | |
22 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
23 #include "PrecompiledHeaders.h" |
0 | 24 #include "HttpClient.h" |
25 | |
1404 | 26 #include "Toolbox.h" |
27 #include "OrthancException.h" | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
28 #include "Logging.h" |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
29 #include "ChunkedBuffer.h" |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
30 #include "SystemToolbox.h" |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
31 |
0 | 32 #include <string.h> |
33 #include <curl/curl.h> | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
34 #include <boost/algorithm/string/predicate.hpp> |
1989 | 35 #include <boost/thread/mutex.hpp> |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
36 |
3428
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
37 // Default timeout = 60 seconds (in Orthanc <= 1.5.6, it was 10 seconds) |
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
38 static const unsigned int DEFAULT_HTTP_TIMEOUT = 60; |
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
39 |
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
40 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
41 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 42 # 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
|
43 #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
|
44 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
45 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
46 extern "C" |
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 static CURLcode GetHttpStatus(CURLcode code, CURL* curl, long* status) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
49 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
50 if (code == CURLE_OK) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
51 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
52 code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
53 return code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
54 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
55 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
56 { |
3122
df4f977c2f88
trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3114
diff
changeset
|
57 LOG(ERROR) << "Error code " << static_cast<int>(code) |
df4f977c2f88
trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3114
diff
changeset
|
58 << " in libcurl: " << curl_easy_strerror(code); |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
59 *status = 0; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
60 return code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
61 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
62 } |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
63 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
64 |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
65 // This is a dummy wrapper function to suppress any OpenSSL-related |
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
66 // problem in valgrind. Inlining is prevented. |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
67 #if defined(__GNUC__) || defined(__clang__) |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
68 __attribute__((noinline)) |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
69 #endif |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
70 static CURLcode OrthancHttpClientPerformSSL(CURL* curl, long* status) |
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
71 { |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
72 #if ORTHANC_ENABLE_SSL == 1 |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
73 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
|
74 #else |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, |
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
76 "Orthanc was compiled without SSL support, " |
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
77 "cannot make HTTPS request"); |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
78 #endif |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
79 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
80 |
0 | 81 |
82 | |
60
77aec9be0a51
renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
57
diff
changeset
|
83 namespace Orthanc |
0 | 84 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
85 static CURLcode CheckCode(CURLcode code) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
86 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
87 if (code == CURLE_NOT_BUILT_IN) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
88 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
89 throw OrthancException(ErrorCode_InternalError, |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
90 "Your libcurl does not contain a required feature, " |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
91 "please recompile Orthanc with -DUSE_SYSTEM_CURL=OFF"); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
92 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
93 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
94 if (code != CURLE_OK) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
95 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
96 throw OrthancException(ErrorCode_NetworkProtocol, |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
97 "libCURL error: " + std::string(curl_easy_strerror(code))); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
98 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
99 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
100 return code; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
101 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
102 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
103 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
104 // RAII pattern around a "curl_slist" |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
105 class HttpClient::CurlHeaders : public boost::noncopyable |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
106 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
107 private: |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
108 struct curl_slist *content_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
109 bool isChunkedTransfer_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
110 bool hasExpect_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
111 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
112 public: |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
113 CurlHeaders() : |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
114 content_(NULL), |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
115 isChunkedTransfer_(false), |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
116 hasExpect_(false) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
117 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
118 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
119 |
4201 | 120 explicit CurlHeaders(const HttpClient::HttpHeaders& headers) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
121 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
122 for (HttpClient::HttpHeaders::const_iterator |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
123 it = headers.begin(); it != headers.end(); ++it) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
124 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
125 AddHeader(it->first, it->second); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
126 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
127 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
128 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
129 ~CurlHeaders() |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
130 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
131 Clear(); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
132 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
133 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
134 bool IsEmpty() const |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
135 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
136 return content_ == NULL; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
137 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
138 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
139 void Clear() |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
140 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
141 if (content_ != NULL) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
142 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
143 curl_slist_free_all(content_); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
144 content_ = NULL; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
145 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
146 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
147 isChunkedTransfer_ = false; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
148 hasExpect_ = false; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
149 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
150 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
151 void AddHeader(const std::string& key, |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
152 const std::string& value) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
153 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
154 if (boost::iequals(key, "Expect")) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
155 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
156 hasExpect_ = true; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
157 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
158 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
159 if (boost::iequals(key, "Transfer-Encoding") && |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
160 value == "chunked") |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
161 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
162 isChunkedTransfer_ = true; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
163 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
164 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
165 std::string item = key + ": " + value; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
166 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
167 struct curl_slist *tmp = curl_slist_append(content_, item.c_str()); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
168 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
169 if (tmp == NULL) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
170 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
171 throw OrthancException(ErrorCode_NotEnoughMemory); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
172 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
173 else |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
174 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
175 content_ = tmp; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
176 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
177 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
178 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
179 void Assign(CURL* curl) const |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
180 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
181 CheckCode(curl_easy_setopt(curl, CURLOPT_HTTPHEADER, content_)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
182 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
183 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
184 bool HasExpect() const |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
185 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
186 return hasExpect_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
187 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
188 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
189 bool IsChunkedTransfer() const |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
190 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
191 return isChunkedTransfer_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
192 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
193 }; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
194 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
195 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
196 class HttpClient::CurlRequestBody : public boost::noncopyable |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
197 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
198 private: |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
199 HttpClient::IRequestBody* body_; |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
200 std::string pending_; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
201 size_t pendingPos_; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
202 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
203 size_t CallbackInternal(char* curlBuffer, |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
204 size_t curlBufferSize) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
205 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
206 if (body_ == NULL) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
207 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
208 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
209 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
210 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
211 if (curlBufferSize == 0) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
212 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
213 throw OrthancException(ErrorCode_InternalError); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
214 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
215 |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
216 if (pendingPos_ + curlBufferSize <= pending_.size()) |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
217 { |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
218 assert(sizeof(char) == 1); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
219 memcpy(curlBuffer, &pending_[pendingPos_], curlBufferSize); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
220 pendingPos_ += curlBufferSize; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
221 return curlBufferSize; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
222 } |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
223 else |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
224 { |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
225 ChunkedBuffer buffer; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
226 buffer.SetPendingBufferSize(curlBufferSize); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
227 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
228 if (pendingPos_ < pending_.size()) |
3590
d5740d3b1d67
fix for issue 156: Chunked Dicom-web transfer uses 100% CPU
Alain Mazy <alain@mazy.be>
parents:
3516
diff
changeset
|
229 { |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
230 buffer.AddChunk(&pending_[pendingPos_], pending_.size() - pendingPos_); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
231 } |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
232 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
233 // Read chunks from the body stream so as to fill the target buffer |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
234 std::string chunk; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
235 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
236 while (buffer.GetNumBytes() < curlBufferSize && |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
237 body_->ReadNextChunk(chunk)) |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
238 { |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
239 buffer.AddChunk(chunk); |
3590
d5740d3b1d67
fix for issue 156: Chunked Dicom-web transfer uses 100% CPU
Alain Mazy <alain@mazy.be>
parents:
3516
diff
changeset
|
240 } |
d5740d3b1d67
fix for issue 156: Chunked Dicom-web transfer uses 100% CPU
Alain Mazy <alain@mazy.be>
parents:
3516
diff
changeset
|
241 |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
242 buffer.Flatten(pending_); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
243 pendingPos_ = std::min(pending_.size(), curlBufferSize); |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
244 |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
245 if (pendingPos_ != 0) |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
246 { |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
247 memcpy(curlBuffer, pending_.c_str(), pendingPos_); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
248 } |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
249 |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
250 return pendingPos_; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
251 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
252 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
253 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
254 public: |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
255 CurlRequestBody() : |
3590
d5740d3b1d67
fix for issue 156: Chunked Dicom-web transfer uses 100% CPU
Alain Mazy <alain@mazy.be>
parents:
3516
diff
changeset
|
256 body_(NULL), |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
257 pendingPos_(0) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
258 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
259 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
260 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
261 void SetBody(HttpClient::IRequestBody& body) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
262 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
263 body_ = &body; |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
264 pending_.clear(); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
265 pendingPos_ = 0; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
266 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
267 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
268 void Clear() |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
269 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
270 body_ = NULL; |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
271 pending_.clear(); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
272 pendingPos_ = 0; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
273 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
274 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
275 bool IsValid() const |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
276 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
277 return body_ != NULL; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
278 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
279 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
280 static size_t Callback(char *buffer, size_t size, size_t nitems, void *userdata) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
281 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
282 try |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
283 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
284 assert(userdata != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
285 return reinterpret_cast<HttpClient::CurlRequestBody*>(userdata)-> |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
286 CallbackInternal(buffer, size * nitems); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
287 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
288 catch (OrthancException& e) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
289 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
290 LOG(ERROR) << "Exception while streaming HTTP body: " << e.What(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
291 return CURL_READFUNC_ABORT; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
292 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
293 catch (...) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
294 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
295 LOG(ERROR) << "Native exception while streaming HTTP body"; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
296 return CURL_READFUNC_ABORT; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
297 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
298 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
299 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
300 |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
301 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
302 class HttpClient::CurlAnswer : public boost::noncopyable |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
303 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
304 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
305 HttpClient::IAnswer& answer_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
306 bool headersLowerCase_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
307 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
308 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
309 CurlAnswer(HttpClient::IAnswer& answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
310 bool headersLowerCase) : |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
311 answer_(answer), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
312 headersLowerCase_(headersLowerCase) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
313 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
314 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
315 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
316 static size_t HeaderCallback(void *buffer, size_t size, size_t nmemb, void *userdata) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
317 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
318 try |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
319 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
320 assert(userdata != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
321 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
322 size_t length = size * nmemb; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
323 if (length == 0) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
324 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
325 return 0; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
326 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
327 else |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
328 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
329 std::string s(reinterpret_cast<const char*>(buffer), length); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
330 std::size_t colon = s.find(':'); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
331 std::size_t eol = s.find("\r\n"); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
332 if (colon != std::string::npos && |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
333 eol != std::string::npos) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
334 { |
4201 | 335 CurlAnswer& that = *(static_cast<CurlAnswer*>(userdata)); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
336 std::string tmp(s.substr(0, colon)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
337 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
338 if (that.headersLowerCase_) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
339 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
340 Toolbox::ToLowerCase(tmp); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
341 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
342 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
343 std::string key = Toolbox::StripSpaces(tmp); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
344 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
345 if (!key.empty()) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
346 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
347 std::string value = Toolbox::StripSpaces(s.substr(colon + 1, eol)); |
4201 | 348 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
349 that.answer_.AddHeader(key, value); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
350 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
351 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
352 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
353 return length; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
354 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
355 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
356 catch (OrthancException& e) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
357 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
358 LOG(ERROR) << "Exception while streaming HTTP body: " << e.What(); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
359 return CURL_READFUNC_ABORT; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
360 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
361 catch (...) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
362 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
363 LOG(ERROR) << "Native exception while streaming HTTP body"; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
364 return CURL_READFUNC_ABORT; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
365 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
366 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
367 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
368 static size_t BodyCallback(void *buffer, size_t size, size_t nmemb, void *userdata) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
369 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
370 try |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
371 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
372 assert(userdata != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
373 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
374 size_t length = size * nmemb; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
375 if (length == 0) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
376 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
377 return 0; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
378 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
379 else |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
380 { |
4201 | 381 CurlAnswer& that = *(static_cast<CurlAnswer*>(userdata)); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
382 that.answer_.AddChunk(buffer, length); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
383 return length; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
384 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
385 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
386 catch (OrthancException& e) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
387 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
388 LOG(ERROR) << "Exception while streaming HTTP body: " << e.What(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
389 return CURL_READFUNC_ABORT; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
390 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
391 catch (...) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
392 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
393 LOG(ERROR) << "Native exception while streaming HTTP body"; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
394 return CURL_READFUNC_ABORT; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
395 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
396 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
397 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
398 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
399 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
400 class HttpClient::DefaultAnswer : public HttpClient::IAnswer |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
401 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
402 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
403 ChunkedBuffer answer_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
404 HttpHeaders* headers_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
405 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
406 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
407 DefaultAnswer() : headers_(NULL) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
408 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
409 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
410 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
411 void SetHeaders(HttpHeaders& headers) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
412 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
413 headers_ = &headers; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
414 headers_->clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
415 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
416 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
417 void FlattenBody(std::string& target) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
418 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
419 answer_.Flatten(target); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
420 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
421 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
422 virtual void AddHeader(const std::string& key, |
4201 | 423 const std::string& value) ORTHANC_OVERRIDE |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
424 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
425 if (headers_ != NULL) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
426 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
427 (*headers_) [key] = value; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
428 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
429 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
430 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
431 virtual void AddChunk(const void* data, |
4201 | 432 size_t size) ORTHANC_OVERRIDE |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
433 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
434 answer_.AddChunk(data, size); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
435 } |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
436 }; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
437 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
438 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
439 class HttpClient::GlobalParameters |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
440 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
441 private: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
442 boost::mutex mutex_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
443 bool httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
444 std::string httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
445 std::string proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
446 long timeout_; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
447 bool verbose_; |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
448 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
449 GlobalParameters() : |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
450 httpsVerifyPeers_(true), |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
451 timeout_(0), |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
452 verbose_(false) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
453 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
454 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
455 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
456 public: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
457 // Singleton pattern |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
458 static GlobalParameters& GetInstance() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
459 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
460 static GlobalParameters parameters; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
461 return parameters; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
462 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
463 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
464 void ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
465 const std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
466 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
467 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
468 httpsVerifyPeers_ = httpsVerifyPeers; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
469 httpsCACertificates_ = httpsCACertificates; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
470 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
471 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
472 void GetSslConfiguration(bool& httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
473 std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
474 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
475 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
476 httpsVerifyPeers = httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
477 httpsCACertificates = httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
478 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
479 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
480 void SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
481 { |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
482 CLOG(INFO, HTTP) << "Setting the default proxy for HTTP client connections: " << proxy; |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
483 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
484 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
485 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
486 proxy_ = proxy; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
487 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
488 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
489 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
490 void GetDefaultProxy(std::string& target) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
491 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
492 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
493 target = proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
494 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
495 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
496 void SetDefaultTimeout(long seconds) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
497 { |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
498 CLOG(INFO, HTTP) << "Setting the default timeout for HTTP client connections: " << seconds << " seconds"; |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
499 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
500 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
501 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
502 timeout_ = seconds; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
503 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
504 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
505 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
506 long GetDefaultTimeout() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
507 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
508 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
509 return timeout_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
510 } |
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
|
511 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
512 #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
|
513 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
|
514 { |
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 boost::mutex::scoped_lock lock(mutex_); |
2025 | 516 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
|
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 |
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 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
|
520 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
|
521 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
|
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 boost::mutex::scoped_lock lock(mutex_); |
2025 | 524 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
|
525 } |
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 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
527 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
528 bool IsDefaultVerbose() const |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
529 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
530 return verbose_; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
531 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
532 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
533 void SetDefaultVerbose(bool verbose) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
534 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
535 verbose_ = verbose; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
536 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
537 }; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
538 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
539 |
0 | 540 struct HttpClient::PImpl |
541 { | |
542 CURL* curl_; | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
543 CurlHeaders defaultPostHeaders_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
544 CurlHeaders defaultChunkedHeaders_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
545 CurlHeaders userHeaders_; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
546 CurlRequestBody requestBody_; |
0 | 547 }; |
548 | |
549 | |
2787
ad2c32082653
Fix OrthancPluginHttpClient() to return the HTTP status on errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2677
diff
changeset
|
550 void HttpClient::ThrowException(HttpStatus status) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
551 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
552 switch (status) |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
553 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
554 case HttpStatus_400_BadRequest: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
555 throw OrthancException(ErrorCode_BadRequest); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
556 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
557 case HttpStatus_401_Unauthorized: |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
558 case HttpStatus_403_Forbidden: |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
559 throw OrthancException(ErrorCode_Unauthorized); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
560 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
561 case HttpStatus_404_NotFound: |
2044 | 562 throw OrthancException(ErrorCode_UnknownResource); |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
563 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
564 default: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
565 throw OrthancException(ErrorCode_NetworkProtocol); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
566 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
567 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
568 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
569 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
570 /*static int CurlDebugCallback(CURL *handle, |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
571 curl_infotype type, |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
572 char *data, |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
573 size_t size, |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
574 void *userptr) |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
575 { |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
576 switch (type) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
577 { |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
578 case CURLINFO_TEXT: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
579 case CURLINFO_HEADER_IN: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
580 case CURLINFO_HEADER_OUT: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
581 case CURLINFO_SSL_DATA_IN: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
582 case CURLINFO_SSL_DATA_OUT: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
583 case CURLINFO_END: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
584 case CURLINFO_DATA_IN: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
585 case CURLINFO_DATA_OUT: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
586 { |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
587 std::string s(data, size); |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
588 CLOG(INFO, INFO) << "libcurl: " << s; |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
589 break; |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
590 } |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
591 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
592 default: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
593 break; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
594 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
595 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
596 return 0; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
597 }*/ |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
598 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
599 |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
600 void HttpClient::Setup() |
0 | 601 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
602 pimpl_->defaultPostHeaders_.AddHeader("Expect", ""); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
603 pimpl_->defaultChunkedHeaders_.AddHeader("Expect", ""); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
604 pimpl_->defaultChunkedHeaders_.AddHeader("Transfer-Encoding", "chunked"); |
0 | 605 |
606 pimpl_->curl_ = curl_easy_init(); | |
607 | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
608 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERFUNCTION, &CurlAnswer::HeaderCallback)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
609 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlAnswer::BodyCallback)); |
0 | 610 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0)); |
611 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1)); | |
612 | |
456 | 613 // This fixes the "longjmp causes uninitialized stack frame" crash |
614 // that happens on modern Linux versions. | |
615 // http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame | |
616 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); | |
617 | |
0 | 618 url_ = ""; |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
619 method_ = HttpMethod_Get; |
3360 | 620 lastStatus_ = HttpStatus_None; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
621 SetVerbose(GlobalParameters::GetInstance().IsDefaultVerbose()); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
622 timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout(); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
623 GlobalParameters::GetInstance().GetDefaultProxy(proxy_); |
2219
262fcab24024
fix for HttpsCACertificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
624 GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_); |
0 | 625 } |
626 | |
627 | |
2020 | 628 HttpClient::HttpClient() : |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
629 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
|
630 verifyPeers_(true), |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
631 pkcs11Enabled_(false), |
2107 | 632 headersToLowerCase_(true), |
633 redirectionFollowed_(true) | |
2020 | 634 { |
635 Setup(); | |
636 } | |
637 | |
638 | |
639 HttpClient::HttpClient(const WebServiceParameters& service, | |
640 const std::string& uri) : | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
641 pimpl_(new PImpl), |
2049 | 642 verifyPeers_(true), |
2107 | 643 headersToLowerCase_(true), |
644 redirectionFollowed_(true) | |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
645 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
646 Setup(); |
2020 | 647 |
648 if (service.GetUsername().size() != 0 && | |
649 service.GetPassword().size() != 0) | |
650 { | |
651 SetCredentials(service.GetUsername().c_str(), | |
652 service.GetPassword().c_str()); | |
653 } | |
654 | |
655 if (!service.GetCertificateFile().empty()) | |
656 { | |
657 SetClientCertificate(service.GetCertificateFile(), | |
658 service.GetCertificateKeyFile(), | |
659 service.GetCertificateKeyPassword()); | |
660 } | |
661 | |
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
|
662 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
|
663 |
2020 | 664 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
|
665 |
2823
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
666 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
|
667 it = service.GetHttpHeaders().begin(); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
668 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
|
669 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
670 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
|
671 } |
4522
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4521
diff
changeset
|
672 |
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4521
diff
changeset
|
673 if (service.HasTimeout()) |
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4521
diff
changeset
|
674 { |
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4521
diff
changeset
|
675 SetTimeout(service.GetTimeout()); |
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4521
diff
changeset
|
676 } |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
677 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
678 |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
679 |
0 | 680 HttpClient::~HttpClient() |
681 { | |
682 curl_easy_cleanup(pimpl_->curl_); | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
683 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
684 |
4297 | 685 void HttpClient::SetUrl(const char *url) |
686 { | |
687 url_ = std::string(url); | |
688 } | |
689 | |
690 void HttpClient::SetUrl(const std::string &url) | |
691 { | |
692 url_ = url; | |
693 } | |
694 | |
695 const std::string &HttpClient::GetUrl() const | |
696 { | |
697 return url_; | |
698 } | |
699 | |
700 void HttpClient::SetMethod(HttpMethod method) | |
701 { | |
702 method_ = method; | |
703 } | |
704 | |
705 HttpMethod HttpClient::GetMethod() const | |
706 { | |
707 return method_; | |
708 } | |
709 | |
710 void HttpClient::SetTimeout(long seconds) | |
711 { | |
712 timeout_ = seconds; | |
713 } | |
714 | |
715 long HttpClient::GetTimeout() const | |
716 { | |
717 return timeout_; | |
718 } | |
719 | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
720 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
721 void HttpClient::SetBody(const std::string& data) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
722 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
723 body_ = data; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
724 pimpl_->requestBody_.Clear(); |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
725 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
726 |
4297 | 727 std::string &HttpClient::GetBody() |
728 { | |
729 return body_; | |
730 } | |
731 | |
732 const std::string &HttpClient::GetBody() const | |
733 { | |
734 return body_; | |
735 } | |
736 | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
737 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
738 void HttpClient::SetBody(IRequestBody& body) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
739 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
740 body_.clear(); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
741 pimpl_->requestBody_.SetBody(body); |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
742 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
743 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
744 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
745 void HttpClient::ClearBody() |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
746 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
747 body_.clear(); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
748 pimpl_->requestBody_.Clear(); |
0 | 749 } |
750 | |
751 | |
752 void HttpClient::SetVerbose(bool isVerbose) | |
753 { | |
754 isVerbose_ = isVerbose; | |
755 | |
756 if (isVerbose_) | |
757 { | |
758 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
|
759 //CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_DEBUGFUNCTION, &CurlDebugCallback)); |
0 | 760 } |
761 else | |
762 { | |
763 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 0)); | |
764 } | |
765 } | |
766 | |
4297 | 767 bool HttpClient::IsVerbose() const |
768 { | |
769 return isVerbose_; | |
770 } | |
771 | |
0 | 772 |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
773 void HttpClient::AddHeader(const std::string& key, |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
774 const std::string& value) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
775 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
776 if (key.empty()) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
777 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
778 throw OrthancException(ErrorCode_ParameterOutOfRange); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
779 } |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
780 else |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
781 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
782 pimpl_->userHeaders_.AddHeader(key, value); |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
783 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
784 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
785 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
786 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
787 void HttpClient::ClearHeaders() |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
788 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
789 pimpl_->userHeaders_.Clear(); |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
790 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
791 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
792 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
793 bool HttpClient::ApplyInternal(CurlAnswer& answer) |
0 | 794 { |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
795 CLOG(INFO, HTTP) << "New HTTP request to: " << url_ << " (timeout: " |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
796 << boost::lexical_cast<std::string>(timeout_ <= 0 ? DEFAULT_HTTP_TIMEOUT : timeout_) << "s)"; |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
797 |
0 | 798 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
799 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADERDATA, &answer)); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
800 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
801 #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
|
802 // 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
|
803 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
804 if (verifyPeers_) |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
805 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
806 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
|
807 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
|
808 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
|
809 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
810 else |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
811 { |
1973
7bd4cb780feb
Option "HttpsVerifyPeers" can be used to connect against self-signed HTTPS certificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
812 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
|
813 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
|
814 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
815 #endif |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
816 |
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
|
817 // 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
|
818 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
|
819 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
|
820 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
821 throw OrthancException(ErrorCode_ParameterOutOfRange, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
822 "Cannot enable both client certificates and PKCS#11 authentication"); |
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
|
823 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
824 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
825 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
|
826 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
827 #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
|
828 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
|
829 { |
2025 | 830 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
|
831 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
|
832 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
|
833 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
834 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
|
835 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
836 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
837 "Cannot use PKCS#11 for a HTTPS request, " |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
838 "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
|
839 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
840 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
841 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
842 "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
|
843 #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
|
844 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
845 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
|
846 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
847 #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
|
848 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
|
849 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERT, clientCertificateFile_.c_str())); |
4195 | 850 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_KEYPASSWD, clientCertificateKeyPassword_.c_str())); |
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
|
851 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
852 // 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
|
853 // 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
|
854 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
|
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 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
|
857 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
|
858 } |
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 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
860 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
861 "This version of Orthanc is compiled without OpenSSL support, " |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
862 "cannot use HTTPS client authentication"); |
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 #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
|
864 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
865 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
866 // Reset the parameters from previous calls to Apply() |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
867 pimpl_->userHeaders_.Assign(pimpl_->curl_); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
868 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
869 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
870 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
871 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, NULL)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
872 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
873 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
|
874 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, NULL)); |
0 | 875 |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
876 if (redirectionFollowed_) |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
877 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
878 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
879 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
880 else |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
881 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
882 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 0L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
883 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
884 |
1186
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
885 // Set timeouts |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
886 if (timeout_ <= 0) |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
887 { |
3428
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
888 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_TIMEOUT, DEFAULT_HTTP_TIMEOUT)); |
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
889 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CONNECTTIMEOUT, DEFAULT_HTTP_TIMEOUT)); |
1186
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
890 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
891 else |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
892 { |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
893 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
|
894 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
|
895 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
896 |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
897 if (credentials_.size() != 0) |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
898 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
899 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
|
900 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
901 |
1273
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
902 if (proxy_.size() != 0) |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
903 { |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
904 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
|
905 } |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
906 |
0 | 907 switch (method_) |
908 { | |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
909 case HttpMethod_Get: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
910 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
911 break; |
0 | 912 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
913 case HttpMethod_Post: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
914 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
|
915 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
916 break; |
0 | 917 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
918 case HttpMethod_Delete: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
919 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
920 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
921 break; |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
922 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
923 case HttpMethod_Put: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
924 // http://stackoverflow.com/a/7570281/881731: Don't use |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
925 // CURLOPT_PUT if there is a body |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
926 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
927 // CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
928 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
929 curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "PUT"); /* !!! */ |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
930 break; |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
931 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
932 default: |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
933 throw OrthancException(ErrorCode_InternalError); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
934 } |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
935 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
936 if (method_ == HttpMethod_Post || |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
937 method_ == HttpMethod_Put) |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
938 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
939 if (!pimpl_->userHeaders_.IsEmpty() && |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
940 !pimpl_->userHeaders_.HasExpect()) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
941 { |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
942 CLOG(INFO, HTTP) << "For performance, the HTTP header \"Expect\" should be set to empty string in POST/PUT requests"; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
943 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
944 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
945 if (pimpl_->requestBody_.IsValid()) |
0 | 946 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
947 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_READFUNCTION, CurlRequestBody::Callback)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
948 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_READDATA, &pimpl_->requestBody_)); |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
949 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
950 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, -1L)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
951 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
952 if (pimpl_->userHeaders_.IsEmpty()) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
953 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
954 pimpl_->defaultChunkedHeaders_.Assign(pimpl_->curl_); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
955 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
956 else if (!pimpl_->userHeaders_.IsChunkedTransfer()) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
957 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
958 LOG(WARNING) << "The HTTP header \"Transfer-Encoding\" must be set to \"chunked\" " |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
959 << "if streaming a chunked body in POST/PUT requests"; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
960 } |
0 | 961 } |
962 else | |
963 { | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
964 // Disable possible previous stream transfers |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
965 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_READFUNCTION, NULL)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
966 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_UPLOAD, 0)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
967 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
968 if (pimpl_->userHeaders_.IsChunkedTransfer()) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
969 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
970 LOG(WARNING) << "The HTTP header \"Transfer-Encoding\" must only be set " |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
971 << "if streaming a chunked body in POST/PUT requests"; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
972 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
973 |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
974 if (pimpl_->userHeaders_.IsEmpty()) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
975 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
976 pimpl_->defaultPostHeaders_.Assign(pimpl_->curl_); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
977 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
978 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
979 if (body_.size() > 0) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
980 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
981 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, body_.c_str())); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
982 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, body_.size())); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
983 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
984 else |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
985 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
986 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
987 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
988 } |
0 | 989 } |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
990 } |
0 | 991 |
992 | |
993 // Do the actual request | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
994 CURLcode code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
995 long status = 0; |
0 | 996 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
997 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &answer)); |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
998 |
3516
96780208dbd7
reporting timings in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3428
diff
changeset
|
999 const boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time(); |
96780208dbd7
reporting timings in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3428
diff
changeset
|
1000 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1001 if (boost::starts_with(url_, "https://")) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1002 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1003 code = OrthancHttpClientPerformSSL(pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1004 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1005 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1006 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1007 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1008 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1009 |
3516
96780208dbd7
reporting timings in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3428
diff
changeset
|
1010 const boost::posix_time::ptime end = boost::posix_time::microsec_clock::universal_time(); |
96780208dbd7
reporting timings in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3428
diff
changeset
|
1011 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1012 CLOG(INFO, HTTP) << "HTTP status code " << status << " in " |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1013 << ((end - start).total_milliseconds()) << " ms after " |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1014 << EnumerationToString(method_) << " request on: " << url_; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1015 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1016 if (isVerbose_) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1017 { |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1018 CLOG(INFO, HTTP) << "cURL status code: " << code; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1019 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1020 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1021 CheckCode(code); |
0 | 1022 |
1023 if (status == 0) | |
1024 { | |
1025 // 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
|
1026 lastStatus_ = HttpStatus_500_InternalServerError; |
0 | 1027 } |
1028 else | |
1029 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
1030 lastStatus_ = static_cast<HttpStatus>(status); |
0 | 1031 } |
1032 | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1033 if (status >= 200 && status < 300) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1034 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1035 return true; // Success |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
1036 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
1037 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
1038 { |
3122
df4f977c2f88
trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3114
diff
changeset
|
1039 LOG(ERROR) << "Error in HTTP request, received HTTP status " << status |
df4f977c2f88
trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3114
diff
changeset
|
1040 << " (" << EnumerationToString(lastStatus_) << ")"; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1041 return false; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1042 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1043 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1044 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1045 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1046 bool HttpClient::ApplyInternal(std::string& answerBody, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1047 HttpHeaders* answerHeaders) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1048 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1049 answerBody.clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1050 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1051 DefaultAnswer answer; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1052 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1053 if (answerHeaders != NULL) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1054 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1055 answer.SetHeaders(*answerHeaders); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1056 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1057 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1058 CurlAnswer wrapper(answer, headersToLowerCase_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1059 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1060 if (ApplyInternal(wrapper)) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1061 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1062 answer.FlattenBody(answerBody); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1063 return true; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1064 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1065 else |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1066 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1067 return false; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1068 } |
0 | 1069 } |
1070 | |
1071 | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1072 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
|
1073 HttpClient::HttpHeaders* answerHeaders) |
0 | 1074 { |
1075 std::string s; | |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
1076 if (ApplyInternal(s, answerHeaders)) |
0 | 1077 { |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
1078 return Toolbox::ReadJson(answerBody, s); |
0 | 1079 } |
1080 else | |
1081 { | |
1082 return false; | |
1083 } | |
1084 } | |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
1085 |
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
1086 |
468
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
1087 void HttpClient::SetCredentials(const char* username, |
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
1088 const char* password) |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
1089 { |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
1090 credentials_ = std::string(username) + ":" + std::string(password); |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
1091 } |
457 | 1092 |
4297 | 1093 void HttpClient::SetProxy(const std::string &proxy) |
1094 { | |
1095 proxy_ = proxy; | |
1096 } | |
1097 | |
1098 void HttpClient::SetHttpsVerifyPeers(bool verify) | |
1099 { | |
1100 verifyPeers_ = verify; | |
1101 } | |
1102 | |
1103 bool HttpClient::IsHttpsVerifyPeers() const | |
1104 { | |
1105 return verifyPeers_; | |
1106 } | |
1107 | |
1108 void HttpClient::SetHttpsCACertificates(const std::string &certificates) | |
1109 { | |
1110 caCertificates_ = certificates; | |
1111 } | |
1112 | |
1113 const std::string &HttpClient::GetHttpsCACertificates() const | |
1114 { | |
1115 return caCertificates_; | |
1116 } | |
1117 | |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1118 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1119 void HttpClient::ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1120 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
|
1121 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
1122 #if ORTHANC_ENABLE_SSL == 1 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1123 if (httpsVerifyPeers) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1124 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1125 if (httpsVerifyCertificates.empty()) |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1126 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1127 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
|
1128 << "set \"HttpsCACertificates\" if you need to do HTTPS requests"; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1129 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1130 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1131 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1132 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
|
1133 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1134 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1135 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1136 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1137 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
|
1138 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1139 #endif |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1140 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1141 GlobalParameters::GetInstance().ConfigureSsl(httpsVerifyPeers, httpsVerifyCertificates); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1142 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1143 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1144 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1145 void HttpClient::GlobalInitialize() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1146 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
1147 #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
|
1148 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
|
1149 #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
|
1150 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
|
1151 #endif |
457 | 1152 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1153 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1154 |
457 | 1155 void HttpClient::GlobalFinalize() |
1156 { | |
1157 curl_global_cleanup(); | |
2025 | 1158 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
1159 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 1160 Pkcs11::Finalize(); |
1161 #endif | |
457 | 1162 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1163 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
1164 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1165 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
|
1166 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1167 GlobalParameters::GetInstance().SetDefaultVerbose(verbose); |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1168 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1169 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1170 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1171 void HttpClient::SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1172 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1173 GlobalParameters::GetInstance().SetDefaultProxy(proxy); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1174 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1175 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1176 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
1177 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
|
1178 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1179 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
|
1180 } |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1181 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1182 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1183 bool HttpClient::Apply(IAnswer& answer) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1184 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1185 CurlAnswer wrapper(answer, headersToLowerCase_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1186 return ApplyInternal(wrapper); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1187 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1188 |
4297 | 1189 bool HttpClient::Apply(std::string &answerBody) |
1190 { | |
1191 return ApplyInternal(answerBody, NULL); | |
1192 } | |
1193 | |
1194 bool HttpClient::Apply(Json::Value &answerBody) | |
1195 { | |
1196 return ApplyInternal(answerBody, NULL); | |
1197 } | |
1198 | |
1199 bool HttpClient::Apply(std::string &answerBody, | |
1200 HttpClient::HttpHeaders &answerHeaders) | |
1201 { | |
1202 return ApplyInternal(answerBody, &answerHeaders); | |
1203 } | |
1204 | |
1205 bool HttpClient::Apply(Json::Value &answerBody, | |
1206 HttpClient::HttpHeaders &answerHeaders) | |
1207 { | |
1208 return ApplyInternal(answerBody, &answerHeaders); | |
1209 } | |
1210 | |
1211 HttpStatus HttpClient::GetLastStatus() const | |
1212 { | |
1213 return lastStatus_; | |
1214 } | |
1215 | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1216 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1217 void HttpClient::ApplyAndThrowException(IAnswer& answer) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1218 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1219 CurlAnswer wrapper(answer, headersToLowerCase_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1220 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1221 if (!ApplyInternal(wrapper)) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1222 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1223 ThrowException(GetLastStatus()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1224 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1225 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1226 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1227 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1228 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
|
1229 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1230 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1231 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1232 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1233 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1234 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1235 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1236 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1237 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
|
1238 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1239 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1240 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1241 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1242 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1243 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1244 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1245 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1246 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
|
1247 HttpHeaders& answerHeaders) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1248 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1249 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1250 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1251 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1252 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1253 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1254 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1255 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1256 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
|
1257 HttpHeaders& answerHeaders) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1258 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1259 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1260 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1261 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1262 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1263 } |
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
|
1264 |
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
|
1265 |
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
|
1266 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
|
1267 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
|
1268 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
|
1269 { |
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
|
1270 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
|
1271 { |
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
|
1272 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
|
1273 } |
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
|
1274 |
2140 | 1275 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
|
1276 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1277 throw OrthancException(ErrorCode_InexistentFile, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1278 "Cannot open certificate file: " + 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
|
1279 } |
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
|
1280 |
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
|
1281 if (!certificateKeyFile.empty() && |
2140 | 1282 !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
|
1283 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1284 throw OrthancException(ErrorCode_InexistentFile, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1285 "Cannot open key file: " + 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
|
1286 } |
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
|
1287 |
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
|
1288 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
|
1289 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
|
1290 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
|
1291 } |
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
|
1292 |
4297 | 1293 void HttpClient::SetPkcs11Enabled(bool enabled) |
1294 { | |
1295 pkcs11Enabled_ = enabled; | |
1296 } | |
1297 | |
1298 bool HttpClient::IsPkcs11Enabled() const | |
1299 { | |
1300 return pkcs11Enabled_; | |
1301 } | |
1302 | |
1303 const std::string &HttpClient::GetClientCertificateFile() const | |
1304 { | |
1305 return clientCertificateFile_; | |
1306 } | |
1307 | |
1308 const std::string &HttpClient::GetClientCertificateKeyFile() const | |
1309 { | |
1310 return clientCertificateKeyFile_; | |
1311 } | |
1312 | |
1313 const std::string &HttpClient::GetClientCertificateKeyPassword() const | |
1314 { | |
1315 return clientCertificateKeyPassword_; | |
1316 } | |
1317 | |
1318 void HttpClient::SetConvertHeadersToLowerCase(bool lowerCase) | |
1319 { | |
1320 headersToLowerCase_ = lowerCase; | |
1321 } | |
1322 | |
1323 bool HttpClient::IsConvertHeadersToLowerCase() const | |
1324 { | |
1325 return headersToLowerCase_; | |
1326 } | |
1327 | |
1328 void HttpClient::SetRedirectionFollowed(bool follow) | |
1329 { | |
1330 redirectionFollowed_ = follow; | |
1331 } | |
1332 | |
1333 bool HttpClient::IsRedirectionFollowed() const | |
1334 { | |
1335 return redirectionFollowed_; | |
1336 } | |
1337 | |
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
|
1338 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
1339 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
|
1340 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
|
1341 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
|
1342 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
1343 #if ORTHANC_ENABLE_PKCS11 == 1 |
4521
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1344 CLOG(INFO, HTTP) << "Initializing PKCS#11 using " << module |
60e4f94ec30f
using CLOG(INFO, HTTP) in HttpClient instead of LOG(INFO)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1345 << (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
|
1346 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
|
1347 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1348 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1349 "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
|
1350 #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
|
1351 } |
0 | 1352 } |