Mercurial > hg > orthanc
annotate Core/HttpClient.cpp @ 3782:142e93179db9 Tomas-Zubiri/replaced-broken-url-with-url-from-waybac-1573762425576
closing pull request
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Mar 2020 09:36:34 +0100 |
parents | 96780208dbd7 |
children | d5740d3b1d67 |
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 |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
10 * License, or (at your option) any later version. |
0 | 11 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
13 * program give permission to link the code of its release with the |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
22 * in the program, then also delete it here. |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
23 * |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
27 * General Public License for more details. |
0 | 28 * |
493
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
ff34c51cd3dd
fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
477
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 31 **/ |
32 | |
33 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
34 #include "PrecompiledHeaders.h" |
0 | 35 #include "HttpClient.h" |
36 | |
1404 | 37 #include "Toolbox.h" |
38 #include "OrthancException.h" | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
39 #include "Logging.h" |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
40 #include "ChunkedBuffer.h" |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
41 #include "SystemToolbox.h" |
475
72cca077abf8
removal of HttpException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
473
diff
changeset
|
42 |
0 | 43 #include <string.h> |
44 #include <curl/curl.h> | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
45 #include <boost/algorithm/string/predicate.hpp> |
1989 | 46 #include <boost/thread/mutex.hpp> |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
47 |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
48 |
3428
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
49 // 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
|
50 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
|
51 |
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
52 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
53 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 54 # 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
|
55 #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
|
56 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
57 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
58 extern "C" |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
59 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
60 static CURLcode GetHttpStatus(CURLcode code, CURL* curl, long* status) |
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 if (code == CURLE_OK) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
63 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
64 code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
65 return code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
66 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
67 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
68 { |
3122
df4f977c2f88
trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3114
diff
changeset
|
69 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
|
70 << " in libcurl: " << curl_easy_strerror(code); |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
71 *status = 0; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
72 return code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
73 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
74 } |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
75 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
76 |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
77 // 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
|
78 // problem in valgrind. Inlining is prevented. |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
79 #if defined(__GNUC__) || defined(__clang__) |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
80 __attribute__((noinline)) |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
81 #endif |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
82 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
|
83 { |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
84 #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
|
85 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
|
86 #else |
3379
974e12006b7d
Removed extern "C" qualifier around function that is internally linked
Benjamin Golinvaux <bgo@osimis.io>
parents:
3360
diff
changeset
|
87 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
|
88 "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
|
89 "cannot make HTTPS request"); |
2473
0f463989f7e3
warning if no SSL support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
90 #endif |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
91 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
92 |
0 | 93 |
94 | |
60
77aec9be0a51
renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
57
diff
changeset
|
95 namespace Orthanc |
0 | 96 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
97 static CURLcode CheckCode(CURLcode 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 if (code == CURLE_NOT_BUILT_IN) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
100 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
101 throw OrthancException(ErrorCode_InternalError, |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
102 "Your libcurl does not contain a required feature, " |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
103 "please recompile Orthanc with -DUSE_SYSTEM_CURL=OFF"); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
104 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
105 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
106 if (code != CURLE_OK) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
107 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
108 throw OrthancException(ErrorCode_NetworkProtocol, |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
109 "libCURL error: " + std::string(curl_easy_strerror(code))); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
110 } |
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 return code; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
113 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
114 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
115 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
116 // RAII pattern around a "curl_slist" |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
117 class HttpClient::CurlHeaders : public boost::noncopyable |
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 private: |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
120 struct curl_slist *content_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
121 bool isChunkedTransfer_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
122 bool hasExpect_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
123 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
124 public: |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
125 CurlHeaders() : |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
126 content_(NULL), |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
127 isChunkedTransfer_(false), |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
128 hasExpect_(false) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
129 { |
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 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
132 CurlHeaders(const HttpClient::HttpHeaders& headers) |
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 for (HttpClient::HttpHeaders::const_iterator |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
135 it = headers.begin(); it != headers.end(); ++it) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
136 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
137 AddHeader(it->first, it->second); |
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 } |
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 ~CurlHeaders() |
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 Clear(); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
144 } |
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 bool IsEmpty() const |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
147 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
148 return content_ == NULL; |
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 Clear() |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
152 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
153 if (content_ != NULL) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
154 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
155 curl_slist_free_all(content_); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
156 content_ = NULL; |
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 isChunkedTransfer_ = false; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
160 hasExpect_ = false; |
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 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
163 void AddHeader(const std::string& key, |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
164 const std::string& value) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
165 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
166 if (boost::iequals(key, "Expect")) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
167 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
168 hasExpect_ = true; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
169 } |
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 if (boost::iequals(key, "Transfer-Encoding") && |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
172 value == "chunked") |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
173 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
174 isChunkedTransfer_ = true; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
175 } |
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 std::string item = key + ": " + value; |
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 struct curl_slist *tmp = curl_slist_append(content_, item.c_str()); |
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 if (tmp == NULL) |
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 throw OrthancException(ErrorCode_NotEnoughMemory); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
184 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
185 else |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
186 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
187 content_ = tmp; |
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 } |
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 void Assign(CURL* curl) const |
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 CheckCode(curl_easy_setopt(curl, CURLOPT_HTTPHEADER, content_)); |
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 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
196 bool HasExpect() const |
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 return hasExpect_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
199 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
200 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
201 bool IsChunkedTransfer() const |
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 return isChunkedTransfer_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
204 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
205 }; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
206 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
207 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
208 class HttpClient::CurlRequestBody : public boost::noncopyable |
3386
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 private: |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
211 HttpClient::IRequestBody* body_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
212 std::string buffer_; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
213 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
214 size_t CallbackInternal(char* curlBuffer, |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
215 size_t curlBufferSize) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
216 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
217 if (body_ == NULL) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
218 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
219 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
220 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
221 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
222 if (curlBufferSize == 0) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
223 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
224 throw OrthancException(ErrorCode_InternalError); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
225 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
226 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
227 // Read chunks from the body stream so as to fill the target buffer |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
228 std::string chunk; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
229 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
230 while (buffer_.size() < curlBufferSize && |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
231 body_->ReadNextChunk(chunk)) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
232 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
233 buffer_ += chunk; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
234 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
235 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
236 size_t s = std::min(buffer_.size(), curlBufferSize); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
237 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
238 if (s != 0) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
239 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
240 memcpy(curlBuffer, buffer_.c_str(), s); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
241 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
242 // Remove the bytes that were actually sent from the buffer |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
243 buffer_.erase(0, s); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
244 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
245 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
246 return s; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
247 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
248 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
249 public: |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
250 CurlRequestBody() : |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
251 body_(NULL) |
3386
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 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
255 void SetBody(HttpClient::IRequestBody& body) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
256 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
257 body_ = &body; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
258 buffer_.clear(); |
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 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
261 void Clear() |
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_ = NULL; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
264 buffer_.clear(); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
265 } |
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 bool IsValid() const |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
268 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
269 return body_ != NULL; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
270 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
271 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
272 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
|
273 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
274 try |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
275 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
276 assert(userdata != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
277 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
|
278 CallbackInternal(buffer, size * nitems); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
279 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
280 catch (OrthancException& e) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
281 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
282 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
|
283 return CURL_READFUNC_ABORT; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
284 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
285 catch (...) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
286 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
287 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
|
288 return CURL_READFUNC_ABORT; |
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 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
291 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
292 |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
293 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
294 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
|
295 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
296 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
297 HttpClient::IAnswer& answer_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
298 bool headersLowerCase_; |
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 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
301 CurlAnswer(HttpClient::IAnswer& answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
302 bool headersLowerCase) : |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
303 answer_(answer), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
304 headersLowerCase_(headersLowerCase) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
305 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
306 } |
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 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
|
309 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
310 try |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
311 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
312 assert(userdata != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
313 CurlAnswer& that = *(static_cast<CurlAnswer*>(userdata)); |
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 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
|
316 if (length == 0) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
317 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
318 return 0; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
319 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
320 else |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
321 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 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
|
326 eol != std::string::npos) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
327 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
328 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
|
329 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
330 if (that.headersLowerCase_) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
331 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
332 Toolbox::ToLowerCase(tmp); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
333 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
334 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
335 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
|
336 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
337 if (!key.empty()) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
338 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
339 std::string value = Toolbox::StripSpaces(s.substr(colon + 1, eol)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
340 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
|
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 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
344 return length; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
345 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
346 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
347 catch (OrthancException& e) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
348 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
349 LOG(ERROR) << "Exception while streaming HTTP body: " << e.What(); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
350 return CURL_READFUNC_ABORT; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
351 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
352 catch (...) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
353 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
354 LOG(ERROR) << "Native exception while streaming HTTP body"; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
355 return CURL_READFUNC_ABORT; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
356 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
357 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
358 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
359 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
|
360 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
361 try |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
362 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
363 assert(userdata != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
364 CurlAnswer& that = *(static_cast<CurlAnswer*>(userdata)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
365 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
366 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
|
367 if (length == 0) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
368 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
369 return 0; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
370 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
371 else |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
372 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
373 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
|
374 return length; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
375 } |
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 catch (OrthancException& e) |
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 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
|
380 return CURL_READFUNC_ABORT; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
381 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
382 catch (...) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
383 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
384 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
|
385 return CURL_READFUNC_ABORT; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
386 } |
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 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
389 |
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 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
|
392 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
393 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
394 ChunkedBuffer answer_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
395 HttpHeaders* headers_; |
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 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
398 DefaultAnswer() : headers_(NULL) |
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 } |
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 void SetHeaders(HttpHeaders& headers) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
403 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
404 headers_ = &headers; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
405 headers_->clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
406 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
407 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
408 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
|
409 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
410 answer_.Flatten(target); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
411 } |
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 virtual void AddHeader(const std::string& key, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
414 const std::string& value) |
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 if (headers_ != NULL) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
417 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
418 (*headers_) [key] = value; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
419 } |
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 AddChunk(const void* data, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
423 size_t size) |
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 answer_.AddChunk(data, size); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
426 } |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
427 }; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
428 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
429 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
430 class HttpClient::GlobalParameters |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
431 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
432 private: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
433 boost::mutex mutex_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
434 bool httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
435 std::string httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
436 std::string proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
437 long timeout_; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
438 bool verbose_; |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
439 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
440 GlobalParameters() : |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
441 httpsVerifyPeers_(true), |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
442 timeout_(0), |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
443 verbose_(false) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
444 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
445 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
446 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
447 public: |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
448 // Singleton pattern |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
449 static GlobalParameters& GetInstance() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
450 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
451 static GlobalParameters parameters; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
452 return parameters; |
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 void ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
456 const std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
457 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
458 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
459 httpsVerifyPeers_ = httpsVerifyPeers; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
460 httpsCACertificates_ = httpsCACertificates; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
461 } |
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 void GetSslConfiguration(bool& httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
464 std::string& httpsCACertificates) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
465 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
466 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
467 httpsVerifyPeers = httpsVerifyPeers_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
468 httpsCACertificates = httpsCACertificates_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
469 } |
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 void SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
472 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
473 LOG(INFO) << "Setting the default proxy for HTTP client connections: " << proxy; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
474 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
475 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
476 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
477 proxy_ = proxy; |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
481 void GetDefaultProxy(std::string& target) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
482 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
483 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
484 target = proxy_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
485 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
486 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
487 void SetDefaultTimeout(long seconds) |
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 LOG(INFO) << "Setting the default timeout for HTTP client connections: " << seconds << " seconds"; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
490 |
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 timeout_ = seconds; |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
497 long GetDefaultTimeout() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
498 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
499 boost::mutex::scoped_lock lock(mutex_); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
500 return timeout_; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
501 } |
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
|
502 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
503 #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
|
504 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
|
505 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
506 boost::mutex::scoped_lock lock(mutex_); |
2025 | 507 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
|
508 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
509 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
510 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
|
511 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
|
512 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
|
513 { |
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 boost::mutex::scoped_lock lock(mutex_); |
2025 | 515 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
|
516 } |
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 #endif |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
518 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
519 bool IsDefaultVerbose() const |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
520 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
521 return verbose_; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
522 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
523 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
524 void SetDefaultVerbose(bool verbose) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
525 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
526 verbose_ = verbose; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
527 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
528 }; |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
529 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
530 |
0 | 531 struct HttpClient::PImpl |
532 { | |
533 CURL* curl_; | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
534 CurlHeaders defaultPostHeaders_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
535 CurlHeaders defaultChunkedHeaders_; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
536 CurlHeaders userHeaders_; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
537 CurlRequestBody requestBody_; |
0 | 538 }; |
539 | |
540 | |
2787
ad2c32082653
Fix OrthancPluginHttpClient() to return the HTTP status on errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2677
diff
changeset
|
541 void HttpClient::ThrowException(HttpStatus status) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
542 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
543 switch (status) |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
544 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
545 case HttpStatus_400_BadRequest: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
546 throw OrthancException(ErrorCode_BadRequest); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
547 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
548 case HttpStatus_401_Unauthorized: |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
549 case HttpStatus_403_Forbidden: |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
550 throw OrthancException(ErrorCode_Unauthorized); |
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 case HttpStatus_404_NotFound: |
2044 | 553 throw OrthancException(ErrorCode_UnknownResource); |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
554 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
555 default: |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
556 throw OrthancException(ErrorCode_NetworkProtocol); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
557 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
558 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
559 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
560 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
561 /*static int CurlDebugCallback(CURL *handle, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
562 curl_infotype type, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
563 char *data, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
564 size_t size, |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
565 void *userptr) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
566 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
567 switch (type) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
568 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
569 case CURLINFO_TEXT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
570 case CURLINFO_HEADER_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
571 case CURLINFO_HEADER_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
572 case CURLINFO_SSL_DATA_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
573 case CURLINFO_SSL_DATA_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
574 case CURLINFO_END: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
575 case CURLINFO_DATA_IN: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
576 case CURLINFO_DATA_OUT: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
577 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
578 std::string s(data, size); |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
579 LOG(INFO) << "libcurl: " << s; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
580 break; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
581 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
582 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
583 default: |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
584 break; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
585 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
586 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
587 return 0; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
588 }*/ |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
589 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
590 |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
591 void HttpClient::Setup() |
0 | 592 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
593 pimpl_->defaultPostHeaders_.AddHeader("Expect", ""); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
594 pimpl_->defaultChunkedHeaders_.AddHeader("Expect", ""); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
595 pimpl_->defaultChunkedHeaders_.AddHeader("Transfer-Encoding", "chunked"); |
0 | 596 |
597 pimpl_->curl_ = curl_easy_init(); | |
598 | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
599 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
|
600 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlAnswer::BodyCallback)); |
0 | 601 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0)); |
602 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1)); | |
603 | |
456 | 604 // This fixes the "longjmp causes uninitialized stack frame" crash |
605 // that happens on modern Linux versions. | |
606 // http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame | |
607 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); | |
608 | |
0 | 609 url_ = ""; |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
610 method_ = HttpMethod_Get; |
3360 | 611 lastStatus_ = HttpStatus_None; |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
612 SetVerbose(GlobalParameters::GetInstance().IsDefaultVerbose()); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
613 timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout(); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
614 GlobalParameters::GetInstance().GetDefaultProxy(proxy_); |
2219
262fcab24024
fix for HttpsCACertificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
615 GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_); |
0 | 616 } |
617 | |
618 | |
2020 | 619 HttpClient::HttpClient() : |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
620 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
|
621 verifyPeers_(true), |
2045
21a8ca9ad928
HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2044
diff
changeset
|
622 pkcs11Enabled_(false), |
2107 | 623 headersToLowerCase_(true), |
624 redirectionFollowed_(true) | |
2020 | 625 { |
626 Setup(); | |
627 } | |
628 | |
629 | |
630 HttpClient::HttpClient(const WebServiceParameters& service, | |
631 const std::string& uri) : | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
632 pimpl_(new PImpl), |
2049 | 633 verifyPeers_(true), |
2107 | 634 headersToLowerCase_(true), |
635 redirectionFollowed_(true) | |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
636 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
637 Setup(); |
2020 | 638 |
639 if (service.GetUsername().size() != 0 && | |
640 service.GetPassword().size() != 0) | |
641 { | |
642 SetCredentials(service.GetUsername().c_str(), | |
643 service.GetPassword().c_str()); | |
644 } | |
645 | |
646 if (!service.GetCertificateFile().empty()) | |
647 { | |
648 SetClientCertificate(service.GetCertificateFile(), | |
649 service.GetCertificateKeyFile(), | |
650 service.GetCertificateKeyPassword()); | |
651 } | |
652 | |
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
|
653 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
|
654 |
2020 | 655 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
|
656 |
2823
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
657 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
|
658 it = service.GetHttpHeaders().begin(); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
659 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
|
660 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2788
diff
changeset
|
661 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
|
662 } |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
663 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
664 |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
665 |
0 | 666 HttpClient::~HttpClient() |
667 { | |
668 curl_easy_cleanup(pimpl_->curl_); | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
669 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
670 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
671 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
672 void HttpClient::SetBody(const std::string& data) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
673 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
674 body_ = data; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
675 pimpl_->requestBody_.Clear(); |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
676 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
677 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
678 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
679 void HttpClient::SetBody(IRequestBody& body) |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
680 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
681 body_.clear(); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
682 pimpl_->requestBody_.SetBody(body); |
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 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
685 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
686 void HttpClient::ClearBody() |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
687 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3386
diff
changeset
|
688 body_.clear(); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
689 pimpl_->requestBody_.Clear(); |
0 | 690 } |
691 | |
692 | |
693 void HttpClient::SetVerbose(bool isVerbose) | |
694 { | |
695 isVerbose_ = isVerbose; | |
696 | |
697 if (isVerbose_) | |
698 { | |
699 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
|
700 //CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_DEBUGFUNCTION, &CurlDebugCallback)); |
0 | 701 } |
702 else | |
703 { | |
704 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_VERBOSE, 0)); | |
705 } | |
706 } | |
707 | |
708 | |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
709 void HttpClient::AddHeader(const std::string& key, |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
710 const std::string& value) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
711 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
712 if (key.empty()) |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
713 { |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
714 throw OrthancException(ErrorCode_ParameterOutOfRange); |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
715 } |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
716 else |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
717 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
718 pimpl_->userHeaders_.AddHeader(key, value); |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
719 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
720 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
721 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
722 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
723 void HttpClient::ClearHeaders() |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
724 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
725 pimpl_->userHeaders_.Clear(); |
1986
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
726 } |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
727 |
99b249867052
HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1973
diff
changeset
|
728 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
729 bool HttpClient::ApplyInternal(CurlAnswer& answer) |
0 | 730 { |
731 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
|
732 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
|
733 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
734 #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
|
735 // 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
|
736 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
737 if (verifyPeers_) |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
738 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
743 else |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
744 { |
1973
7bd4cb780feb
Option "HttpsVerifyPeers" can be used to connect against self-signed HTTPS certificates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
745 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
|
746 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
|
747 } |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
748 #endif |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
749 |
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
|
750 // 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
|
751 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
|
752 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
|
753 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
754 throw OrthancException(ErrorCode_ParameterOutOfRange, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
755 "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
|
756 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
757 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
758 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
|
759 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
760 #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
|
761 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
|
762 { |
2025 | 763 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
|
764 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
|
765 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
|
766 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
767 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
|
768 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
769 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
770 "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
|
771 "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
|
772 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
773 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
774 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
775 "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
|
776 #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
|
777 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
778 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
|
779 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
780 #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
|
781 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
|
782 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSLCERT, clientCertificateFile_.c_str())); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
783 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
784 if (!clientCertificateKeyPassword_.empty()) |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
785 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
786 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_KEYPASSWD, clientCertificateKeyPassword_.c_str())); |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
787 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
788 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
789 // 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
|
790 // 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
|
791 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
|
792 { |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
793 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
|
794 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
|
795 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
796 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
797 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
798 "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
|
799 "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
|
800 #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
|
801 } |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
802 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
803 // Reset the parameters from previous calls to Apply() |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
804 pimpl_->userHeaders_.Assign(pimpl_->curl_); |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
805 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
806 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
807 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 0L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
808 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, NULL)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
809 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
810 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
|
811 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PROXY, NULL)); |
0 | 812 |
2104
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
813 if (redirectionFollowed_) |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
814 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
815 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
816 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
817 else |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
818 { |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
819 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 0L)); |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
820 } |
58a0ee0b4be1
HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2099
diff
changeset
|
821 |
1186
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
822 // Set timeouts |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
823 if (timeout_ <= 0) |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
824 { |
3428
6add197274b1
default value of HttpTimeout is now 60 seconds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3393
diff
changeset
|
825 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
|
826 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
|
827 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
828 else |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
829 { |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
830 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
|
831 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
|
832 } |
b17b6bd59747
timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1052
diff
changeset
|
833 |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
834 if (credentials_.size() != 0) |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
835 { |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
836 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
|
837 } |
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
838 |
1273
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
839 if (proxy_.size() != 0) |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
840 { |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
841 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
|
842 } |
88010d8e12cf
Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1186
diff
changeset
|
843 |
0 | 844 switch (method_) |
845 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
846 case HttpMethod_Get: |
0 | 847 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); |
848 break; | |
849 | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
850 case HttpMethod_Post: |
0 | 851 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
|
852 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
853 break; |
0 | 854 |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
855 case HttpMethod_Delete: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
856 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
857 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
858 break; |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
859 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
860 case HttpMethod_Put: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
861 // http://stackoverflow.com/a/7570281/881731: Don't use |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
862 // CURLOPT_PUT if there is a body |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
863 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
864 // CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
865 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
866 curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "PUT"); /* !!! */ |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
867 break; |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
868 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
869 default: |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
870 throw OrthancException(ErrorCode_InternalError); |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
871 } |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
872 |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
873 if (method_ == HttpMethod_Post || |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
874 method_ == HttpMethod_Put) |
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
875 { |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
876 if (!pimpl_->userHeaders_.IsEmpty() && |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
877 !pimpl_->userHeaders_.HasExpect()) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
878 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
879 LOG(INFO) << "For performance, the HTTP header \"Expect\" should be set to empty string in POST/PUT requests"; |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
880 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
881 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
882 if (pimpl_->requestBody_.IsValid()) |
0 | 883 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
884 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
|
885 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_READDATA, &pimpl_->requestBody_)); |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
886 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
887 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, -1L)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
888 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
889 if (pimpl_->userHeaders_.IsEmpty()) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
890 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
891 pimpl_->defaultChunkedHeaders_.Assign(pimpl_->curl_); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
892 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
893 else if (!pimpl_->userHeaders_.IsChunkedTransfer()) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
894 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
895 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
|
896 << "if streaming a chunked body in POST/PUT requests"; |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
897 } |
0 | 898 } |
899 else | |
900 { | |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
901 // Disable possible previous stream transfers |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
902 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_READFUNCTION, NULL)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
903 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_UPLOAD, 0)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
904 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
905 if (pimpl_->userHeaders_.IsChunkedTransfer()) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
906 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
907 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
|
908 << "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
|
909 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
910 |
3386
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
911 if (pimpl_->userHeaders_.IsEmpty()) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
912 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
913 pimpl_->defaultPostHeaders_.Assign(pimpl_->curl_); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
914 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
915 |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
916 if (body_.size() > 0) |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
917 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
918 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, body_.c_str())); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
919 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, body_.size())); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
920 } |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
921 else |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
922 { |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
923 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDS, NULL)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
924 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); |
af9432e46c07
HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3379
diff
changeset
|
925 } |
0 | 926 } |
1052
cc4ff680e2a0
http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
927 } |
0 | 928 |
929 | |
930 // Do the actual request | |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
931 CURLcode code; |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
932 long status = 0; |
0 | 933 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
934 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
|
935 |
3516
96780208dbd7
reporting timings in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3428
diff
changeset
|
936 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
|
937 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
938 if (boost::starts_with(url_, "https://")) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
939 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
940 code = OrthancHttpClientPerformSSL(pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
941 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
942 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
943 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
944 code = GetHttpStatus(curl_easy_perform(pimpl_->curl_), pimpl_->curl_, &status); |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
945 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
946 |
3516
96780208dbd7
reporting timings in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3428
diff
changeset
|
947 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
|
948 |
96780208dbd7
reporting timings in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3428
diff
changeset
|
949 LOG(INFO) << "HTTP status code " << status << " in " |
96780208dbd7
reporting timings in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3428
diff
changeset
|
950 << ((end - start).total_milliseconds()) << " ms after " |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
951 << EnumerationToString(method_) << " request on: " << url_; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
952 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
953 if (isVerbose_) |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
954 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
955 LOG(INFO) << "cURL status code: " << code; |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
956 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
957 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
958 CheckCode(code); |
0 | 959 |
960 if (status == 0) | |
961 { | |
962 // 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
|
963 lastStatus_ = HttpStatus_500_InternalServerError; |
0 | 964 } |
965 else | |
966 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
469
diff
changeset
|
967 lastStatus_ = static_cast<HttpStatus>(status); |
0 | 968 } |
969 | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
970 if (status >= 200 && status < 300) |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
971 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
972 return true; // Success |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
973 } |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
974 else |
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
975 { |
3122
df4f977c2f88
trying to reproduce isse 32 in C++
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3114
diff
changeset
|
976 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
|
977 << " (" << EnumerationToString(lastStatus_) << ")"; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
978 return false; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
979 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
980 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
981 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
982 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
983 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
|
984 HttpHeaders* answerHeaders) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
985 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
986 answerBody.clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
987 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
988 DefaultAnswer answer; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
989 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
990 if (answerHeaders != NULL) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
991 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
992 answer.SetHeaders(*answerHeaders); |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
993 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
994 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
995 CurlAnswer wrapper(answer, headersToLowerCase_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
996 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
997 if (ApplyInternal(wrapper)) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
998 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
999 answer.FlattenBody(answerBody); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1000 return true; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1001 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1002 else |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1003 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1004 return false; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1005 } |
0 | 1006 } |
1007 | |
1008 | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1009 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
|
1010 HttpClient::HttpHeaders* answerHeaders) |
0 | 1011 { |
1012 std::string s; | |
2040
6ea2e264ca50
retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2025
diff
changeset
|
1013 if (ApplyInternal(s, answerHeaders)) |
0 | 1014 { |
1015 Json::Reader reader; | |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1016 return reader.parse(s, answerBody); |
0 | 1017 } |
1018 else | |
1019 { | |
1020 return false; | |
1021 } | |
1022 } | |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
1023 |
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
1024 |
468
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
1025 void HttpClient::SetCredentials(const char* username, |
456b9d2e9af4
rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
457
diff
changeset
|
1026 const char* password) |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
1027 { |
469
a6fe16a31615
transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
468
diff
changeset
|
1028 credentials_ = std::string(username) + ":" + std::string(password); |
144
aa6c8a942952
http client password
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
60
diff
changeset
|
1029 } |
457 | 1030 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1031 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1032 void HttpClient::ConfigureSsl(bool httpsVerifyPeers, |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1033 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
|
1034 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
1035 #if ORTHANC_ENABLE_SSL == 1 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1036 if (httpsVerifyPeers) |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1037 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1038 if (httpsVerifyCertificates.empty()) |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1039 { |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1040 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
|
1041 << "set \"HttpsCACertificates\" if you need to do HTTPS requests"; |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1042 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1043 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1044 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1045 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
|
1046 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1047 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1048 else |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1049 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1050 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
|
1051 } |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1052 #endif |
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1053 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1054 GlobalParameters::GetInstance().ConfigureSsl(httpsVerifyPeers, httpsVerifyCertificates); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1055 } |
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 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1058 void HttpClient::GlobalInitialize() |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1059 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
1060 #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
|
1061 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
|
1062 #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
|
1063 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
|
1064 #endif |
457 | 1065 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1404
diff
changeset
|
1066 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1067 |
457 | 1068 void HttpClient::GlobalFinalize() |
1069 { | |
1070 curl_global_cleanup(); | |
2025 | 1071 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
1072 #if ORTHANC_ENABLE_PKCS11 == 1 |
2025 | 1073 Pkcs11::Finalize(); |
1074 #endif | |
457 | 1075 } |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1076 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
1077 |
2788
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1078 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
|
1079 { |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1080 GlobalParameters::GetInstance().SetDefaultVerbose(verbose); |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1081 } |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1082 |
959bd8857eb5
New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2787
diff
changeset
|
1083 |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1084 void HttpClient::SetDefaultProxy(const std::string& proxy) |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1085 { |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1086 GlobalParameters::GetInstance().SetDefaultProxy(proxy); |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1087 } |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1088 |
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1089 |
1590
ba0226474e22
New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1534
diff
changeset
|
1090 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
|
1091 { |
1987
ce90d109bb64
new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1986
diff
changeset
|
1092 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
|
1093 } |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1094 |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1095 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1096 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
|
1097 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1098 CurlAnswer wrapper(answer, headersToLowerCase_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1099 return ApplyInternal(wrapper); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1100 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1101 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1102 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1103 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
|
1104 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1105 CurlAnswer wrapper(answer, headersToLowerCase_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1106 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1107 if (!ApplyInternal(wrapper)) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1108 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1109 ThrowException(GetLastStatus()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1110 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1111 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1112 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
1113 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1114 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
|
1115 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1116 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1117 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1118 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1119 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1120 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1121 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1122 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1123 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
|
1124 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1125 if (!Apply(answerBody)) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1126 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1127 ThrowException(GetLastStatus()); |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1128 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1129 } |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1130 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1131 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1132 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
|
1133 HttpHeaders& answerHeaders) |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1134 { |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1135 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1136 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1137 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1138 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1139 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1140 |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1141 |
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1142 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
|
1143 HttpHeaders& answerHeaders) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1144 { |
2041
9f61ca1e3eb3
OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2040
diff
changeset
|
1145 if (!Apply(answerBody, answerHeaders)) |
1606
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1146 { |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1147 ThrowException(GetLastStatus()); |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1148 } |
31f4adefb88f
issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1590
diff
changeset
|
1149 } |
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
|
1150 |
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
|
1151 |
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
|
1152 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
|
1153 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
|
1154 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
|
1155 { |
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
|
1156 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
|
1157 { |
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
|
1158 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
|
1159 } |
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
|
1160 |
2140 | 1161 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
|
1162 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1163 throw OrthancException(ErrorCode_InexistentFile, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1164 "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
|
1165 } |
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
|
1166 |
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
|
1167 if (!certificateKeyFile.empty() && |
2140 | 1168 !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
|
1169 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1170 throw OrthancException(ErrorCode_InexistentFile, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1171 "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
|
1172 } |
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
|
1173 |
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
|
1174 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
|
1175 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
|
1176 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
|
1177 } |
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
|
1178 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
1179 |
fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2020
diff
changeset
|
1180 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
|
1181 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
|
1182 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
|
1183 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2107
diff
changeset
|
1184 #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
|
1185 LOG(INFO) << "Initializing PKCS#11 using " << module |
2024 | 1186 << (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
|
1187 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
|
1188 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1189 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2823
diff
changeset
|
1190 "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
|
1191 #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
|
1192 } |
0 | 1193 } |