annotate Core/HttpServer/HttpOutput.cpp @ 3508:70524b4acc72

Name of temporary files now include the process ID to ease design of scripts cleaning /tmp
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Aug 2019 11:41:26 +0200
parents 2f6dcb9c8cc1
children f6fe095f7130
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
4 * Department, University Hospital of Liege, Belgium
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
11 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
12 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
13 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
16 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
20 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
21 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
22 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
34 #include "../PrecompiledHeaders.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "HttpOutput.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
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
37 #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
38 #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
39 #include "../Compression/ZlibCompressor.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1430
diff changeset
40 #include "../Logging.h"
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1430
diff changeset
41 #include "../OrthancException.h"
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1430
diff changeset
42 #include "../Toolbox.h"
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1430
diff changeset
43
324
64925c94825c api improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
44 #include <iostream>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include <vector>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #include <stdio.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 #include <boost/lexical_cast.hpp>
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1430
diff changeset
48
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
3178
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
50 #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
51 # 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
52 # 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
53 # endif
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
54 #endif
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
55
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
56
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
57 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
59 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
60 bool isKeepAlive) :
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
61 stream_(stream),
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
62 state_(State_WritingHeader),
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
63 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
64 hasContentLength_(false),
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
65 contentPosition_(0),
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
66 keepAlive_(isKeepAlive)
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
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
70 HttpOutput::StateMachine::~StateMachine()
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
71 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
72 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
73 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
74 //asm volatile ("int3;");
1200
1e1390665639 fix sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1115
diff changeset
75 //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
76 }
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 (hasContentLength_ && contentPosition_ != contentLength_)
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
79 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
80 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
81 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
82 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
83
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
84
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
85 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
86 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
87 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
88 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
89 throw OrthancException(ErrorCode_BadSequenceOfCalls);
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
90 }
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
91
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
92 status_ = status;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
93 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
94
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
95
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
96 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
97 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
98 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
99 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
100 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
101 }
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
102
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
103 hasContentLength_ = true;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
104 contentLength_ = length;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
105 }
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
106
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
107 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
108 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
109 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
110 }
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 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
113 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
114 // 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
115 AddHeader("Content-Disposition", "filename=\"" + std::string(filename) + "\"");
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
116 }
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
117
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
118 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
119 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
120 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
121 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
122 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
123 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
124 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
125
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
126 // TODO Escape "=" characters
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
127 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
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
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
131 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
132 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
133 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
134 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
135 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
136 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
137 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
138
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
139 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
140 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
141
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
142 void HttpOutput::StateMachine::ClearHeaders()
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
143 {
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
144 if (state_ != State_WritingHeader)
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
145 {
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
146 throw OrthancException(ErrorCode_BadSequenceOfCalls);
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
147 }
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
148
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
149 headers_.clear();
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
150 }
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
151
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
152 void HttpOutput::StateMachine::SendBody(const void* buffer, size_t length)
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
153 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
154 if (state_ == State_Done)
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
155 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
156 if (length == 0)
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
157 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
158 return;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
159 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
160 else
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
161 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
162 throw OrthancException(ErrorCode_BadSequenceOfCalls,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
163 "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
164 "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
165 }
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
166 }
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
167
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
168 if (state_ == State_WritingMultipart)
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
169 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
170 throw OrthancException(ErrorCode_InternalError);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
171 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
172
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
173 if (state_ == State_WritingHeader)
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
174 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
175 // 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
176
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
177 stream_.OnHttpStatusReceived(status_);
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
178
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
179 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
180 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
181 " " + 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
182 "\r\n";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
183
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
184 if (keepAlive_)
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
185 {
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
186 s += "Connection: keep-alive\r\n";
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
187 }
3171
81cd9a4f3018 always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
188 else
81cd9a4f3018 always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
189 {
81cd9a4f3018 always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
190 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
191 }
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
192
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
193 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
194 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
195 {
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
196 s += *it;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
197 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
198
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
199 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
200 {
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
201 hasContentLength_ = false;
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
202 }
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
203
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
204 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
205 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
206
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
207 stream_.Send(true, s.c_str(), s.size());
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
208 state_ = State_WritingBody;
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
209 }
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
210
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
211 if (hasContentLength_ &&
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
212 contentPosition_ + length > contentLength_)
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
213 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
214 throw OrthancException(ErrorCode_BadSequenceOfCalls,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
215 "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
216 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
217
910
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
218 if (length > 0)
28a52982196e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
219 {
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 910
diff changeset
220 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
221 contentPosition_ += length;
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
222 }
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
223
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
224 if (!hasContentLength_ ||
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
225 contentPosition_ == contentLength_)
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
226 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
227 state_ = State_Done;
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
228 }
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
229 }
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 324
diff changeset
230
207
7f74209ea0f8 RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
231
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
232 void HttpOutput::StateMachine::CloseBody()
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
233 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
234 switch (state_)
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
235 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
236 case State_WritingHeader:
1522
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
237 SetContentLength(0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
238 SendBody(NULL, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
239 break;
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
240
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
241 case State_WritingBody:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
242 if (!hasContentLength_ ||
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
243 contentPosition_ == contentLength_)
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
244 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
245 state_ = State_Done;
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 else
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
248 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
249 throw OrthancException(ErrorCode_BadSequenceOfCalls,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
250 "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
251 }
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 break;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
254
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
255 case State_WritingMultipart:
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
256 throw OrthancException(ErrorCode_BadSequenceOfCalls,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
257 "Cannot invoke CloseBody() with multipart outputs");
1519
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 case State_Done:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
260 return; // Ignore
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
261
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
262 default:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
263 throw OrthancException(ErrorCode_InternalError);
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 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
266
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
267
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
268 HttpCompression HttpOutput::GetPreferredCompression(size_t bodySize) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
269 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
270 #if 0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
271 // TODO Do not compress small files?
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
272 if (bodySize < 512)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
273 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
274 return HttpCompression_None;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
275 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
276 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
277
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
278 // Prefer "gzip" over "deflate" if the choice is offered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
279
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
280 if (isGzipAllowed_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
281 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
282 return HttpCompression_Gzip;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
283 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
284 else if (isDeflateAllowed_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
285 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
286 return HttpCompression_Deflate;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
287 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
288 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
289 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
290 return HttpCompression_None;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
291 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
292 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
293
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
294
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 911
diff changeset
295 void HttpOutput::SendMethodNotAllowed(const std::string& allowed)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
297 stateMachine_.ClearHeaders();
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
298 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
299 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
300 stateMachine_.SendBody(NULL, 0);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
1567
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1523
diff changeset
304 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
305 const char* message,
9c5d93510414 If error while calling the REST API, the answer body contains an error description
jodogne
parents: 1523
diff changeset
306 size_t messageSize)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
1954
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1953
diff changeset
308 if (status == HttpStatus_301_MovedPermanently ||
3425
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3416
diff changeset
309 //status == HttpStatus_401_Unauthorized ||
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
310 status == HttpStatus_405_MethodNotAllowed)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
312 throw OrthancException(ErrorCode_ParameterOutOfRange,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
313 "Please use the dedicated methods to this HTTP status code in HttpOutput");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
316 stateMachine_.SetHttpStatus(status);
1645
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1592
diff changeset
317 stateMachine_.SendBody(message, messageSize);
339
639272ef7615 answer raw buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
318 }
639272ef7615 answer raw buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
319
639272ef7615 answer raw buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
320
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 void HttpOutput::Redirect(const std::string& path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
323 stateMachine_.ClearHeaders();
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
324 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
325 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
326 stateMachine_.SendBody(NULL, 0);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
328
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
329
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
330 void HttpOutput::SendUnauthorized(const std::string& realm)
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
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_401_Unauthorized);
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
334 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
335 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
336 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
337
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2905
diff changeset
338
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
339 void HttpOutput::Answer(const void* buffer,
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
340 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
341 {
1511
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
342 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
343 {
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
344 AnswerEmpty();
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
345 return;
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
346 }
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
347
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
348 HttpCompression compression = GetPreferredCompression(length);
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
349
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
350 if (compression == HttpCompression_None)
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
351 {
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
352 stateMachine_.SetContentLength(length);
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
353 stateMachine_.SendBody(buffer, length);
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
354 return;
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
355 }
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
356
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
357 std::string compressed, encoding;
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
358
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
359 switch (compression)
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
360 {
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
361 case HttpCompression_Deflate:
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
362 {
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
363 encoding = "deflate";
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
364 ZlibCompressor compressor;
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
365 // Do not prefix the buffer with its uncompressed size, to be compatible with "deflate"
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
366 compressor.SetPrefixWithUncompressedSize(false);
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
367 compressor.Compress(compressed, buffer, length);
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
368 break;
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
369 }
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
370
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
371 case HttpCompression_Gzip:
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
372 {
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
373 encoding = "gzip";
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
374 GzipCompressor compressor;
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
375 compressor.Compress(compressed, buffer, length);
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
376 break;
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
377 }
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
378
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
379 default:
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
380 throw OrthancException(ErrorCode_InternalError);
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
381 }
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
382
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
383 LOG(TRACE) << "Compressing a HTTP answer using " << encoding;
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
384
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
385 // The body is empty, do not use HTTP compression
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
386 if (compressed.size() == 0)
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
387 {
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
388 AnswerEmpty();
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
389 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
390 else
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
391 {
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
392 stateMachine_.AddHeader("Content-Encoding", encoding);
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
393 stateMachine_.SetContentLength(compressed.size());
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
394 stateMachine_.SendBody(compressed.c_str(), compressed.size());
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
395 }
1511
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
396
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
397 stateMachine_.CloseBody();
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
398 }
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
399
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
400
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
401 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
402 {
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
403 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
404 }
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
405
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
406
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
407 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
408 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
409 stateMachine_.CloseBody();
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
410 }
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
411
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
412
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
413 void HttpOutput::StateMachine::StartMultipart(const std::string& subType,
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
414 const std::string& contentType)
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
415 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
416 if (subType != "mixed" &&
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
417 subType != "related")
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
418 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
419 throw OrthancException(ErrorCode_ParameterOutOfRange);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
420 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
421
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
422 if (state_ != State_WritingHeader)
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
423 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
424 throw OrthancException(ErrorCode_BadSequenceOfCalls);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
425 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
426
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
427 if (status_ != HttpStatus_200_Ok)
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
428 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
429 SendBody(NULL, 0);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
430 return;
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
431 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
432
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
433 stream_.OnHttpStatusReceived(status_);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
434
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
435 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
436
3154
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
437 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
438 {
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
439 #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
440 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
441 "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
442 "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
443
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
444 #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
445 # 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
446 // 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
447 // 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
448 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
449 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
450 # else
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
451 // 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
452 // 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
453 // decrease.
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
454 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
455 # endif
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
456
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
457 #else
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3171
diff changeset
458 # 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
459 #endif
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
460 }
3171
81cd9a4f3018 always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
461 else
81cd9a4f3018 always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
462 {
81cd9a4f3018 always add HTTP header "Connection: close" if keep-alive is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
463 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
464 }
3154
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
465
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
466 // Possibly add the cookies
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
467 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
468 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
469 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
470 if (!Toolbox::StartsWith(*it, "Set-Cookie: "))
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
471 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
472 throw OrthancException(ErrorCode_BadSequenceOfCalls,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
473 "The only headers that can be set in multipart answers "
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
474 "are Set-Cookie (here: " + *it + " is set)");
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
475 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
476
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
477 header += *it;
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
478 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
479
2805
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
480 /**
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
481 * Fix for issue 54 ("Decide what to do wrt. quoting of multipart
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
482 * answers"). The "type" parameter in the "Content-Type" HTTP
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
483 * header must be quoted if it contains a forward slash "/". This
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
484 * is necessary for DICOMweb compatibility with OsiriX, but breaks
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
485 * compatibility with old releases of the client in the Orthanc
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
486 * DICOMweb plugin <= 0.3 (releases >= 0.4 work fine).
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
487 *
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
488 * Full history is available at the following locations:
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
489 * - In changeset 2248:69b0f4e8a49b:
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
490 * # hg history -v -r 2248
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
491 * - https://bitbucket.org/sjodogne/orthanc/issues/54/
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
492 * - https://groups.google.com/d/msg/orthanc-users/65zhIM5xbKI/TU5Q1_LhAwAJ
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
493 **/
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
494 std::string tmp;
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
495 if (contentType.find('/') == std::string::npos)
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
496 {
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
497 // No forward slash in the content type
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
498 tmp = contentType;
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
499 }
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
500 else
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
501 {
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
502 // Quote the content type because of the forward slash
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
503 tmp = "\"" + contentType + "\"";
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
504 }
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
505
3416
541c787e2230 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3380
diff changeset
506 multipartBoundary_ = Toolbox::GenerateUuid() + "-" + Toolbox::GenerateUuid();
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
507 multipartContentType_ = contentType;
2805
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
508 header += ("Content-Type: multipart/" + subType + "; type=" +
e02af4ca8003 Fix issue #54 (quoting multipart answers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2512
diff changeset
509 tmp + "; boundary=" + multipartBoundary_ + "\r\n\r\n");
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
510
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
511 stream_.Send(true, header.c_str(), header.size());
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
512 state_ = State_WritingMultipart;
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
513 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
514
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
515
1882
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
516 void HttpOutput::StateMachine::SendMultipartItem(const void* item,
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
517 size_t length,
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
518 const std::map<std::string, std::string>& headers)
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
519 {
1882
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
520 if (state_ != State_WritingMultipart)
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
521 {
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
522 throw OrthancException(ErrorCode_BadSequenceOfCalls);
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
523 }
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
524
1832
b7da58699f92 Fix formatting of multipart HTTP answers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
525 std::string header = "--" + multipartBoundary_ + "\r\n";
1882
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
526
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
527 bool hasContentType = false;
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
528 bool hasContentLength = false;
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
529 bool hasMimeVersion = false;
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
530
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
531 for (std::map<std::string, std::string>::const_iterator
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
532 it = headers.begin(); it != headers.end(); ++it)
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
533 {
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
534 header += it->first + ": " + it->second + "\r\n";
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
535
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
536 std::string tmp;
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
537 Toolbox::ToLowerCase(tmp, it->first);
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
538
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
539 if (tmp == "content-type")
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
540 {
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
541 hasContentType = true;
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
542 }
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
543
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
544 if (tmp == "content-length")
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
545 {
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
546 hasContentLength = true;
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
547 }
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
548
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
549 if (tmp == "mime-version")
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
550 {
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
551 hasMimeVersion = true;
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
552 }
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
553 }
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
554
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
555 if (!hasContentType)
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
556 {
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
557 header += "Content-Type: " + multipartContentType_ + "\r\n";
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
558 }
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
559
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
560 if (!hasContentLength)
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
561 {
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
562 header += "Content-Length: " + boost::lexical_cast<std::string>(length) + "\r\n";
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
563 }
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
564
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
565 if (!hasMimeVersion)
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
566 {
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
567 header += "MIME-Version: 1.0\r\n\r\n";
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
568 }
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
569
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
570 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
571
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
572 if (length > 0)
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
573 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
574 stream_.Send(false, item, length);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
575 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
576
1882
5cf2bd0abfa2 OrthancPluginSendMultipartItem2 for DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1875
diff changeset
577 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
578 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
579
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 void HttpOutput::StateMachine::CloseMultipart()
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 if (state_ != State_WritingMultipart)
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
584 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
585 throw OrthancException(ErrorCode_BadSequenceOfCalls);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
586 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
587
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
588 // 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
589 // 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
590 try
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
591 {
1832
b7da58699f92 Fix formatting of multipart HTTP answers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1645
diff changeset
592 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
593 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
594 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
595 catch (OrthancException&)
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
596 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
597 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
598
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
599 state_ = State_Done;
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
600 }
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
601
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
602
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
603 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
604 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
605 {
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
606 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
607
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
608 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
609 {
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
610 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
611 {
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
612 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
613 }
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
614 }
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
615
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
616 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
617 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
618
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
619 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
620
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
621 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
622 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
623 {
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
624 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
625 }
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
626
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
627 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
628 }
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
629
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
630
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
631 void HttpOutput::Answer(IHttpStreamAnswer& stream)
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
632 {
1523
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
633 HttpCompression compression = stream.SetupHttpCompression(isGzipAllowed_, isDeflateAllowed_);
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
634
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
635 switch (compression)
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
636 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
637 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
638 {
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
639 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
640 {
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
641 // 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
642 // 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
643 // 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
644 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
645 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
646 }
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
647
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
648 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
649 }
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
650
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
651 case HttpCompression_Gzip:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
652 stateMachine_.AddHeader("Content-Encoding", "gzip");
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
653 break;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
654
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
655 case HttpCompression_Deflate:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
656 stateMachine_.AddHeader("Content-Encoding", "deflate");
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
657 break;
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
658
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
659 default:
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
660 throw OrthancException(ErrorCode_ParameterOutOfRange);
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
661 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
662
1523
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
663 stateMachine_.SetContentLength(stream.GetContentLength());
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
664
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
665 std::string contentType = stream.GetContentType();
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
666 if (contentType.empty())
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
667 {
2905
ae20fccdd867 refactoring mime types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2805
diff changeset
668 contentType = MIME_BINARY;
1523
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
669 }
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
670
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
671 stateMachine_.SetContentType(contentType.c_str());
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
672
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
673 std::string filename;
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
674 if (stream.HasContentFilename(filename))
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
675 {
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
676 SetContentFilename(filename.c_str());
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
677 }
c388502a066d testing FilesystemHttpSender
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
678
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
679 while (stream.ReadNextChunk())
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
680 {
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
681 stateMachine_.SendBody(stream.GetChunkContent(),
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
682 stream.GetChunkSize());
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
683 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
684
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
685 stateMachine_.CloseBody();
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
686 }
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
687
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 }