Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/IHttpHandler.cpp @ 4844:55e8fb8e8028
tagging a pre-release of the Orthanc framework for WSI 1.1
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Dec 2021 14:01:17 +0100 |
parents | 7053502fbf97 |
children | 43e613a7756b |
rev | line source |
---|---|
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
4831
7053502fbf97
added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4605
diff
changeset
|
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * License along with this program. If not, see |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "IHttpHandler.h" |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include "HttpOutput.h" |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include "HttpToolbox.h" |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 #include "StringHttpOutput.h" |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 static const char* LOCALHOST = "127.0.0.1"; |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 namespace Orthanc |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
36 HttpStatus IHttpHandler::SimpleGet(std::string& answerBody, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
37 HttpToolbox::Arguments* answerHeaders, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
38 IHttpHandler& handler, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
39 RequestOrigin origin, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
40 const std::string& uri, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
41 const HttpToolbox::Arguments& httpHeaders) |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 UriComponents curi; |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4329
diff
changeset
|
44 HttpToolbox::GetArguments getArguments; |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 HttpToolbox::ParseGetQuery(curi, getArguments, uri.c_str()); |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 StringHttpOutput stream; |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 HttpOutput http(stream, false /* no keep alive */); |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 if (handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Get, curi, |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 httpHeaders, getArguments, NULL /* no body for GET */, 0)) |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 { |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
53 stream.GetBody(answerBody); |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
54 |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
55 if (answerHeaders != NULL) |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
56 { |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
57 stream.GetHeaders(*answerHeaders, true /* convert key to lower case */); |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
58 } |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
59 |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
60 return stream.GetStatus(); |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 else |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 { |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
64 return HttpStatus_404_NotFound; |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
69 static HttpStatus SimplePostOrPut(std::string& answerBody, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
70 HttpToolbox::Arguments* answerHeaders, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
71 IHttpHandler& handler, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
72 RequestOrigin origin, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
73 HttpMethod method, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
74 const std::string& uri, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
75 const void* bodyData, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
76 size_t bodySize, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
77 const HttpToolbox::Arguments& httpHeaders) |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4329
diff
changeset
|
79 HttpToolbox::GetArguments getArguments; // No GET argument for POST/PUT |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 UriComponents curi; |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 Toolbox::SplitUriComponents(curi, uri); |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 StringHttpOutput stream; |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 HttpOutput http(stream, false /* no keep alive */); |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 if (handler.Handle(http, origin, LOCALHOST, "", method, curi, |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 httpHeaders, getArguments, bodyData, bodySize)) |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 { |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
90 stream.GetBody(answerBody); |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
91 |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
92 if (answerHeaders != NULL) |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
93 { |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
94 stream.GetHeaders(*answerHeaders, true /* convert key to lower case */); |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
95 } |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
96 |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
97 return stream.GetStatus(); |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 else |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 { |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
101 return HttpStatus_404_NotFound; |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
106 HttpStatus IHttpHandler::SimplePost(std::string& answerBody, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
107 HttpToolbox::Arguments* answerHeaders, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
108 IHttpHandler& handler, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
109 RequestOrigin origin, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
110 const std::string& uri, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
111 const void* bodyData, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
112 size_t bodySize, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
113 const HttpToolbox::Arguments& httpHeaders) |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 { |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
115 return SimplePostOrPut(answerBody, answerHeaders, handler, origin, HttpMethod_Post, uri, bodyData, bodySize, httpHeaders); |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
119 HttpStatus IHttpHandler::SimplePut(std::string& answerBody, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
120 HttpToolbox::Arguments* answerHeaders, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
121 IHttpHandler& handler, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
122 RequestOrigin origin, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
123 const std::string& uri, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
124 const void* bodyData, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
125 size_t bodySize, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
126 const HttpToolbox::Arguments& httpHeaders) |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 { |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
128 return SimplePostOrPut(answerBody, answerHeaders, handler, origin, HttpMethod_Put, uri, bodyData, bodySize, httpHeaders); |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
132 HttpStatus IHttpHandler::SimpleDelete(HttpToolbox::Arguments* answerHeaders, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
133 IHttpHandler& handler, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
134 RequestOrigin origin, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
135 const std::string& uri, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
136 const HttpToolbox::Arguments& httpHeaders) |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 { |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 UriComponents curi; |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 Toolbox::SplitUriComponents(curi, uri); |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4329
diff
changeset
|
141 HttpToolbox::GetArguments getArguments; // No GET argument for DELETE |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 StringHttpOutput stream; |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 HttpOutput http(stream, false /* no keep alive */); |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 |
4605
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
146 if (handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Delete, curi, |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
147 httpHeaders, getArguments, NULL /* no body for DELETE */, 0)) |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
148 { |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
149 if (answerHeaders != NULL) |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
150 { |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
151 stream.GetHeaders(*answerHeaders, true /* convert key to lower case */); |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
152 } |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
153 |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
154 return stream.GetStatus(); |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
155 } |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
156 else |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
157 { |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
158 return HttpStatus_404_NotFound; |
c8f444e8556d
new function in the plugin SDK: OrthancPluginCallRestApi()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
159 } |
4329
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 } |
9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 } |