annotate Core/HttpServer/HttpOutput.h @ 4089:a2060a76ed6a

note in ArchiveStudiesInTimeRange.py
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Jun 2020 18:43:42 +0200
parents f9863630ec7f
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 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1137
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3528
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
11 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
12 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
13 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
16 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
20 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
21 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
22 * in the program, then also delete it here.
0
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 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #pragma once
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
2142
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
36 #include "../Enumerations.h"
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
37 #include "IHttpOutputStream.h"
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
38 #include "IHttpStreamAnswer.h"
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
39
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
40 #include <list>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <string>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <stdint.h>
2142
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
43 #include <map>
3528
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
44 #include <vector>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
46 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
48 class ORTHANC_PUBLIC HttpOutput : public boost::noncopyable
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 private:
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
51 typedef std::list< std::pair<std::string, std::string> > Header;
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
52
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
53 class StateMachine : public boost::noncopyable
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
54 {
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
55 public:
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
56 enum State
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
57 {
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
58 State_WritingHeader,
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
59 State_WritingBody,
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
60 State_WritingMultipart,
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
61 State_Done
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
62 };
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
63
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
64 private:
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
65 IHttpOutputStream& stream_;
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
66 State state_;
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
67
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
68 HttpStatus status_;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
69 bool hasContentLength_;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
70 uint64_t contentLength_;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
71 uint64_t contentPosition_;
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
72 bool keepAlive_;
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
73 std::list<std::string> headers_;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
74
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
75 std::string multipartBoundary_;
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
76 std::string multipartContentType_;
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
77
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
78 public:
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
79 StateMachine(IHttpOutputStream& stream,
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
80 bool isKeepAlive);
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
81
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
82 ~StateMachine();
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
83
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
84 void SetHttpStatus(HttpStatus status);
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
85
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
86 void SetContentLength(uint64_t length);
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
87
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
88 void SetContentType(const char* contentType);
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
89
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
90 void SetContentFilename(const char* filename);
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
91
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
92 void SetCookie(const std::string& cookie,
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
93 const std::string& value);
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
94
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
95 void AddHeader(const std::string& header,
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
96 const std::string& value);
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
97
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
98 void ClearHeaders();
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
99
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
100 void SendBody(const void* buffer, size_t length);
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
101
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
102 void StartMultipart(const std::string& subType,
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
103 const std::string& contentType);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
104
1882
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
105 void SendMultipartItem(const void* item,
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
106 size_t length,
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
107 const std::map<std::string, std::string>& headers);
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
108
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
109 void CloseMultipart();
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
110
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
111 void CloseBody();
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
112
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
113 State GetState() const
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
114 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
115 return state_;
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
116 }
3528
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
117
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
118 void CheckHeadersCompatibilityWithMultipart() const;
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
119 };
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
120
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
121 StateMachine stateMachine_;
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
122 bool isDeflateAllowed_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
123 bool isGzipAllowed_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
124
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
125 HttpCompression GetPreferredCompression(size_t bodySize) const;
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
126
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 public:
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
128 HttpOutput(IHttpOutputStream& stream,
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
129 bool isKeepAlive) :
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
130 stateMachine_(stream, isKeepAlive),
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
131 isDeflateAllowed_(false),
1645
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1592
diff changeset
132 isGzipAllowed_(false)
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
133 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
134 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
135
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
136 void SetDeflateAllowed(bool allowed)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
138 isDeflateAllowed_ = allowed;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
139 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
140
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
141 bool IsDeflateAllowed() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
142 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
143 return isDeflateAllowed_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
144 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
145
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
146 void SetGzipAllowed(bool allowed)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
147 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
148 isGzipAllowed_ = allowed;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
149 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
150
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
151 bool IsGzipAllowed() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
152 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1511
diff changeset
153 return isGzipAllowed_;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
1567
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
156 void SendStatus(HttpStatus status,
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
157 const char* message,
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
158 size_t messageSize);
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
159
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
160 void SendStatus(HttpStatus status)
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
161 {
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
162 SendStatus(status, NULL, 0);
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
163 }
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
164
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
165 void SendStatus(HttpStatus status,
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
166 const std::string& message)
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
167 {
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1521
diff changeset
168 SendStatus(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
169 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
170
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
171 void SetContentType(MimeType contentType)
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
172 {
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
173 stateMachine_.SetContentType(EnumerationToString(contentType));
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
174 }
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
175
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
176 void SetContentType(const std::string& contentType)
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
177 {
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
178 stateMachine_.SetContentType(contentType.c_str());
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
179 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
180
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
181 void SetContentFilename(const char* filename)
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
182 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
183 stateMachine_.SetContentFilename(filename);
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
184 }
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
185
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
186 void SetCookie(const std::string& cookie,
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
187 const std::string& value)
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
188 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
189 stateMachine_.SetCookie(cookie, value);
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
190 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
1137
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1115
diff changeset
192 void AddHeader(const std::string& key,
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1115
diff changeset
193 const std::string& value)
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1115
diff changeset
194 {
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1115
diff changeset
195 stateMachine_.AddHeader(key, value);
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1115
diff changeset
196 }
d9c27f9f1a51 OrthancPluginSetHttpHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1115
diff changeset
197
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
198 void Answer(const void* buffer,
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
199 size_t length);
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
200
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
201 void Answer(const std::string& str);
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
202
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
203 void AnswerEmpty();
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
204
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
205 void SendMethodNotAllowed(const std::string& allowed);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
207 void Redirect(const std::string& path);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
209 void SendUnauthorized(const std::string& realm);
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
210
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
211 void StartMultipart(const std::string& subType,
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
212 const std::string& contentType)
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
213 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
214 stateMachine_.StartMultipart(subType, contentType);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
215 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
216
1882
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
217 void SendMultipartItem(const void* item,
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
218 size_t size,
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
219 const std::map<std::string, std::string>& headers)
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
220 {
1882
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
221 stateMachine_.SendMultipartItem(item, size, headers);
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
222 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
223
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
224 void CloseMultipart()
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
225 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
226 stateMachine_.CloseMultipart();
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
227 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
228
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
229 bool IsWritingMultipart() const
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
230 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
231 return stateMachine_.GetState() == StateMachine::State_WritingMultipart;
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
232 }
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
233
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
234 void Answer(IHttpStreamAnswer& stream);
3528
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
235
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
236 /**
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
237 * This method is a replacement to the combination
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
238 * "StartMultipart()" + "SendMultipartItem()". It generates the
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
239 * same answer, but it gives a chance to compress the body if
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
240 * "Accept-Encoding: gzip" is provided by the client, which is not
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
241 * possible in chunked transfers.
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
242 **/
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
243 void AnswerMultipartWithoutChunkedTransfer(
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
244 const std::string& subType,
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
245 const std::string& contentType,
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
246 const std::vector<const void*>& parts,
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
247 const std::vector<size_t>& sizes,
f6fe095f7130 don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
248 const std::vector<const std::map<std::string, std::string>*>& headers);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }