Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/HttpOutput.cpp @ 5066:956a9fed0aa8
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 15 Aug 2022 14:22:50 +0200 |
parents | 43e613a7756b |
children | bdec57f3cbf2 |
rev | line source |
---|---|
0 | 1 /** |
59 | 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:
1200
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 |
0 | 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. |
136 | 12 * |
0 | 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. |
0 | 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/>. |
0 | 21 **/ |
22 | |
23 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
0 | 25 #include "HttpOutput.h" |
26 | |
3380
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
27 #include "../ChunkedBuffer.h" |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
28 #include "../Compression/GzipCompressor.h" |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
29 #include "../Compression/ZlibCompressor.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
30 #include "../Logging.h" |
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
31 #include "../OrthancException.h" |
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
32 #include "../Toolbox.h" |
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
33 |
324 | 34 #include <iostream> |
0 | 35 #include <vector> |
36 #include <stdio.h> | |
37 #include <boost/lexical_cast.hpp> | |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
38 |
0 | 39 |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
40 #if ORTHANC_ENABLE_CIVETWEB == 1 |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
41 # if !defined(CIVETWEB_HAS_DISABLE_KEEP_ALIVE) |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
42 # error Macro CIVETWEB_HAS_DISABLE_KEEP_ALIVE must be defined |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
43 # endif |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
44 #endif |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
45 |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
46 |
59 | 47 namespace Orthanc |
0 | 48 { |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
49 HttpOutput::StateMachine::StateMachine(IHttpOutputStream& stream, |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
50 bool isKeepAlive) : |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
51 stream_(stream), |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
52 state_(State_WritingHeader), |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
53 status_(HttpStatus_200_Ok), |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
54 hasContentLength_(false), |
4201 | 55 contentLength_(0), |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
56 contentPosition_(0), |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
57 keepAlive_(isKeepAlive) |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
58 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
59 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
60 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
61 HttpOutput::StateMachine::~StateMachine() |
910 | 62 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
63 if (state_ != State_Done) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
64 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
65 //asm volatile ("int3;"); |
1200 | 66 //LOG(ERROR) << "This HTTP answer does not contain any body"; |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
67 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
68 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
69 if (hasContentLength_ && contentPosition_ != contentLength_) |
910 | 70 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
71 LOG(ERROR) << "This HTTP answer has not sent the proper number of bytes in its body"; |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
72 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
73 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
74 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
75 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
76 void HttpOutput::StateMachine::SetHttpStatus(HttpStatus status) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
77 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
78 if (state_ != State_WritingHeader) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
79 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
80 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
910 | 81 } |
82 | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
83 status_ = status; |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
84 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
85 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
86 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
87 void HttpOutput::StateMachine::SetContentLength(uint64_t length) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
88 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
89 if (state_ != State_WritingHeader) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
90 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
91 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
92 } |
910 | 93 |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
94 hasContentLength_ = true; |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
95 contentLength_ = length; |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
96 } |
910 | 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 HttpOutput::StateMachine::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
|
99 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
100 AddHeader("Content-Type", contentType); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
101 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
102 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
103 void HttpOutput::StateMachine::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
|
104 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
105 // TODO Escape double quotes |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
106 AddHeader("Content-Disposition", "filename=\"" + std::string(filename) + "\""); |
910 | 107 } |
108 | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
109 void HttpOutput::StateMachine::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
|
110 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
|
111 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
112 if (state_ != State_WritingHeader) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
113 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
114 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
115 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
116 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
117 // TODO Escape "=" characters |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
118 AddHeader("Set-Cookie", cookie + "=" + value); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
119 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
120 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
121 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
122 void HttpOutput::StateMachine::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
|
123 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
|
124 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
125 if (state_ != State_WritingHeader) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
126 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
127 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
128 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
129 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
130 headers_.push_back(header + ": " + value + "\r\n"); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
131 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
132 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
133 void HttpOutput::StateMachine::ClearHeaders() |
910 | 134 { |
135 if (state_ != State_WritingHeader) | |
136 { | |
137 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
138 } | |
139 | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
140 headers_.clear(); |
910 | 141 } |
142 | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
143 void HttpOutput::StateMachine::SendBody(const void* buffer, size_t length) |
910 | 144 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
145 if (state_ == State_Done) |
910 | 146 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
147 if (length == 0) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
148 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
149 return; |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
150 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
151 else |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
152 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
153 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
154 "Because of keep-alive connections, the entire body must " |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
155 "be sent at once or Content-Length must be given"); |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
156 } |
910 | 157 } |
158 | |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
159 if (state_ == State_WritingMultipart) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
160 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
161 throw OrthancException(ErrorCode_InternalError); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
162 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
163 |
910 | 164 if (state_ == State_WritingHeader) |
165 { | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
166 // Send the HTTP header before writing the body |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
167 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
168 stream_.OnHttpStatusReceived(status_); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
169 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
170 std::string s = "HTTP/1.1 " + |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
171 boost::lexical_cast<std::string>(status_) + |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
172 " " + std::string(EnumerationToString(status_)) + |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
173 "\r\n"; |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
174 |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
175 if (keepAlive_) |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
176 { |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
177 s += "Connection: keep-alive\r\n"; |
4301
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
178 |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
179 /** |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
180 * [LIFY-2311] The "Keep-Alive" HTTP header was missing in |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
181 * Orthanc <= 1.8.0, which notably caused failures if |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
182 * uploading DICOM instances by applying Java's |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
183 * "org.apache.http.client.methods.HttpPost()" on "/instances" |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
184 * URI, if "PoolingHttpClientConnectionManager" was in used. A |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
185 * workaround was to manually set a timeout for the keep-alive |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
186 * client to, say, 200 milliseconds, by using |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
187 * "HttpClients.custom().setKeepAliveStrategy((httpResponse,httpContext)->200)". |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
188 * Note that the "timeout" value can only be integer in the |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
189 * HTTP header, so we can't use the milliseconds granularity. |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
190 **/ |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
191 s += ("Keep-Alive: timeout=" + |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
192 boost::lexical_cast<std::string>(CIVETWEB_KEEP_ALIVE_TIMEOUT_SECONDS) + "\r\n"); |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
193 } |
3171
81cd9a4f3018
always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
194 else |
81cd9a4f3018
always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
195 { |
81cd9a4f3018
always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
196 s += "Connection: close\r\n"; |
81cd9a4f3018
always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
197 } |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
198 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
199 for (std::list<std::string>::const_iterator |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
200 it = headers_.begin(); it != headers_.end(); ++it) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
201 { |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
202 s += *it; |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
203 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
204 |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
205 if (status_ != HttpStatus_200_Ok) |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
206 { |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
207 hasContentLength_ = false; |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
208 } |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
209 |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
210 uint64_t contentLength = (hasContentLength_ ? contentLength_ : length); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
211 s += "Content-Length: " + boost::lexical_cast<std::string>(contentLength) + "\r\n\r\n"; |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
212 |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
213 stream_.Send(true, s.c_str(), s.size()); |
910 | 214 state_ = State_WritingBody; |
215 } | |
216 | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
217 if (hasContentLength_ && |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
218 contentPosition_ + length > contentLength_) |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
219 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
220 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
221 "The body size exceeds what was declared with SetContentSize()"); |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
222 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
223 |
910 | 224 if (length > 0) |
225 { | |
911 | 226 stream_.Send(false, buffer, length); |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
227 contentPosition_ += length; |
330 | 228 } |
229 | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
230 if (!hasContentLength_ || |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
231 contentPosition_ == contentLength_) |
330 | 232 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
233 state_ = State_Done; |
330 | 234 } |
235 } | |
236 | |
207 | 237 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
238 void HttpOutput::StateMachine::CloseBody() |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
239 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
240 switch (state_) |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
241 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
242 case State_WritingHeader: |
1522 | 243 SetContentLength(0); |
244 SendBody(NULL, 0); | |
245 break; | |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
246 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
247 case State_WritingBody: |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
248 if (!hasContentLength_ || |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
249 contentPosition_ == contentLength_) |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
250 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
251 state_ = State_Done; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
252 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
253 else |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
254 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
255 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
256 "The body size has not reached what was declared with SetContentSize()"); |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
257 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
258 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
259 break; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
260 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
261 case State_WritingMultipart: |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
262 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
263 "Cannot invoke CloseBody() with multipart outputs"); |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
264 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
265 case State_Done: |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
266 return; // Ignore |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
267 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
268 default: |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
269 throw OrthancException(ErrorCode_InternalError); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
270 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
271 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
272 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
273 |
1517 | 274 HttpCompression HttpOutput::GetPreferredCompression(size_t bodySize) const |
275 { | |
276 #if 0 | |
277 // TODO Do not compress small files? | |
278 if (bodySize < 512) | |
279 { | |
280 return HttpCompression_None; | |
281 } | |
282 #endif | |
283 | |
284 // Prefer "gzip" over "deflate" if the choice is offered | |
285 | |
286 if (isGzipAllowed_) | |
287 { | |
288 return HttpCompression_Gzip; | |
289 } | |
290 else if (isDeflateAllowed_) | |
291 { | |
292 return HttpCompression_Deflate; | |
293 } | |
294 else | |
295 { | |
296 return HttpCompression_None; | |
297 } | |
298 } | |
299 | |
300 | |
4298 | 301 HttpOutput::HttpOutput(IHttpOutputStream &stream, |
302 bool isKeepAlive) : | |
303 stateMachine_(stream, isKeepAlive), | |
304 isDeflateAllowed_(false), | |
305 isGzipAllowed_(false) | |
306 { | |
307 } | |
308 | |
309 void HttpOutput::SetDeflateAllowed(bool allowed) | |
310 { | |
311 isDeflateAllowed_ = allowed; | |
312 } | |
313 | |
314 bool HttpOutput::IsDeflateAllowed() const | |
315 { | |
316 return isDeflateAllowed_; | |
317 } | |
318 | |
319 void HttpOutput::SetGzipAllowed(bool allowed) | |
320 { | |
321 isGzipAllowed_ = allowed; | |
322 } | |
323 | |
324 bool HttpOutput::IsGzipAllowed() const | |
325 { | |
326 return isGzipAllowed_; | |
327 } | |
328 | |
329 | |
1042
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
911
diff
changeset
|
330 void HttpOutput::SendMethodNotAllowed(const std::string& allowed) |
0 | 331 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
332 stateMachine_.ClearHeaders(); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
333 stateMachine_.SetHttpStatus(HttpStatus_405_MethodNotAllowed); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
334 stateMachine_.AddHeader("Allow", allowed); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
335 stateMachine_.SendBody(NULL, 0); |
0 | 336 } |
337 | |
338 | |
1567
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1523
diff
changeset
|
339 void HttpOutput::SendStatus(HttpStatus status, |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1523
diff
changeset
|
340 const char* message, |
9c5d93510414
If error while calling the REST API, the answer body contains an error description
jodogne
parents:
1523
diff
changeset
|
341 size_t messageSize) |
0 | 342 { |
1954 | 343 if (status == HttpStatus_301_MovedPermanently || |
3425 | 344 //status == HttpStatus_401_Unauthorized || |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
345 status == HttpStatus_405_MethodNotAllowed) |
0 | 346 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
347 throw OrthancException(ErrorCode_ParameterOutOfRange, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
348 "Please use the dedicated methods to this HTTP status code in HttpOutput"); |
0 | 349 } |
350 | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
351 stateMachine_.SetHttpStatus(status); |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1592
diff
changeset
|
352 stateMachine_.SendBody(message, messageSize); |
339 | 353 } |
354 | |
4298 | 355 void HttpOutput::SendStatus(HttpStatus status) |
356 { | |
357 SendStatus(status, NULL, 0); | |
358 } | |
359 | |
360 void HttpOutput::SendStatus(HttpStatus status, const std::string &message) | |
361 { | |
362 SendStatus(status, message.c_str(), message.size()); | |
363 } | |
364 | |
365 void HttpOutput::SetContentType(MimeType contentType) | |
366 { | |
367 stateMachine_.SetContentType(EnumerationToString(contentType)); | |
368 } | |
369 | |
370 void HttpOutput::SetContentType(const std::string &contentType) | |
371 { | |
372 stateMachine_.SetContentType(contentType.c_str()); | |
373 } | |
374 | |
375 void HttpOutput::SetContentFilename(const char *filename) | |
376 { | |
377 stateMachine_.SetContentFilename(filename); | |
378 } | |
379 | |
380 void HttpOutput::SetCookie(const std::string &cookie, const std::string &value) | |
381 { | |
382 stateMachine_.SetCookie(cookie, value); | |
383 } | |
384 | |
385 void HttpOutput::AddHeader(const std::string &key, const std::string &value) | |
386 { | |
387 stateMachine_.AddHeader(key, value); | |
388 } | |
389 | |
339 | 390 |
0 | 391 void HttpOutput::Redirect(const std::string& path) |
392 { | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
393 stateMachine_.ClearHeaders(); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
394 stateMachine_.SetHttpStatus(HttpStatus_301_MovedPermanently); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
395 stateMachine_.AddHeader("Location", path); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
396 stateMachine_.SendBody(NULL, 0); |
0 | 397 } |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
398 |
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
399 |
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
400 void HttpOutput::SendUnauthorized(const std::string& realm) |
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
401 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
402 stateMachine_.ClearHeaders(); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
403 stateMachine_.SetHttpStatus(HttpStatus_401_Unauthorized); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
404 stateMachine_.AddHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
405 stateMachine_.SendBody(NULL, 0); |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
406 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
407 |
4298 | 408 void HttpOutput::StartMultipart(const std::string &subType, const std::string &contentType) |
409 { | |
410 stateMachine_.StartMultipart(subType, contentType); | |
411 } | |
412 | |
413 void HttpOutput::SendMultipartItem(const void *item, | |
414 size_t size, | |
415 const std::map<std::string, std::string> &headers) | |
416 { | |
417 stateMachine_.SendMultipartItem(item, size, headers); | |
418 } | |
419 | |
420 void HttpOutput::CloseMultipart() | |
421 { | |
422 stateMachine_.CloseMultipart(); | |
423 } | |
424 | |
425 bool HttpOutput::IsWritingMultipart() const | |
426 { | |
427 return stateMachine_.GetState() == StateMachine::State_WritingMultipart; | |
428 } | |
429 | |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
430 |
4298 | 431 void HttpOutput::Answer(const void* buffer, |
1521 | 432 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
|
433 { |
1511
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
434 if (length == 0) |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
435 { |
1521 | 436 AnswerEmpty(); |
437 return; | |
438 } | |
439 | |
440 HttpCompression compression = GetPreferredCompression(length); | |
441 | |
442 if (compression == HttpCompression_None) | |
443 { | |
444 stateMachine_.SetContentLength(length); | |
445 stateMachine_.SendBody(buffer, length); | |
446 return; | |
447 } | |
448 | |
449 std::string compressed, encoding; | |
450 | |
451 switch (compression) | |
452 { | |
453 case HttpCompression_Deflate: | |
454 { | |
455 encoding = "deflate"; | |
456 ZlibCompressor compressor; | |
457 // Do not prefix the buffer with its uncompressed size, to be compatible with "deflate" | |
458 compressor.SetPrefixWithUncompressedSize(false); | |
459 compressor.Compress(compressed, buffer, length); | |
460 break; | |
461 } | |
462 | |
463 case HttpCompression_Gzip: | |
464 { | |
465 encoding = "gzip"; | |
466 GzipCompressor compressor; | |
467 compressor.Compress(compressed, buffer, length); | |
468 break; | |
469 } | |
470 | |
471 default: | |
472 throw OrthancException(ErrorCode_InternalError); | |
473 } | |
474 | |
475 LOG(TRACE) << "Compressing a HTTP answer using " << encoding; | |
476 | |
477 // The body is empty, do not use HTTP compression | |
478 if (compressed.size() == 0) | |
479 { | |
480 AnswerEmpty(); | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
481 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
482 else |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
483 { |
1521 | 484 stateMachine_.AddHeader("Content-Encoding", encoding); |
485 stateMachine_.SetContentLength(compressed.size()); | |
486 stateMachine_.SendBody(compressed.c_str(), compressed.size()); | |
487 } | |
1511
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
488 |
1521 | 489 stateMachine_.CloseBody(); |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
490 } |
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
491 |
1521 | 492 |
493 void HttpOutput::Answer(const std::string& str) | |
1511
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
494 { |
1521 | 495 Answer(str.size() == 0 ? NULL : str.c_str(), str.size()); |
1511
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
496 } |
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
497 |
1521 | 498 |
499 void HttpOutput::AnswerEmpty() | |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
500 { |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
501 stateMachine_.CloseBody(); |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
502 } |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
503 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
504 |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
505 void HttpOutput::StateMachine::CheckHeadersCompatibilityWithMultipart() const |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
506 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
507 for (std::list<std::string>::const_iterator |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
508 it = headers_.begin(); it != headers_.end(); ++it) |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
509 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
510 if (!Toolbox::StartsWith(*it, "Set-Cookie: ")) |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
511 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
512 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
513 "The only headers that can be set in multipart answers " |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
514 "are Set-Cookie (here: " + *it + " is set)"); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
515 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
516 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
517 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
518 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
519 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
520 static void PrepareMultipartMainHeader(std::string& boundary, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
521 std::string& contentTypeHeader, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
522 const std::string& subType, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
523 const std::string& contentType) |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
524 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
525 if (subType != "mixed" && |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
526 subType != "related") |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
527 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
528 throw OrthancException(ErrorCode_ParameterOutOfRange); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
529 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
530 |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
531 /** |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
532 * Fix for issue 54 ("Decide what to do wrt. quoting of multipart |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
533 * answers"). The "type" parameter in the "Content-Type" HTTP |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
534 * header must be quoted if it contains a forward slash "/". This |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
535 * is necessary for DICOMweb compatibility with OsiriX, but breaks |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
536 * compatibility with old releases of the client in the Orthanc |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
537 * DICOMweb plugin <= 0.3 (releases >= 0.4 work fine). |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
538 * |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
539 * Full history is available at the following locations: |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
540 * - In changeset 2248:69b0f4e8a49b: |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
541 * # hg history -v -r 2248 |
4476
c1f36fd13730
migrate remaining links to issues in bitbucket to mercurial server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
542 * - https://bugs.orthanc-server.com/show_bug.cgi?id=54 |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
543 * - https://groups.google.com/d/msg/orthanc-users/65zhIM5xbKI/TU5Q1_LhAwAJ |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
544 **/ |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
545 std::string tmp; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
546 if (contentType.find('/') == std::string::npos) |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
547 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
548 // No forward slash in the content type |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
549 tmp = contentType; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
550 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
551 else |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
552 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
553 // Quote the content type because of the forward slash |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
554 tmp = "\"" + contentType + "\""; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
555 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
556 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
557 boundary = Toolbox::GenerateUuid() + "-" + Toolbox::GenerateUuid(); |
3616 | 558 |
559 /** | |
560 * Fix for issue #165: "Encapsulation boundaries must not appear | |
561 * within the encapsulations, and must be no longer than 70 | |
562 * characters, not counting the two leading hyphens." | |
563 * https://tools.ietf.org/html/rfc1521 | |
4476
c1f36fd13730
migrate remaining links to issues in bitbucket to mercurial server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
564 * https://bugs.orthanc-server.com/show_bug.cgi?id=165 |
3616 | 565 **/ |
566 if (boundary.size() != 36 + 1 + 36) // one UUID contains 36 characters | |
567 { | |
568 throw OrthancException(ErrorCode_InternalError); | |
569 } | |
570 | |
571 boundary = boundary.substr(0, 70); | |
572 | |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
573 contentTypeHeader = ("multipart/" + subType + "; type=" + tmp + "; boundary=" + boundary); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
574 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
575 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
576 |
4672
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
577 void HttpOutput::StateMachine::StartStreamInternal(const std::string& contentType) |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
578 { |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
579 if (state_ != State_WritingHeader) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
580 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
581 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
582 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
583 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
584 if (status_ != HttpStatus_200_Ok) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
585 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
586 SendBody(NULL, 0); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
587 return; |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
588 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
589 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
590 stream_.OnHttpStatusReceived(status_); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
591 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
592 std::string header = "HTTP/1.1 200 OK\r\n"; |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
593 |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
594 if (keepAlive_) |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
595 { |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
596 #if ORTHANC_ENABLE_MONGOOSE == 1 |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
597 throw OrthancException(ErrorCode_NotImplemented, |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
598 "Multipart answers are not implemented together " |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
599 "with keep-alive connections if using Mongoose"); |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
600 |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
601 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
602 # if CIVETWEB_HAS_DISABLE_KEEP_ALIVE == 1 |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
603 // Turn off Keep-Alive for multipart answers |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
604 // https://github.com/civetweb/civetweb/issues/727 |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
605 stream_.DisableKeepAlive(); |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
606 header += "Connection: close\r\n"; |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
607 # else |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
608 // The function "mg_disable_keep_alive()" is not available, |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
609 // let's continue with Keep-Alive. Performance of WADO-RS will |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
610 // decrease. |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
611 header += "Connection: keep-alive\r\n"; |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
612 # endif |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
613 |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
614 #else |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3171
diff
changeset
|
615 # error Please support your embedded Web server here |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
616 #endif |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
617 } |
3171
81cd9a4f3018
always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
618 else |
81cd9a4f3018
always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
619 { |
81cd9a4f3018
always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
620 header += "Connection: close\r\n"; |
81cd9a4f3018
always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
621 } |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
622 |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
623 for (std::list<std::string>::const_iterator |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
624 it = headers_.begin(); it != headers_.end(); ++it) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
625 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
626 header += *it; |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
627 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
628 |
4672
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
629 header += ("Content-Type: " + contentType + "\r\n\r\n"); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
630 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
631 stream_.Send(true, header.c_str(), header.size()); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
632 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
633 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
634 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
635 void HttpOutput::StateMachine::StartMultipart(const std::string& subType, |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
636 const std::string& contentType) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
637 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
638 CheckHeadersCompatibilityWithMultipart(); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
639 |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
640 std::string contentTypeHeader; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
641 PrepareMultipartMainHeader(multipartBoundary_, contentTypeHeader, subType, contentType); |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
642 multipartContentType_ = contentType; |
4672
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
643 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
644 StartStreamInternal(contentTypeHeader); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
645 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
646 state_ = State_WritingMultipart; |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
647 } |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
648 |
4672
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
649 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
650 void HttpOutput::StateMachine::StartStream(const std::string& contentType) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
651 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
652 StartStreamInternal(contentType); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
653 state_ = State_WritingStream; |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
654 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
655 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
656 |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
657 static void PrepareMultipartItemHeader(std::string& target, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
658 size_t length, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
659 const std::map<std::string, std::string>& headers, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
660 const std::string& boundary, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
661 const std::string& contentType) |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
662 { |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
663 target = "--" + boundary + "\r\n"; |
1882
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
664 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
665 bool hasContentType = false; |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
666 bool hasContentLength = false; |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
667 bool hasMimeVersion = false; |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
668 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
669 for (std::map<std::string, std::string>::const_iterator |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
670 it = headers.begin(); it != headers.end(); ++it) |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
671 { |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
672 target += it->first + ": " + it->second + "\r\n"; |
1882
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
673 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
674 std::string tmp; |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
675 Toolbox::ToLowerCase(tmp, it->first); |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
676 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
677 if (tmp == "content-type") |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
678 { |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
679 hasContentType = true; |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
680 } |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
681 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
682 if (tmp == "content-length") |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
683 { |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
684 hasContentLength = true; |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
685 } |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
686 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
687 if (tmp == "mime-version") |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
688 { |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
689 hasMimeVersion = true; |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
690 } |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
691 } |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
692 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
693 if (!hasContentType) |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
694 { |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
695 target += "Content-Type: " + contentType + "\r\n"; |
1882
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
696 } |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
697 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
698 if (!hasContentLength) |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
699 { |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
700 target += "Content-Length: " + boost::lexical_cast<std::string>(length) + "\r\n"; |
1882
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
701 } |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
702 |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
703 if (!hasMimeVersion) |
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
704 { |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
705 target += "MIME-Version: 1.0\r\n\r\n"; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
706 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
707 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
708 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
709 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
710 void HttpOutput::StateMachine::SendMultipartItem(const void* item, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
711 size_t length, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
712 const std::map<std::string, std::string>& headers) |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
713 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
714 if (state_ != State_WritingMultipart) |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
715 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
716 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
1882
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
717 } |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
718 |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
719 std::string header; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
720 PrepareMultipartItemHeader(header, length, headers, multipartBoundary_, multipartContentType_); |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
721 stream_.Send(false, header.c_str(), header.size()); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
722 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
723 if (length > 0) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
724 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
725 stream_.Send(false, item, length); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
726 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
727 |
1882
5cf2bd0abfa2
OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1875
diff
changeset
|
728 stream_.Send(false, "\r\n", 2); |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
729 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
730 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
731 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
732 void HttpOutput::StateMachine::CloseMultipart() |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
733 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
734 if (state_ != State_WritingMultipart) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
735 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
736 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
737 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
738 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
739 // The two lines below might throw an exception, if the client has |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
740 // closed the connection. Such an error is ignored. |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
741 try |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
742 { |
1832
b7da58699f92
Fix formatting of multipart HTTP answers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1645
diff
changeset
|
743 std::string header = "--" + multipartBoundary_ + "--\r\n"; |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
744 stream_.Send(false, header.c_str(), header.size()); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
745 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
746 catch (OrthancException&) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
747 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
748 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
749 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
750 state_ = State_Done; |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
751 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
752 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
753 |
4672
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
754 void HttpOutput::StateMachine::SendStreamItem(const void* data, |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
755 size_t size) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
756 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
757 if (state_ != State_WritingStream) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
758 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
759 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
760 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
761 else |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
762 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
763 if (size > 0) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
764 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
765 stream_.Send(false, data, size); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
766 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
767 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
768 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
769 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
770 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
771 void HttpOutput::StateMachine::CloseStream() |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
772 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
773 if (state_ != State_WritingStream) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
774 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
775 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
776 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
777 else |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
778 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
779 state_ = State_Done; |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
780 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
781 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
782 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
783 |
3380
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
784 static void AnswerStreamAsBuffer(HttpOutput& output, |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
785 IHttpStreamAnswer& stream) |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
786 { |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
787 ChunkedBuffer buffer; |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
788 |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
789 while (stream.ReadNextChunk()) |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
790 { |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
791 if (stream.GetChunkSize() > 0) |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
792 { |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
793 buffer.AddChunk(stream.GetChunkContent(), stream.GetChunkSize()); |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
794 } |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
795 } |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
796 |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
797 std::string s; |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
798 buffer.Flatten(s); |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
799 |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
800 output.SetContentType(stream.GetContentType()); |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
801 |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
802 std::string filename; |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
803 if (stream.HasContentFilename(filename)) |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
804 { |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
805 output.SetContentFilename(filename.c_str()); |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
806 } |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
807 |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
808 output.Answer(s); |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
809 } |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
810 |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
811 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
812 void HttpOutput::Answer(IHttpStreamAnswer& stream) |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
813 { |
1523
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
814 HttpCompression compression = stream.SetupHttpCompression(isGzipAllowed_, isDeflateAllowed_); |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
815 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
816 switch (compression) |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
817 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
818 case HttpCompression_None: |
3380
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
819 { |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
820 if (isGzipAllowed_ || isDeflateAllowed_) |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
821 { |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
822 // New in Orthanc 1.5.7: Compress streams without built-in |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
823 // compression, if requested by the "Accept-Encoding" HTTP |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
824 // header |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
825 AnswerStreamAsBuffer(*this, stream); |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
826 return; |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
827 } |
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
828 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
829 break; |
3380
0528a6c36f3d
HTTP header "Accept-Encoding" is honored for streams without built-in support for compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
830 } |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
831 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
832 case HttpCompression_Gzip: |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
833 stateMachine_.AddHeader("Content-Encoding", "gzip"); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
834 break; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
835 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
836 case HttpCompression_Deflate: |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
837 stateMachine_.AddHeader("Content-Encoding", "deflate"); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
838 break; |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
839 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
840 default: |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
841 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
842 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
843 |
1523
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
844 stateMachine_.SetContentLength(stream.GetContentLength()); |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
845 |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
846 std::string contentType = stream.GetContentType(); |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
847 if (contentType.empty()) |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
848 { |
2905
ae20fccdd867
refactoring mime types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2805
diff
changeset
|
849 contentType = MIME_BINARY; |
1523
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
850 } |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
851 |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
852 stateMachine_.SetContentType(contentType.c_str()); |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
853 |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
854 std::string filename; |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
855 if (stream.HasContentFilename(filename)) |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
856 { |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
857 SetContentFilename(filename.c_str()); |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
858 } |
c388502a066d
testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1522
diff
changeset
|
859 |
1519
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
860 while (stream.ReadNextChunk()) |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
861 { |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
862 stateMachine_.SendBody(stream.GetChunkContent(), |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
863 stream.GetChunkSize()); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
864 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
865 |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
866 stateMachine_.CloseBody(); |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
867 } |
8bd0d897763f
refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
868 |
3528
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
869 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
870 void HttpOutput::AnswerMultipartWithoutChunkedTransfer( |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
871 const std::string& subType, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
872 const std::string& contentType, |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
873 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:
3425
diff
changeset
|
874 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:
3425
diff
changeset
|
875 const std::vector<const std::map<std::string, std::string>*>& headers) |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
876 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
877 if (parts.size() != sizes.size()) |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
878 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
879 throw OrthancException(ErrorCode_ParameterOutOfRange); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
880 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
881 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
882 stateMachine_.CheckHeadersCompatibilityWithMultipart(); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
883 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
884 std::string boundary, contentTypeHeader; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
885 PrepareMultipartMainHeader(boundary, contentTypeHeader, subType, contentType); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
886 SetContentType(contentTypeHeader); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
887 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
888 std::map<std::string, std::string> empty; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
889 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
890 ChunkedBuffer chunked; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
891 for (size_t i = 0; i < parts.size(); i++) |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
892 { |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
893 std::string partHeader; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
894 PrepareMultipartItemHeader(partHeader, sizes[i], headers[i] == NULL ? empty : *headers[i], |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
895 boundary, contentType); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
896 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
897 chunked.AddChunk(partHeader); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
898 chunked.AddChunk(parts[i], sizes[i]); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
899 chunked.AddChunk("\r\n"); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
900 } |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
901 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
902 chunked.AddChunk("--" + boundary + "--\r\n"); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
903 |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
904 std::string body; |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
905 chunked.Flatten(body); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
906 Answer(body); |
f6fe095f7130
don't open a multipart stream if plugin only sends one part
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3425
diff
changeset
|
907 } |
4672
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
908 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
909 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
910 void HttpOutput::AnswerWithoutBuffering(IHttpStreamAnswer& stream) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
911 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
912 std::string contentType = stream.GetContentType(); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
913 if (contentType.empty()) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
914 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
915 contentType = MIME_BINARY; |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
916 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
917 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
918 std::string filename; |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
919 if (stream.HasContentFilename(filename)) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
920 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
921 stateMachine_.AddHeader("Content-Disposition", "filename=\"" + std::string(filename) + "\""); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
922 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
923 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
924 stateMachine_.StartStream(contentType.c_str()); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
925 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
926 while (stream.ReadNextChunk()) |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
927 { |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
928 stateMachine_.SendStreamItem(stream.GetChunkContent(), stream.GetChunkSize()); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
929 } |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
930 |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
931 stateMachine_.CloseStream(); |
d9942d48fea7
ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4476
diff
changeset
|
932 } |
0 | 933 } |