annotate OrthancServer/Sources/OrthancHttpHandler.cpp @ 5663:3765085693e5 large-queries

merge default -> large-queries
author Alain Mazy <am@orthanc.team>
date Thu, 04 Jul 2024 07:40:58 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * License, or (at your option) any later version.
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * General Public License for more details.
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "PrecompiledHeadersServer.h"
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "OrthancHttpHandler.h"
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
27 #include "../../OrthancFramework/Sources/OrthancException.h"
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace Orthanc
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
32 bool OrthancHttpHandler::CreateChunkedRequestReader(
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
33 std::unique_ptr<IHttpHandler::IChunkedRequestReader>& target,
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
34 RequestOrigin origin,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
35 const char* remoteIp,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
36 const char* username,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
37 HttpMethod method,
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
38 const UriComponents& uri,
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
39 const HttpToolbox::Arguments& headers)
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
40 {
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
41 if (method != HttpMethod_Post &&
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
42 method != HttpMethod_Put)
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
43 {
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
44 throw OrthancException(ErrorCode_InternalError);
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
45 }
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
46
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
47 for (Handlers::const_iterator it = handlers_.begin(); it != handlers_.end(); ++it)
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
48 {
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
49 if ((*it)->CreateChunkedRequestReader
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
50 (target, origin, remoteIp, username, method, uri, headers))
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
51 {
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
52 if (target.get() == NULL)
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
53 {
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
54 throw OrthancException(ErrorCode_InternalError);
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
55 }
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
56
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
57 return true;
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
58 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
59 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
60
3414
b9cba6a91780 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
61 return false;
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
62 }
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
63
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
64
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 bool OrthancHttpHandler::Handle(HttpOutput& output,
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
66 RequestOrigin origin,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
67 const char* remoteIp,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
68 const char* username,
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 HttpMethod method,
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 const UriComponents& uri,
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
71 const HttpToolbox::Arguments& headers,
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
72 const HttpToolbox::GetArguments& getArguments,
3401
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3395
diff changeset
73 const void* bodyData,
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1445
diff changeset
74 size_t bodySize)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
76 for (Handlers::const_iterator it = handlers_.begin(); it != handlers_.end(); ++it)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
78 if ((*it)->Handle(output, origin, remoteIp, username, method, uri,
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
79 headers, getArguments, bodyData, bodySize))
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
80 {
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
81 return true;
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
82 }
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
3395
0ce9b4f5fdf5 new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
85 return false;
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1442
diff changeset
89 void OrthancHttpHandler::Register(IHttpHandler& handler,
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1442
diff changeset
90 bool isOrthancRestApi)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 handlers_.push_back(&handler);
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 if (isOrthancRestApi)
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 orthancRestApi_ = &handler;
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
1445
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
101 IHttpHandler& OrthancHttpHandler::RestrictToOrthancRestApi(bool restrict)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
1445
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
103 if (restrict)
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
1445
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
105 if (orthancRestApi_ == NULL)
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
106 {
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
107 throw OrthancException(ErrorCode_InternalError);
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
108 }
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
109
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
110 return *orthancRestApi_;
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
1445
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
112 else
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
113 {
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
114 return *this;
d26c8a93d05a refactoring: SimpleGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
115 }
1442
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
4ff8dd753d79 OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }