Mercurial > hg > orthanc
annotate OrthancFramework/Sources/RestApi/RestApiOutput.cpp @ 4737:979ae3ea3381
DANGEROUS commit: Anonymization is now also applied to nested sequences
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 Jul 2021 08:12:26 +0200 |
parents | d9942d48fea7 |
children | 0a38000b086d |
rev | line source |
---|---|
209 | 1 /** |
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:
1194
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4394
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
209 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
209 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
209 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
209 | 20 **/ |
21 | |
22 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
23 #include "../PrecompiledHeaders.h" |
209 | 24 #include "RestApiOutput.h" |
25 | |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
26 #include "../Logging.h" |
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
27 #include "../OrthancException.h" |
2142 | 28 #include "../Toolbox.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
29 |
330 | 30 #include <boost/lexical_cast.hpp> |
31 | |
211 | 32 |
209 | 33 namespace Orthanc |
34 { | |
1368 | 35 RestApiOutput::RestApiOutput(HttpOutput& output, |
36 HttpMethod method) : | |
1046
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
37 output_(output), |
1368 | 38 method_(method), |
1046
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
39 convertJsonToXml_(false) |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
40 { |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
41 alreadySent_ = false; |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
42 } |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
43 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
44 RestApiOutput::~RestApiOutput() |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
45 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
46 } |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
47 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
48 void RestApiOutput::Finalize() |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
49 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
50 if (!alreadySent_) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
51 { |
1368 | 52 if (method_ == HttpMethod_Post) |
53 { | |
54 output_.SendStatus(HttpStatus_400_BadRequest); | |
55 } | |
56 else | |
57 { | |
58 output_.SendStatus(HttpStatus_404_NotFound); | |
59 } | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
60 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
61 } |
211 | 62 |
63 void RestApiOutput::CheckStatus() | |
64 { | |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
65 if (alreadySent_) |
211 | 66 { |
67 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
68 } | |
69 } | |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
70 |
1514
d73a2178b319
support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1511
diff
changeset
|
71 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1518
diff
changeset
|
72 void RestApiOutput::AnswerStream(IHttpStreamAnswer& stream) |
209 | 73 { |
211 | 74 CheckStatus(); |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1518
diff
changeset
|
75 output_.Answer(stream); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
76 alreadySent_ = true; |
209 | 77 } |
78 | |
4672
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
79 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
80 void RestApiOutput::AnswerWithoutBuffering(IHttpStreamAnswer& stream) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
81 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
82 CheckStatus(); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
83 output_.AnswerWithoutBuffering(stream); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
84 alreadySent_ = true; |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
85 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
86 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
87 |
209 | 88 void RestApiOutput::AnswerJson(const Json::Value& value) |
89 { | |
211 | 90 CheckStatus(); |
1046
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
91 |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
92 if (convertJsonToXml_) |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
93 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2118
diff
changeset
|
94 #if ORTHANC_ENABLE_PUGIXML == 1 |
1517 | 95 std::string s; |
1046
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
96 Toolbox::JsonToXml(s, value); |
2905
ae20fccdd867
refactoring mime types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
97 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
98 output_.SetContentType(MIME_XML_UTF8); |
1521 | 99 output_.Answer(s); |
1046
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
100 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
101 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
102 "Orthanc was compiled without XML support"); |
1046
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
103 #endif |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
104 } |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
105 else |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
106 { |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
107 std::string s; |
4394
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
108 Toolbox::WriteStyledJson(s, value); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
109 output_.SetContentType(MIME_JSON_UTF8); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
110 output_.Answer(s); |
1046
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
111 } |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
112 |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
113 alreadySent_ = true; |
209 | 114 } |
115 | |
116 void RestApiOutput::AnswerBuffer(const std::string& buffer, | |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
117 MimeType contentType) |
209 | 118 { |
1514
d73a2178b319
support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1511
diff
changeset
|
119 AnswerBuffer(buffer.size() == 0 ? NULL : buffer.c_str(), |
d73a2178b319
support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1511
diff
changeset
|
120 buffer.size(), contentType); |
209 | 121 } |
122 | |
339 | 123 void RestApiOutput::AnswerBuffer(const void* buffer, |
124 size_t length, | |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
125 MimeType contentType) |
339 | 126 { |
127 CheckStatus(); | |
3314
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
128 |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
129 if (convertJsonToXml_ && |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
130 contentType == MimeType_Json) |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
131 { |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
132 Json::Value json; |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
133 if (Toolbox::ReadJson(json, buffer, length)) |
3314
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
134 { |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
135 AnswerJson(json); |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
136 } |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
137 else |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
138 { |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
139 throw OrthancException(ErrorCode_BadFileFormat, |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
140 "The REST API tries and answers with an invalid JSON file"); |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
141 } |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
142 } |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
143 else |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
144 { |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
145 output_.SetContentType(contentType); |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
146 output_.Answer(buffer, length); |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
147 alreadySent_ = true; |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
148 } |
339 | 149 } |
150 | |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
211
diff
changeset
|
151 void RestApiOutput::Redirect(const std::string& path) |
209 | 152 { |
211 | 153 CheckStatus(); |
209 | 154 output_.Redirect(path); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
155 alreadySent_ = true; |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
156 } |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
157 |
1567
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
158 void RestApiOutput::SignalErrorInternal(HttpStatus status, |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
159 const char* message, |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
160 size_t messageSize) |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
161 { |
1194 | 162 if (status != HttpStatus_400_BadRequest && |
163 status != HttpStatus_403_Forbidden && | |
1165
0561f2087cc9
Fix reporting of errors in Orthanc Explorer when sending images to peers/modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
164 status != HttpStatus_500_InternalServerError && |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
165 status != HttpStatus_415_UnsupportedMediaType) |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
166 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1567
diff
changeset
|
167 throw OrthancException(ErrorCode_BadHttpStatusInRest); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
168 } |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
169 |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
170 CheckStatus(); |
1567
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
171 output_.SendStatus(status, message, messageSize); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
172 alreadySent_ = true; |
209 | 173 } |
330 | 174 |
1567
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
175 void RestApiOutput::SignalError(HttpStatus status) |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
176 { |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
177 SignalErrorInternal(status, NULL, 0); |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
178 } |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
179 |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
180 void RestApiOutput::SignalError(HttpStatus status, |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
181 const std::string& message) |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
182 { |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
183 SignalErrorInternal(status, message.c_str(), message.size()); |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
184 } |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
185 |
330 | 186 void RestApiOutput::SetCookie(const std::string& name, |
187 const std::string& value, | |
188 unsigned int maxAge) | |
189 { | |
190 if (name.find(";") != std::string::npos || | |
191 name.find(" ") != std::string::npos || | |
192 value.find(";") != std::string::npos || | |
193 value.find(" ") != std::string::npos) | |
194 { | |
195 throw OrthancException(ErrorCode_NotImplemented); | |
196 } | |
197 | |
198 CheckStatus(); | |
199 | |
200 std::string v = value + ";path=/"; | |
201 | |
202 if (maxAge != 0) | |
203 { | |
204 v += ";max-age=" + boost::lexical_cast<std::string>(maxAge); | |
205 } | |
206 | |
1042
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
207 output_.SetCookie(name, v); |
330 | 208 } |
209 | |
210 void RestApiOutput::ResetCookie(const std::string& name) | |
211 { | |
212 // This marks the cookie to be deleted by the browser in 1 second, | |
213 // and before it actually gets deleted, its value is set to the | |
214 // empty string | |
215 SetCookie(name, "", 1); | |
216 } | |
209 | 217 } |