Mercurial > hg > orthanc
annotate OrthancFramework/Sources/RestApi/RestApiOutput.cpp @ 5134:6aa41d86b948
fix ModificationJob state machine
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 10 Jan 2023 11:46:00 +0100 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
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 |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
209 | 7 * |
8 * 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
|
9 * 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
|
10 * 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
|
11 * the License, or (at your option) any later version. |
209 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * 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
|
16 * Lesser General Public License for more details. |
209 | 17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
209 | 21 **/ |
22 | |
23 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
209 | 25 #include "RestApiOutput.h" |
26 | |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
27 #include "../Logging.h" |
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
28 #include "../OrthancException.h" |
2142 | 29 #include "../Toolbox.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
30 |
330 | 31 #include <boost/lexical_cast.hpp> |
32 | |
211 | 33 |
209 | 34 namespace Orthanc |
35 { | |
1368 | 36 RestApiOutput::RestApiOutput(HttpOutput& output, |
37 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
|
38 output_(output), |
1368 | 39 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
|
40 convertJsonToXml_(false) |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
41 { |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
42 alreadySent_ = false; |
210
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 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
45 RestApiOutput::~RestApiOutput() |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
46 { |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
47 } |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
48 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
49 void RestApiOutput::Finalize() |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
50 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
51 if (!alreadySent_) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
52 { |
1368 | 53 if (method_ == HttpMethod_Post) |
54 { | |
55 output_.SendStatus(HttpStatus_400_BadRequest); | |
56 } | |
57 else | |
58 { | |
59 output_.SendStatus(HttpStatus_404_NotFound); | |
60 } | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
61 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
62 } |
211 | 63 |
64 void RestApiOutput::CheckStatus() | |
65 { | |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
66 if (alreadySent_) |
211 | 67 { |
68 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
69 } | |
70 } | |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
71 |
1514
d73a2178b319
support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1511
diff
changeset
|
72 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1518
diff
changeset
|
73 void RestApiOutput::AnswerStream(IHttpStreamAnswer& stream) |
209 | 74 { |
211 | 75 CheckStatus(); |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1518
diff
changeset
|
76 output_.Answer(stream); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
77 alreadySent_ = true; |
209 | 78 } |
79 | |
4672
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
80 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
81 void RestApiOutput::AnswerWithoutBuffering(IHttpStreamAnswer& stream) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
82 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
83 CheckStatus(); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
84 output_.AnswerWithoutBuffering(stream); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
85 alreadySent_ = true; |
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 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
88 |
209 | 89 void RestApiOutput::AnswerJson(const Json::Value& value) |
90 { | |
211 | 91 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
|
92 |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
93 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
|
94 { |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2118
diff
changeset
|
95 #if ORTHANC_ENABLE_PUGIXML == 1 |
1517 | 96 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
|
97 Toolbox::JsonToXml(s, value); |
2905
ae20fccdd867
refactoring mime types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
98 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
99 output_.SetContentType(MIME_XML_UTF8); |
1521 | 100 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
|
101 #else |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
102 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
103 "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
|
104 #endif |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
105 } |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
106 else |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
107 { |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
108 std::string s; |
4394
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
109 Toolbox::WriteStyledJson(s, value); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
110 output_.SetContentType(MIME_JSON_UTF8); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
111 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
|
112 } |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
113 |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
114 alreadySent_ = true; |
209 | 115 } |
116 | |
117 void RestApiOutput::AnswerBuffer(const std::string& buffer, | |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
118 MimeType contentType) |
209 | 119 { |
1514
d73a2178b319
support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1511
diff
changeset
|
120 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
|
121 buffer.size(), contentType); |
209 | 122 } |
123 | |
339 | 124 void RestApiOutput::AnswerBuffer(const void* buffer, |
125 size_t length, | |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
126 MimeType contentType) |
339 | 127 { |
128 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
|
129 |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
130 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
|
131 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
|
132 { |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
133 Json::Value json; |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
134 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
|
135 { |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
136 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
|
137 } |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
138 else |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
139 { |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
140 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
|
141 "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
|
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 } |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
144 else |
7eb5405b7ed8
Enlarge the support of JSON-to-XML conversion in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
145 { |
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_.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
|
147 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
|
148 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
|
149 } |
339 | 150 } |
151 | |
215
c07170f3f4f7
refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
211
diff
changeset
|
152 void RestApiOutput::Redirect(const std::string& path) |
209 | 153 { |
211 | 154 CheckStatus(); |
209 | 155 output_.Redirect(path); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
156 alreadySent_ = true; |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
157 } |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
158 |
1567
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
159 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
|
160 const char* message, |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
161 size_t messageSize) |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
162 { |
1194 | 163 if (status != HttpStatus_400_BadRequest && |
164 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
|
165 status != HttpStatus_500_InternalServerError && |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
166 status != HttpStatus_415_UnsupportedMediaType) |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
167 { |
1582
bd1889029cbb
encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1567
diff
changeset
|
168 throw OrthancException(ErrorCode_BadHttpStatusInRest); |
216
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 |
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
171 CheckStatus(); |
1567
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
172 output_.SendStatus(status, message, messageSize); |
216
e5d5d4a9a326
refactored upload of dicom through http
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
215
diff
changeset
|
173 alreadySent_ = true; |
209 | 174 } |
330 | 175 |
1567
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
176 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
|
177 { |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
178 SignalErrorInternal(status, NULL, 0); |
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 |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
181 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
|
182 const std::string& message) |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
183 { |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
184 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
|
185 } |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1521
diff
changeset
|
186 |
330 | 187 void RestApiOutput::SetCookie(const std::string& name, |
188 const std::string& value, | |
189 unsigned int maxAge) | |
190 { | |
191 if (name.find(";") != std::string::npos || | |
192 name.find(" ") != std::string::npos || | |
193 value.find(";") != std::string::npos || | |
194 value.find(" ") != std::string::npos) | |
195 { | |
196 throw OrthancException(ErrorCode_NotImplemented); | |
197 } | |
198 | |
199 CheckStatus(); | |
200 | |
201 std::string v = value + ";path=/"; | |
202 | |
203 if (maxAge != 0) | |
204 { | |
205 v += ";max-age=" + boost::lexical_cast<std::string>(maxAge); | |
206 } | |
207 | |
1042
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
208 output_.SetCookie(name, v); |
330 | 209 } |
210 | |
211 void RestApiOutput::ResetCookie(const std::string& name) | |
212 { | |
213 // This marks the cookie to be deleted by the browser in 1 second, | |
214 // and before it actually gets deleted, its value is set to the | |
215 // empty string | |
216 SetCookie(name, "", 1); | |
217 } | |
4805
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4672
diff
changeset
|
218 |
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4672
diff
changeset
|
219 void RestApiOutput::SetContentFilename(const char* filename) |
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4672
diff
changeset
|
220 { |
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4672
diff
changeset
|
221 output_.SetContentFilename(filename); |
0a38000b086d
Archive jobs response now contains a header Content-Disposition:filename='archive.zip'
Alain Mazy <am@osimis.io>
parents:
4672
diff
changeset
|
222 } |
209 | 223 } |