annotate OrthancFramework/Sources/HttpClient.h @ 5644:343149762476

fix build with DCMTK <= 3.6.6
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 31 May 2024 18:23:44 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
60
77aec9be0a51 renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1606
diff changeset
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
493
ff34c51cd3dd fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * the License, or (at your option) any later version.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
493
ff34c51cd3dd fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
14 * This program is distributed in the hope that it will be useful, but
ff34c51cd3dd fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
ff34c51cd3dd fix licensing terms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 476
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * Lesser General Public License for more details.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 * <http://www.gnu.org/licenses/>.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #pragma once
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
1404
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
27 #include "Enumerations.h"
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3991
diff changeset
28 #include "OrthancFramework.h"
2020
a0bd8cd55da7 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2019
diff changeset
29 #include "WebServiceParameters.h"
474
a9693dc7089c move tostring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
30
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <string>
3386
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
32 #include <boost/noncopyable.hpp>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <boost/shared_ptr.hpp>
4392
3af1d763763a confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
34 #include <json/value.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
4026
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
36 #if !defined(ORTHANC_ENABLE_CURL)
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
37 # error The macro ORTHANC_ENABLE_CURL must be defined
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
38 #endif
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
39
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
40 #if ORTHANC_ENABLE_CURL != 1
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
41 # error Support for curl is disabled, cannot use this file
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
42 #endif
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
43
2137
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
44 #if !defined(ORTHANC_ENABLE_SSL)
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
45 # error The macro ORTHANC_ENABLE_SSL must be defined
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
46 #endif
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
47
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
48 #if !defined(ORTHANC_ENABLE_PKCS11)
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
49 # error The macro ORTHANC_ENABLE_PKCS11 must be defined
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
50 #endif
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
51
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2104
diff changeset
52
60
77aec9be0a51 renaming of cppclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
53 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
3991
5d2348b39392 turning toolbox namespaces into classes to control visibility in shared libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3990
diff changeset
55 class ORTHANC_PUBLIC HttpClient : public boost::noncopyable
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
2040
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2023
diff changeset
57 public:
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2023
diff changeset
58 typedef std::map<std::string, std::string> HttpHeaders;
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2023
diff changeset
59
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
60 class IRequestBody : public boost::noncopyable
3386
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
61 {
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
62 public:
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
63 virtual ~IRequestBody()
3386
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
64 {
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
65 }
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
66
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
67 virtual bool ReadNextChunk(std::string& chunk) = 0;
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
68 };
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
69
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
70 class IAnswer : public boost::noncopyable
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
71 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
72 public:
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
73 virtual ~IAnswer()
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
74 {
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
75 }
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
76
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
77 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
78 const std::string& value) = 0;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
79
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
80 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
81 size_t size) = 0;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
82 };
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
83
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 private:
3386
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
85 class CurlHeaders;
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
86 class CurlRequestBody;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
87 class CurlAnswer;
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
88 class DefaultAnswer;
1987
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
89 class GlobalParameters;
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
90
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 struct PImpl;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 boost::shared_ptr<PImpl> pimpl_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 std::string url_;
469
a6fe16a31615 transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 468
diff changeset
95 std::string credentials_;
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 469
diff changeset
96 HttpMethod method_;
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 469
diff changeset
97 HttpStatus lastStatus_;
1606
31f4adefb88f issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1590
diff changeset
98 std::string body_; // This only makes sense for POST and PUT requests
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 bool isVerbose_;
1186
b17b6bd59747 timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1052
diff changeset
100 long timeout_;
1273
88010d8e12cf Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1186
diff changeset
101 std::string proxy_;
1534
95b3b0260240 Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1533
diff changeset
102 bool verifyPeers_;
95b3b0260240 Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1533
diff changeset
103 std::string caCertificates_;
2019
9c9332e486ca HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1987
diff changeset
104 std::string clientCertificateFile_;
9c9332e486ca HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1987
diff changeset
105 std::string clientCertificateKeyFile_;
9c9332e486ca HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1987
diff changeset
106 std::string clientCertificateKeyPassword_;
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
107 bool pkcs11Enabled_;
2045
21a8ca9ad928 HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2041
diff changeset
108 bool headersToLowerCase_;
2104
58a0ee0b4be1 HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2099
diff changeset
109 bool redirectionFollowed_;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
4650
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
111 // New in Orthanc 1.9.3 to avoid memcpy()
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
112 bool hasExternalBody_;
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
113 const void* externalBodyData_;
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
114 size_t externalBodySize_;
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
115
469
a6fe16a31615 transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 468
diff changeset
116 void Setup();
a6fe16a31615 transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 468
diff changeset
117
1987
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
118 void operator= (const HttpClient&); // Assignment forbidden
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
119 HttpClient(const HttpClient& base); // Copy forbidden
469
a6fe16a31615 transmitting credentials by copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 468
diff changeset
120
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
121 bool ApplyInternal(CurlAnswer& answer);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
122
2041
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
123 bool ApplyInternal(std::string& answerBody,
2040
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2023
diff changeset
124 HttpHeaders* answerHeaders);
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2023
diff changeset
125
2041
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
126 bool ApplyInternal(Json::Value& answerBody,
2040
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2023
diff changeset
127 HttpHeaders* answerHeaders);
2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2022
diff changeset
128
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 public:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 HttpClient();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
2020
a0bd8cd55da7 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2019
diff changeset
132 HttpClient(const WebServiceParameters& service,
a0bd8cd55da7 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2019
diff changeset
133 const std::string& uri);
a0bd8cd55da7 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2019
diff changeset
134
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 ~HttpClient();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
137 void SetUrl(const char* url);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
139 void SetUrl(const std::string& url);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
141 const std::string& GetUrl() const;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
143 void SetMethod(HttpMethod method);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
145 HttpMethod GetMethod() const;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
147 void SetTimeout(long seconds);
1186
b17b6bd59747 timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1052
diff changeset
148
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
149 long GetTimeout() const;
1186
b17b6bd59747 timeouts for HTTP and DICOM
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1052
diff changeset
150
4650
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
151 void AssignBody(const std::string& data);
1052
cc4ff680e2a0 http requests in lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
152
4650
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
153 void AssignBody(const void* data,
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
154 size_t size);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
156 void SetBody(IRequestBody& body);
3386
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
157
4650
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
158 // New in Orthanc 1.9.3: The "data" buffer must have a lifetime
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
159 // that is longer than the HttpClient object
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
160 void SetExternalBody(const void* data,
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
161 size_t size);
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
162
4657
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4650
diff changeset
163 void SetExternalBody(const std::string& data);
4650
9804d6490872 Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
164
3387
a48d652f1500 new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3386
diff changeset
165 void ClearBody();
3386
af9432e46c07 HttpClient::IBodyStream
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
166
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 void SetVerbose(bool isVerbose);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
169 bool IsVerbose() const;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
1986
99b249867052 HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
171 void AddHeader(const std::string& key,
99b249867052 HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
172 const std::string& value);
99b249867052 HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
173
99b249867052 HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
174 void ClearHeaders();
99b249867052 HTTP headers in HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
175
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
176 bool Apply(IAnswer& answer);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
177
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
178 bool Apply(std::string& answerBody);
2040
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2023
diff changeset
179
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
180 bool Apply(Json::Value& answerBody);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
2041
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
182 bool Apply(std::string& answerBody,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
183 HttpHeaders& answerHeaders);
2040
6ea2e264ca50 retrieval of HTTP headers in answers within HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2023
diff changeset
184
2041
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
185 bool Apply(Json::Value& answerBody,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
186 HttpHeaders& answerHeaders);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
188 HttpStatus GetLastStatus() const;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
468
456b9d2e9af4 rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 457
diff changeset
190 void SetCredentials(const char* username,
456b9d2e9af4 rename methods for clarity
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 457
diff changeset
191 const char* password);
457
997282a61ff8 cleaner names
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 400
diff changeset
192
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
193 void SetProxy(const std::string& proxy);
1273
88010d8e12cf Support of HTTP proxy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1186
diff changeset
194
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
195 void SetHttpsVerifyPeers(bool verify);
1534
95b3b0260240 Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1533
diff changeset
196
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
197 bool IsHttpsVerifyPeers() const;
1534
95b3b0260240 Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1533
diff changeset
198
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
199 void SetHttpsCACertificates(const std::string& certificates);
1534
95b3b0260240 Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1533
diff changeset
200
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
201 const std::string& GetHttpsCACertificates() const;
1534
95b3b0260240 Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1533
diff changeset
202
2019
9c9332e486ca HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1987
diff changeset
203 void 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: 1987
diff changeset
204 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: 1987
diff changeset
205 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: 1987
diff changeset
206
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
207 void SetPkcs11Enabled(bool enabled);
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
208
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
209 bool IsPkcs11Enabled() const;
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
210
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
211 const std::string& GetClientCertificateFile() const;
2019
9c9332e486ca HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1987
diff changeset
212
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
213 const std::string& GetClientCertificateKeyFile() const;
2019
9c9332e486ca HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1987
diff changeset
214
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
215 const std::string& GetClientCertificateKeyPassword() const;
2019
9c9332e486ca HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1987
diff changeset
216
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
217 void SetConvertHeadersToLowerCase(bool lowerCase);
2045
21a8ca9ad928 HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2041
diff changeset
218
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
219 bool IsConvertHeadersToLowerCase() const;
2045
21a8ca9ad928 HttpClient::SetConvertHeadersToLowerCase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2041
diff changeset
220
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
221 void SetRedirectionFollowed(bool follow);
2104
58a0ee0b4be1 HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2099
diff changeset
222
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
223 bool IsRedirectionFollowed() const;
2104
58a0ee0b4be1 HttpClient::SetRedirectionFollowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2099
diff changeset
224
1987
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
225 static void GlobalInitialize();
457
997282a61ff8 cleaner names
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 400
diff changeset
226
997282a61ff8 cleaner names
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 400
diff changeset
227 static void GlobalFinalize();
1590
ba0226474e22 New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1534
diff changeset
228
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
229 static 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
230 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
231 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
232
1987
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
233 static void ConfigureSsl(bool httpsVerifyPeers,
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
234 const std::string& httpsCACertificates);
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
235
2788
959bd8857eb5 New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2787
diff changeset
236 static void SetDefaultVerbose(bool verbose);
959bd8857eb5 New configuration option: "HttpVerbose" to debug outgoing HTTP connections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2787
diff changeset
237
1987
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
238 static void SetDefaultProxy(const std::string& proxy);
ce90d109bb64 new plugin functions: OrthancPluginHttpClient and OrthancPluginGenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1986
diff changeset
239
1590
ba0226474e22 New configuration option: "HttpTimeout" to set the default timeout for HTTP requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1534
diff changeset
240 static void SetDefaultTimeout(long timeout);
1606
31f4adefb88f issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1590
diff changeset
241
3393
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
242 void ApplyAndThrowException(IAnswer& answer);
2cd0369a156f support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3392
diff changeset
243
2041
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
244 void ApplyAndThrowException(std::string& answerBody);
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
245
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
246 void ApplyAndThrowException(Json::Value& answerBody);
1606
31f4adefb88f issuing HTTP requests from the plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1590
diff changeset
247
2041
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
248 void ApplyAndThrowException(std::string& answerBody,
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
249 HttpHeaders& answerHeaders);
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
250
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
251 void ApplyAndThrowException(Json::Value& answerBody,
9f61ca1e3eb3 OrthancPluginHttpClient can return the HTTP headers of the answer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2040
diff changeset
252 HttpHeaders& answerHeaders);
2787
ad2c32082653 Fix OrthancPluginHttpClient() to return the HTTP status on errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2677
diff changeset
253
ad2c32082653 Fix OrthancPluginHttpClient() to return the HTTP status on errors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2677
diff changeset
254 static void ThrowException(HttpStatus status);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }