Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/HttpServer.cpp @ 5447:dacdce5e5c22
now accepting GET requests on the /tools/create-archive route and siblings
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 24 Nov 2023 18:14:52 +0100 |
parents | 0ea402b4d901 |
children | 9ffd6d18daf3 |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5119
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5119
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
136 | 12 * |
0 | 13 * This program is distributed in the hope that it will be useful, but |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
0 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
0 | 21 **/ |
22 | |
23 | |
24 // http://en.highscore.de/cpp/boost/stringhandling.html | |
25 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
26 #include "../PrecompiledHeaders.h" |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
27 #include "HttpServer.h" |
0 | 28 |
3357
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3356
diff
changeset
|
29 #include "../ChunkedBuffer.h" |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3356
diff
changeset
|
30 #include "../FileBuffer.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
31 #include "../Logging.h" |
2895 | 32 #include "../OrthancException.h" |
3357
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3356
diff
changeset
|
33 #include "../TemporaryFile.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
34 #include "HttpToolbox.h" |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
35 #include "IHttpHandler.h" |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
36 #include "MultipartStreamReader.h" |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
37 #include "StringHttpOutput.h" |
5097
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
38 #include <algorithm> |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
39 |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
40 #if ORTHANC_ENABLE_PUGIXML == 1 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
41 # include "IWebDavBucket.h" |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
42 #endif |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
43 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
44 #if ORTHANC_ENABLE_MONGOOSE == 1 |
3069 | 45 # include <mongoose.h> |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
46 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
47 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
3069 | 48 # include <civetweb.h> |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
49 # define MONGOOSE_USE_CALLBACKS 1 |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
50 # 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:
3154
diff
changeset
|
51 # 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:
3154
diff
changeset
|
52 # endif |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
53 # if !defined(CIVETWEB_HAS_WEBDAV_WRITING) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
54 # error Macro CIVETWEB_HAS_WEBDAV_WRITING must be defined |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
55 # endif |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
56 #else |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
57 # error "Either Mongoose or Civetweb must be enabled to compile this file" |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
58 #endif |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
59 |
0 | 60 #include <algorithm> |
61 #include <boost/algorithm/string.hpp> | |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
62 #include <boost/algorithm/string/predicate.hpp> |
3672
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
63 #include <boost/filesystem.hpp> |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
64 #include <boost/lexical_cast.hpp> |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
65 #include <boost/thread.hpp> |
0 | 66 #include <iostream> |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
67 #include <stdio.h> |
0 | 68 #include <string.h> |
69 | |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
70 #if !defined(ORTHANC_ENABLE_SSL) |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
71 # error The macro ORTHANC_ENABLE_SSL must be defined |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
72 #endif |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2136
diff
changeset
|
73 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
74 #if ORTHANC_ENABLE_SSL == 1 |
3801
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
75 # include <openssl/opensslv.h> |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
76 # include <openssl/err.h> |
4741
a6b7c29f5118
compiler warning about openssl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4616
diff
changeset
|
77 |
a6b7c29f5118
compiler warning about openssl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4616
diff
changeset
|
78 # if OPENSSL_VERSION_NUMBER < 0x30000000L |
5073
859f3668c181
replaced macro "#warning" by "#pragma message" for Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
79 # if defined(_MSC_VER) |
859f3668c181
replaced macro "#warning" by "#pragma message" for Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
80 # pragma message("You are linking Orthanc against OpenSSL 1.x, whose license is incompatible with the GPLv3+ used by Orthanc >= 1.10.0. Please update to OpenSSL 3.x, that uses the Apache 2 license.") |
859f3668c181
replaced macro "#warning" by "#pragma message" for Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
81 # else |
859f3668c181
replaced macro "#warning" by "#pragma message" for Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
82 # warning You are linking Orthanc against OpenSSL 1.x, whose license is incompatible with the GPLv3+ used by Orthanc >= 1.10.0. Please update to OpenSSL 3.x, that uses the Apache 2 license. |
859f3668c181
replaced macro "#warning" by "#pragma message" for Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
83 # endif |
4741
a6b7c29f5118
compiler warning about openssl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4616
diff
changeset
|
84 # endif |
a6b7c29f5118
compiler warning about openssl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4616
diff
changeset
|
85 |
748
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
86 #endif |
0 | 87 |
59 | 88 #define ORTHANC_REALM "Orthanc Secure Area" |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
89 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
90 |
59 | 91 namespace Orthanc |
0 | 92 { |
93 namespace | |
94 { | |
95 // Anonymous namespace to avoid clashes between compilation modules | |
911 | 96 class MongooseOutputStream : public IHttpOutputStream |
0 | 97 { |
98 private: | |
99 struct mg_connection* connection_; | |
100 | |
911 | 101 public: |
4201 | 102 explicit MongooseOutputStream(struct mg_connection* connection) : |
103 connection_(connection) | |
911 | 104 { |
105 } | |
106 | |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
107 virtual void Send(bool isHeader, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
108 const void* buffer, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
109 size_t length) ORTHANC_OVERRIDE |
0 | 110 { |
217 | 111 if (length > 0) |
112 { | |
5097
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
113 // mg_write does not support buffers > 2GB (INT_MAX) -> need to split it |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
114 size_t offset = 0; |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
115 size_t remainingSize = length; |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
116 |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
117 while (remainingSize > 0) |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1363
diff
changeset
|
118 { |
5097
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
119 size_t packetSize = std::min(remainingSize, static_cast<size_t>(INT_MAX)); |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
120 |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
121 int status = mg_write(connection_, &(reinterpret_cast<const char*>(buffer)[offset]), packetSize); |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
122 |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
123 if (status != static_cast<int>(packetSize)) |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
124 { |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
125 // status == 0 when the connection has been closed, -1 on error |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
126 throw OrthancException(ErrorCode_NetworkProtocol); |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
127 } |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
128 |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
129 offset += packetSize; |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
130 remainingSize -= packetSize; |
d842e4446e63
Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB)
Alain Mazy <am@osimis.io>
parents:
5073
diff
changeset
|
131 } |
217 | 132 } |
0 | 133 } |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
134 |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
135 virtual void OnHttpStatusReceived(HttpStatus status) ORTHANC_OVERRIDE |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
136 { |
911 | 137 // Ignore this |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
138 } |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
139 |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
140 virtual void DisableKeepAlive() ORTHANC_OVERRIDE |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
141 { |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
142 #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:
3145
diff
changeset
|
143 throw OrthancException(ErrorCode_NotImplemented, |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
144 "Only available if using CivetWeb"); |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
145 |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
146 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
147 # if CIVETWEB_HAS_DISABLE_KEEP_ALIVE == 1 |
4616
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
148 # if CIVETWEB_VERSION_MAJOR == 1 && CIVETWEB_VERSION_MINOR <= 13 // From "civetweb-1.13.patch" |
3154
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
149 mg_disable_keep_alive(connection_); |
4616
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
150 # else |
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
151 /** |
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
152 * Function "mg_disable_keep_alive()" contributed by Sebastien |
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
153 * Jodogne was renamed as "mg_disable_connection_keep_alive()" |
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
154 * in the official CivetWeb repository: |
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
155 * https://github.com/civetweb/civetweb/commit/78d45f4c4b0ab821f4f259b21ad3783f6d6c556a |
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
156 **/ |
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
157 mg_disable_connection_keep_alive(connection_); |
57b1a36645ae
upgrade to civetweb 1.14
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4454
diff
changeset
|
158 # endif |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
159 # else |
4449
6a6017027162
"#warning" is not available on Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
160 # if defined(__GNUC__) || defined(__clang__) |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
161 # warning The function "mg_disable_keep_alive()" is not available, DICOMweb might run slowly |
4449
6a6017027162
"#warning" is not available on Visual Studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
162 # endif |
3178
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
163 throw OrthancException(ErrorCode_NotImplemented, |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
164 "Only available if using a patched version of CivetWeb"); |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
165 # endif |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
166 |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
167 #else |
6d558598d713
Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3154
diff
changeset
|
168 # 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:
3145
diff
changeset
|
169 #endif |
6e8822be2f08
Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3145
diff
changeset
|
170 } |
0 | 171 }; |
172 | |
173 | |
174 enum PostDataStatus | |
175 { | |
176 PostDataStatus_Success, | |
177 PostDataStatus_NoLength, | |
178 PostDataStatus_Pending, | |
179 PostDataStatus_Failure | |
180 }; | |
181 } | |
182 | |
183 | |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
184 namespace |
0 | 185 { |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
186 class ChunkedFile : public ChunkedBuffer |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
187 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
188 private: |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
189 std::string filename_; |
0 | 190 |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
191 public: |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
192 explicit ChunkedFile(const std::string& filename) : |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
193 filename_(filename) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
194 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
195 } |
0 | 196 |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
197 const std::string& GetFilename() const |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
198 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
199 return filename_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
200 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
201 }; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
202 } |
0 | 203 |
204 | |
205 | |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
206 class HttpServer::ChunkStore : public boost::noncopyable |
0 | 207 { |
208 private: | |
209 typedef std::list<ChunkedFile*> Content; | |
210 Content content_; | |
211 unsigned int numPlaces_; | |
212 | |
213 boost::mutex mutex_; | |
214 std::set<std::string> discardedFiles_; | |
215 | |
216 void Clear() | |
217 { | |
218 for (Content::iterator it = content_.begin(); | |
656 | 219 it != content_.end(); ++it) |
0 | 220 { |
221 delete *it; | |
222 } | |
223 } | |
224 | |
225 Content::iterator Find(const std::string& filename) | |
226 { | |
227 for (Content::iterator it = content_.begin(); | |
656 | 228 it != content_.end(); ++it) |
0 | 229 { |
230 if ((*it)->GetFilename() == filename) | |
231 { | |
232 return it; | |
233 } | |
234 } | |
235 | |
236 return content_.end(); | |
237 } | |
238 | |
239 void Remove(const std::string& filename) | |
240 { | |
241 Content::iterator it = Find(filename); | |
242 if (it != content_.end()) | |
243 { | |
244 delete *it; | |
245 content_.erase(it); | |
246 } | |
247 } | |
248 | |
249 public: | |
250 ChunkStore() | |
251 { | |
252 numPlaces_ = 10; | |
253 } | |
254 | |
255 ~ChunkStore() | |
256 { | |
257 Clear(); | |
258 } | |
259 | |
260 PostDataStatus Store(std::string& completed, | |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
261 const void* chunkData, |
0 | 262 size_t chunkSize, |
263 const std::string& filename, | |
264 size_t filesize) | |
265 { | |
266 boost::mutex::scoped_lock lock(mutex_); | |
267 | |
268 std::set<std::string>::iterator wasDiscarded = discardedFiles_.find(filename); | |
269 if (wasDiscarded != discardedFiles_.end()) | |
270 { | |
271 discardedFiles_.erase(wasDiscarded); | |
272 return PostDataStatus_Failure; | |
273 } | |
274 | |
275 ChunkedFile* f; | |
276 Content::iterator it = Find(filename); | |
277 if (it == content_.end()) | |
278 { | |
279 f = new ChunkedFile(filename); | |
280 | |
281 // Make some room | |
282 if (content_.size() >= numPlaces_) | |
283 { | |
284 discardedFiles_.insert(content_.front()->GetFilename()); | |
285 delete content_.front(); | |
286 content_.pop_front(); | |
287 } | |
288 | |
289 content_.push_back(f); | |
290 } | |
291 else | |
292 { | |
293 f = *it; | |
294 } | |
295 | |
296 f->AddChunk(chunkData, chunkSize); | |
297 | |
298 if (f->GetNumBytes() > filesize) | |
299 { | |
300 Remove(filename); | |
301 } | |
302 else if (f->GetNumBytes() == filesize) | |
303 { | |
304 f->Flatten(completed); | |
305 Remove(filename); | |
306 return PostDataStatus_Success; | |
307 } | |
308 | |
309 return PostDataStatus_Pending; | |
310 } | |
311 | |
312 /*void Print() | |
313 { | |
314 boost::mutex::scoped_lock lock(mutex_); | |
315 | |
316 printf("ChunkStore status:\n"); | |
317 for (Content::const_iterator i = content_.begin(); | |
318 i != content_.end(); i++) | |
319 { | |
320 printf(" [%s]: %d\n", (*i)->GetFilename().c_str(), (*i)->GetNumBytes()); | |
321 } | |
322 printf("-----\n"); | |
323 }*/ | |
324 }; | |
325 | |
326 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
327 struct HttpServer::PImpl |
0 | 328 { |
329 struct mg_context *context_; | |
330 ChunkStore chunkStore_; | |
4201 | 331 |
332 PImpl() : | |
333 context_(NULL) | |
334 { | |
335 } | |
0 | 336 }; |
337 | |
338 | |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
339 class HttpServer::MultipartFormDataHandler : public MultipartStreamReader::IHandler |
0 | 340 { |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
341 private: |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
342 IHttpHandler& handler_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
343 ChunkStore& chunkStore_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
344 const std::string& remoteIp_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
345 const std::string& username_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
346 const UriComponents& uri_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
347 bool isJQueryUploadChunk_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
348 std::string jqueryUploadFileName_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
349 size_t jqueryUploadFileSize_; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
350 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
351 void HandleInternal(const MultipartStreamReader::HttpHeaders& headers, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
352 const void* part, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
353 size_t size) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
354 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
355 StringHttpOutput stringOutput; |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
356 HttpOutput fakeOutput(stringOutput, false /* assume no keep-alive */, 0); |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
357 HttpToolbox::GetArguments getArguments; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
358 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
359 if (!handler_.Handle(fakeOutput, RequestOrigin_RestApi, remoteIp_.c_str(), username_.c_str(), |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
360 HttpMethod_Post, uri_, headers, getArguments, part, size)) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
361 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
362 throw OrthancException(ErrorCode_UnknownResource); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
363 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
364 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
365 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
366 public: |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
367 MultipartFormDataHandler(IHttpHandler& handler, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
368 ChunkStore& chunkStore, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
369 const std::string& remoteIp, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
370 const std::string& username, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
371 const UriComponents& uri, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
372 const MultipartStreamReader::HttpHeaders& headers) : |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
373 handler_(handler), |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
374 chunkStore_(chunkStore), |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
375 remoteIp_(remoteIp), |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
376 username_(username), |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
377 uri_(uri), |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
378 isJQueryUploadChunk_(false), |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
379 jqueryUploadFileSize_(0) // Dummy initialization |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
380 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
381 typedef HttpToolbox::Arguments::const_iterator Iterator; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
382 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
383 Iterator requestedWith = headers.find("x-requested-with"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
384 if (requestedWith != headers.end() && |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
385 requestedWith->second != "XMLHttpRequest") |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
386 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
387 throw OrthancException(ErrorCode_NetworkProtocol, "HTTP header \"X-Requested-With\" should be " |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
388 "\"XMLHttpRequest\" in multipart uploads"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
389 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
390 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
391 Iterator fileName = headers.find("x-file-name"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
392 Iterator fileSize = headers.find("x-file-size"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
393 if (fileName != headers.end() || |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
394 fileSize != headers.end()) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
395 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
396 if (fileName == headers.end()) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
397 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
398 throw OrthancException(ErrorCode_NetworkProtocol, "HTTP header \"X-File-Name\" is missing"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
399 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
400 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
401 if (fileSize == headers.end()) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
402 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
403 throw OrthancException(ErrorCode_NetworkProtocol, "HTTP header \"X-File-Size\" is missing"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
404 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
405 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
406 isJQueryUploadChunk_ = true; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
407 jqueryUploadFileName_ = fileName->second; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
408 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
409 try |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
410 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
411 int64_t s = boost::lexical_cast<int64_t>(fileSize->second); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
412 if (s < 0) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
413 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
414 throw OrthancException(ErrorCode_NetworkProtocol, "HTTP header \"X-File-Size\" has negative value"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
415 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
416 else |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
417 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
418 jqueryUploadFileSize_ = static_cast<size_t>(s); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
419 if (static_cast<int64_t>(jqueryUploadFileSize_) != s) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
420 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
421 throw OrthancException(ErrorCode_NotEnoughMemory); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
422 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
423 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
424 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
425 catch (boost::bad_lexical_cast& e) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
426 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
427 throw OrthancException(ErrorCode_NetworkProtocol, "HTTP header \"X-File-Size\" is not an integer"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
428 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
429 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
430 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
431 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
432 virtual void HandlePart(const MultipartStreamReader::HttpHeaders& headers, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
433 const void* part, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
434 size_t size) ORTHANC_OVERRIDE |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
435 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
436 if (isJQueryUploadChunk_) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
437 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
438 std::string completedFile; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
439 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
440 PostDataStatus status = chunkStore_.Store(completedFile, part, size, jqueryUploadFileName_, jqueryUploadFileSize_); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
441 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
442 switch (status) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
443 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
444 case PostDataStatus_Failure: |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
445 throw OrthancException(ErrorCode_NetworkProtocol, "Error in the multipart form upload"); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
446 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
447 case PostDataStatus_Success: |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
448 assert(completedFile.size() == jqueryUploadFileSize_); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
449 HandleInternal(headers, completedFile.empty() ? NULL : completedFile.c_str(), completedFile.size()); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
450 break; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
451 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
452 case PostDataStatus_Pending: |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
453 break; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
454 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
455 default: |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
456 throw OrthancException(ErrorCode_InternalError); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
457 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
458 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
459 else |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
460 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
461 HandleInternal(headers, part, size); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
462 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
463 } |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
464 }; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
465 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
466 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
467 void HttpServer::ProcessMultipartFormData(const std::string& remoteIp, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
468 const std::string& username, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
469 const UriComponents& uri, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
470 const std::map<std::string, std::string>& headers, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
471 const std::string& body, |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
472 const std::string& boundary) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
473 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
474 MultipartFormDataHandler handler(GetHandler(), pimpl_->chunkStore_, remoteIp, username, uri, headers); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
475 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
476 MultipartStreamReader reader(boundary); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
477 reader.SetHandler(handler); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
478 reader.AddChunk(body); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
479 reader.CloseStream(); |
0 | 480 } |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
481 |
0 | 482 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
483 static PostDataStatus ReadBodyWithContentLength(std::string& body, |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
484 struct mg_connection *connection, |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
485 const std::string& contentLength) |
0 | 486 { |
4152
36257d6f348f
Support of multipart messages larger than 2GB in the embedded HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
487 size_t length; |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
488 try |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
489 { |
4201 | 490 int64_t tmp = boost::lexical_cast<int64_t>(contentLength); |
491 if (tmp < 0) | |
492 { | |
493 return PostDataStatus_NoLength; | |
494 } | |
495 | |
496 length = static_cast<size_t>(tmp); | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
497 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
498 catch (boost::bad_lexical_cast&) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
499 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
500 return PostDataStatus_NoLength; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
501 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
502 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
503 body.resize(length); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
504 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
505 size_t pos = 0; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
506 while (length > 0) |
0 | 507 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
508 int r = mg_read(connection, &body[pos], length); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
509 if (r <= 0) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
510 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
511 return PostDataStatus_Failure; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
512 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
513 |
4152
36257d6f348f
Support of multipart messages larger than 2GB in the embedded HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
514 assert(static_cast<size_t>(r) <= length); |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
515 length -= r; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
516 pos += r; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
517 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
518 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
519 return PostDataStatus_Success; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
520 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
521 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
522 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
523 static PostDataStatus ReadBodyWithoutContentLength(std::string& body, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
524 struct mg_connection *connection) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
525 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
526 // Store the individual chunks in a temporary file, then read it |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
527 // back into the memory buffer "body" |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
528 FileBuffer buffer; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
529 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
530 std::string tmp(1024 * 1024, 0); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
531 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
532 for (;;) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
533 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
534 int r = mg_read(connection, &tmp[0], tmp.size()); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
535 if (r < 0) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
536 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
537 return PostDataStatus_Failure; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
538 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
539 else if (r == 0) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
540 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
541 break; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
542 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
543 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
544 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
545 buffer.Append(tmp.c_str(), r); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
546 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
547 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
548 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
549 buffer.Read(body); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
550 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
551 return PostDataStatus_Success; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
552 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
553 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
554 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
555 static PostDataStatus ReadBodyToString(std::string& body, |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
556 struct mg_connection *connection, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
557 const HttpToolbox::Arguments& headers) |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
558 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
559 HttpToolbox::Arguments::const_iterator contentLength = headers.find("content-length"); |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
560 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
561 if (contentLength != headers.end()) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
562 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
563 // "Content-Length" is available |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
564 return ReadBodyWithContentLength(body, connection, contentLength->second); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
565 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
566 else |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
567 { |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
568 // No Content-Length |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
569 return ReadBodyWithoutContentLength(body, connection); |
0 | 570 } |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
571 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
572 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
573 |
3414 | 574 static PostDataStatus ReadBodyToStream(IHttpHandler::IChunkedRequestReader& stream, |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
575 struct mg_connection *connection, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
576 const HttpToolbox::Arguments& headers) |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
577 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
578 HttpToolbox::Arguments::const_iterator contentLength = headers.find("content-length"); |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
579 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
580 if (contentLength != headers.end()) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
581 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
582 // "Content-Length" is available |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
583 std::string body; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
584 PostDataStatus status = ReadBodyWithContentLength(body, connection, contentLength->second); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
585 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
586 if (status == PostDataStatus_Success && |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
587 !body.empty()) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
588 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
589 stream.AddBodyChunk(body.c_str(), body.size()); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
590 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
591 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
592 return status; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
593 } |
3356
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
594 else |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
595 { |
3404
e280ced38a4c
ErrorCode_UnsupportedMediaType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3395
diff
changeset
|
596 // No Content-Length: This is a chunked transfer. Stream the HTTP connection. |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
597 std::string tmp(1024 * 1024, 0); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
598 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
599 for (;;) |
3356
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
600 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
601 int r = mg_read(connection, &tmp[0], tmp.size()); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
602 if (r < 0) |
3356
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
603 { |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
604 return PostDataStatus_Failure; |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
605 } |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
606 else if (r == 0) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
607 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
608 break; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
609 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
610 else |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
611 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
612 stream.AddBodyChunk(tmp.c_str(), r); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
613 } |
3356
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
614 } |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
615 |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
616 return PostDataStatus_Success; |
f744730c294b
Orthanc now accepts chunked transfer encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3330
diff
changeset
|
617 } |
0 | 618 } |
619 | |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
620 |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
621 enum AccessMode |
23 | 622 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
623 AccessMode_Forbidden, |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
624 AccessMode_AuthorizationToken, |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
625 AccessMode_RegisteredUser |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
626 }; |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
627 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
628 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
629 static AccessMode IsAccessGranted(const HttpServer& that, |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
630 const HttpToolbox::Arguments& headers) |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
631 { |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
632 static const std::string BASIC = "Basic "; |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
633 static const std::string BEARER = "Bearer "; |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
634 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
635 HttpToolbox::Arguments::const_iterator auth = headers.find("authorization"); |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
636 if (auth != headers.end()) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
637 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
638 std::string s = auth->second; |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
639 if (boost::starts_with(s, BASIC)) |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
640 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
641 std::string b64 = s.substr(BASIC.length()); |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
642 if (that.IsValidBasicHttpAuthentication(b64)) |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
643 { |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
644 return AccessMode_RegisteredUser; |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
645 } |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
646 } |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
647 else if (boost::starts_with(s, BEARER) && |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
648 that.GetIncomingHttpRequestFilter() != NULL) |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
649 { |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
650 // New in Orthanc 1.8.1 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
651 std::string token = s.substr(BEARER.length()); |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
652 if (that.GetIncomingHttpRequestFilter()->IsValidBearerToken(token)) |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
653 { |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
654 return AccessMode_AuthorizationToken; |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
655 } |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
656 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
657 } |
23 | 658 |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
659 return AccessMode_Forbidden; |
23 | 660 } |
661 | |
662 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
663 static std::string GetAuthenticatedUsername(const HttpToolbox::Arguments& headers) |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
664 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
665 HttpToolbox::Arguments::const_iterator auth = headers.find("authorization"); |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
666 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
667 if (auth == headers.end()) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
668 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
669 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
670 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
671 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
672 std::string s = auth->second; |
1213 | 673 if (s.size() <= 6 || |
674 s.substr(0, 6) != "Basic ") | |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
675 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
676 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
677 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
678 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
679 std::string b64 = s.substr(6); |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
680 std::string decoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
681 Toolbox::DecodeBase64(decoded, b64); |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
682 size_t semicolons = decoded.find(':'); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
683 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
684 if (semicolons == std::string::npos) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
685 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
686 // Bad-formatted request |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
687 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
688 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
689 else |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
690 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
691 return decoded.substr(0, semicolons); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
692 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
693 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
694 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
695 |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
696 static bool ExtractMethod(HttpMethod& method, |
414 | 697 const struct mg_request_info *request, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
698 const HttpToolbox::Arguments& headers, |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
699 const HttpToolbox::GetArguments& argumentsGET) |
414 | 700 { |
701 std::string overriden; | |
702 | |
703 // Check whether some PUT/DELETE faking is done | |
704 | |
705 // 1. Faking with Google's approach | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
706 HttpToolbox::Arguments::const_iterator methodOverride = |
414 | 707 headers.find("x-http-method-override"); |
708 | |
709 if (methodOverride != headers.end()) | |
710 { | |
711 overriden = methodOverride->second; | |
712 } | |
713 else if (!strcmp(request->request_method, "GET")) | |
714 { | |
715 // 2. Faking with Ruby on Rail's approach | |
716 // GET /my/resource?_method=delete <=> DELETE /my/resource | |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
717 for (size_t i = 0; i < argumentsGET.size(); i++) |
414 | 718 { |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
719 if (argumentsGET[i].first == "_method") |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
720 { |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
721 overriden = argumentsGET[i].second; |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
722 break; |
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
723 } |
414 | 724 } |
725 } | |
726 | |
727 if (overriden.size() > 0) | |
728 { | |
729 // A faking has been done within this request | |
730 Toolbox::ToUpperCase(overriden); | |
731 | |
4295 | 732 CLOG(INFO, HTTP) << "HTTP method faking has been detected for " << overriden; |
416 | 733 |
414 | 734 if (overriden == "PUT") |
735 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
736 method = HttpMethod_Put; |
416 | 737 return true; |
414 | 738 } |
739 else if (overriden == "DELETE") | |
740 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
741 method = HttpMethod_Delete; |
416 | 742 return true; |
414 | 743 } |
744 else | |
745 { | |
746 return false; | |
747 } | |
748 } | |
749 | |
750 // No PUT/DELETE faking was present | |
751 if (!strcmp(request->request_method, "GET")) | |
752 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
753 method = HttpMethod_Get; |
414 | 754 } |
755 else if (!strcmp(request->request_method, "POST")) | |
756 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
757 method = HttpMethod_Post; |
414 | 758 } |
759 else if (!strcmp(request->request_method, "DELETE")) | |
760 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
761 method = HttpMethod_Delete; |
414 | 762 } |
763 else if (!strcmp(request->request_method, "PUT")) | |
764 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
765 method = HttpMethod_Put; |
414 | 766 } |
767 else | |
768 { | |
769 return false; | |
770 } | |
771 | |
772 return true; | |
773 } | |
774 | |
775 | |
1517 | 776 static void ConfigureHttpCompression(HttpOutput& output, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
777 const HttpToolbox::Arguments& headers) |
1517 | 778 { |
779 // Look if the client wishes HTTP compression | |
780 // https://en.wikipedia.org/wiki/HTTP_compression | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
781 HttpToolbox::Arguments::const_iterator it = headers.find("accept-encoding"); |
1517 | 782 if (it != headers.end()) |
783 { | |
784 std::vector<std::string> encodings; | |
785 Toolbox::TokenizeString(encodings, it->second, ','); | |
786 | |
787 for (size_t i = 0; i < encodings.size(); i++) | |
788 { | |
789 std::string s = Toolbox::StripSpaces(encodings[i]); | |
790 | |
791 if (s == "deflate") | |
792 { | |
793 output.SetDeflateAllowed(true); | |
794 } | |
795 else if (s == "gzip") | |
796 { | |
797 output.SetGzipAllowed(true); | |
798 } | |
799 } | |
800 } | |
801 } | |
802 | |
803 | |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
804 #if ORTHANC_ENABLE_PUGIXML == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
805 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
806 # if CIVETWEB_HAS_WEBDAV_WRITING == 0 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
807 static void AnswerWebDavReadOnly(HttpOutput& output, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
808 const std::string& uri) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
809 { |
4295 | 810 CLOG(ERROR, HTTP) << "Orthanc was compiled without support for read-write access to WebDAV: " << uri; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
811 output.SendStatus(HttpStatus_403_Forbidden); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
812 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
813 # endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
814 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
815 static bool HandleWebDav(HttpOutput& output, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
816 const HttpServer::WebDavBuckets& buckets, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
817 const std::string& method, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
818 const HttpToolbox::Arguments& headers, |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
819 const std::string& uri, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
820 struct mg_connection *connection /* to read the PUT body if need be */) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
821 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
822 if (buckets.empty()) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
823 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
824 return false; // Speed up things if WebDAV is not used |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
825 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
826 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
827 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
828 * The "buckets" maps an URI relative to the root of the |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
829 * bucket, to the content of the bucket. The root URI does *not* |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
830 * contain a trailing slash. |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
831 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
832 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
833 if (method == "OPTIONS") |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
834 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
835 // Remove the trailing slash, if any (necessary for davfs2) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
836 std::string s = uri; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
837 if (!s.empty() && |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
838 s[s.size() - 1] == '/') |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
839 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
840 s.resize(s.size() - 1); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
841 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
842 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
843 HttpServer::WebDavBuckets::const_iterator bucket = buckets.find(s); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
844 if (bucket == buckets.end()) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
845 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
846 return false; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
847 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
848 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
849 { |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
850 output.AddHeader("DAV", "1,2"); // Necessary for Windows XP |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
851 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
852 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
853 output.AddHeader("Allow", "GET, PUT, DELETE, OPTIONS, PROPFIND, HEAD, LOCK, UNLOCK, PROPPATCH, MKCOL"); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
854 #else |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
855 output.AddHeader("Allow", "GET, PUT, DELETE, OPTIONS, PROPFIND, HEAD"); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
856 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
857 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
858 output.SendStatus(HttpStatus_200_Ok); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
859 return true; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
860 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
861 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
862 else if (method == "GET" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
863 method == "PROPFIND" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
864 method == "PROPPATCH" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
865 method == "PUT" || |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
866 method == "DELETE" || |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
867 method == "HEAD" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
868 method == "LOCK" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
869 method == "UNLOCK" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
870 method == "MKCOL") |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
871 { |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
872 // Locate the WebDAV bucket of interest, if any |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
873 for (HttpServer::WebDavBuckets::const_iterator bucket = buckets.begin(); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
874 bucket != buckets.end(); ++bucket) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
875 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
876 assert(!bucket->first.empty() && |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
877 bucket->first[bucket->first.size() - 1] != '/' && |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
878 bucket->second != NULL); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
879 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
880 if (uri == bucket->first || |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
881 boost::starts_with(uri, bucket->first + "/")) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
882 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
883 std::string s = uri.substr(bucket->first.size()); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
884 if (s.empty()) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
885 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
886 s = "/"; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
887 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
888 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
889 std::vector<std::string> path; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
890 Toolbox::SplitUriComponents(path, s); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
891 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
892 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
893 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
894 * WebDAV - PROPFIND |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
895 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
896 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
897 if (method == "PROPFIND") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
898 { |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
899 HttpToolbox::Arguments::const_iterator i = headers.find("depth"); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
900 if (i == headers.end()) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
901 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
902 throw OrthancException(ErrorCode_NetworkProtocol, "WebDAV PROPFIND without depth"); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
903 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
904 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
905 int depth = boost::lexical_cast<int>(i->second); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
906 if (depth != 0 && |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
907 depth != 1) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
908 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
909 throw OrthancException( |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
910 ErrorCode_NetworkProtocol, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
911 "WebDAV PROPFIND at unsupported depth (can only be 0 or 1): " + i->second); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
912 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
913 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
914 std::string answer; |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
915 |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
916 MimeType mime; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
917 std::string content; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
918 boost::posix_time::ptime modificationTime = boost::posix_time::second_clock::universal_time(); |
4246 | 919 |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
920 if (bucket->second->IsExistingFolder(path)) |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
921 { |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
922 if (depth == 0) |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
923 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
924 IWebDavBucket::Collection c; |
4246 | 925 c.Format(answer, uri); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
926 } |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
927 else if (depth == 1) |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
928 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
929 IWebDavBucket::Collection c; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
930 |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
931 if (!bucket->second->ListCollection(c, path)) |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
932 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
933 output.SendStatus(HttpStatus_404_NotFound); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
934 return true; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
935 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
936 |
4246 | 937 c.Format(answer, uri); |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
938 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
939 else |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
940 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
941 throw OrthancException(ErrorCode_InternalError); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
942 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
943 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
944 else if (!path.empty() && |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
945 bucket->second->GetFileContent(mime, content, modificationTime, path)) |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
946 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
947 if (depth == 0 || |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
948 depth == 1) |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
949 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
950 std::unique_ptr<IWebDavBucket::File> f(new IWebDavBucket::File(path.back())); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
951 f->SetContentLength(content.size()); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
952 f->SetModificationTime(modificationTime); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
953 f->SetMimeType(mime); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
954 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
955 IWebDavBucket::Collection c; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
956 c.AddResource(f.release()); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
957 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
958 std::vector<std::string> p; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
959 Toolbox::SplitUriComponents(p, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
960 if (p.empty()) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
961 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
962 throw OrthancException(ErrorCode_InternalError); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
963 } |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
964 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
965 p.resize(p.size() - 1); |
4246 | 966 c.Format(answer, Toolbox::FlattenUri(p)); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
967 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
968 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
969 { |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
970 throw OrthancException(ErrorCode_InternalError); |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
971 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
972 } |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
973 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
974 { |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
975 output.SendStatus(HttpStatus_404_NotFound); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
976 return true; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
977 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
978 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
979 output.AddHeader("Content-Type", "application/xml; charset=UTF-8"); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
980 output.SendStatus(HttpStatus_207_MultiStatus, answer); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
981 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
982 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
983 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
984 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
985 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
986 * WebDAV - GET and HEAD |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
987 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
988 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
989 else if (method == "GET" || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
990 method == "HEAD") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
991 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
992 MimeType mime; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
993 std::string content; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
994 boost::posix_time::ptime modificationTime; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
995 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
996 if (bucket->second->GetFileContent(mime, content, modificationTime, path)) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
997 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
998 output.AddHeader("Content-Type", EnumerationToString(mime)); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
999 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1000 // "Last-Modified" is necessary on Windows XP. The "Z" |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1001 // suffix is mandatory on Windows >= 7. |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1002 output.AddHeader("Last-Modified", boost::posix_time::to_iso_extended_string(modificationTime) + "Z"); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1003 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1004 if (method == "GET") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1005 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1006 output.Answer(content); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1007 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1008 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1009 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1010 output.SendStatus(HttpStatus_200_Ok); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1011 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1012 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1013 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1014 { |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1015 output.SendStatus(HttpStatus_404_NotFound); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1016 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1017 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1018 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1019 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1020 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1021 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1022 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1023 * WebDAV - PUT |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1024 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1025 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1026 else if (method == "PUT") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1027 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1028 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1029 std::string body; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1030 if (ReadBodyToString(body, connection, headers) == PostDataStatus_Success) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1031 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1032 if (bucket->second->StoreFile(body, path)) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1033 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1034 //output.SendStatus(HttpStatus_200_Ok); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1035 output.SendStatus(HttpStatus_201_Created); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1036 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1037 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1038 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1039 output.SendStatus(HttpStatus_403_Forbidden); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1040 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1041 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1042 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1043 { |
4295 | 1044 CLOG(ERROR, HTTP) << "Cannot read the content of a file to be stored in WebDAV"; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1045 output.SendStatus(HttpStatus_400_BadRequest); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1046 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1047 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1048 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1049 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1050 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1051 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1052 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1053 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1054 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1055 /** |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1056 * WebDAV - DELETE |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1057 **/ |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1058 |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1059 else if (method == "DELETE") |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1060 { |
4252 | 1061 if (bucket->second->DeleteItem(path)) |
4232
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1062 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1063 output.SendStatus(HttpStatus_204_NoContent); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1064 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1065 else |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1066 { |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1067 output.SendStatus(HttpStatus_403_Forbidden); |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1068 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1069 return true; |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1070 } |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1071 |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1072 |
688435755466
added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4229
diff
changeset
|
1073 /** |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1074 * WebDAV - MKCOL |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1075 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1076 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1077 else if (method == "MKCOL") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1078 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1079 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1080 if (bucket->second->CreateFolder(path)) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1081 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1082 //output.SendStatus(HttpStatus_200_Ok); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1083 output.SendStatus(HttpStatus_201_Created); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1084 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1085 else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1086 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1087 output.SendStatus(HttpStatus_403_Forbidden); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1088 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1089 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1090 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1091 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1092 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1093 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1094 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1095 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1096 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1097 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1098 * WebDAV - Faking PROPPATCH, LOCK and UNLOCK |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1099 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1100 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1101 else if (method == "PROPPATCH") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1102 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1103 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1104 IWebDavBucket::AnswerFakedProppatch(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1105 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1106 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1107 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1108 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1109 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1110 else if (method == "LOCK") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1111 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1112 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1113 IWebDavBucket::AnswerFakedLock(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1114 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1115 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1116 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1117 return true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1118 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1119 else if (method == "UNLOCK") |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1120 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1121 #if CIVETWEB_HAS_WEBDAV_WRITING == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1122 IWebDavBucket::AnswerFakedUnlock(output); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1123 #else |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1124 AnswerWebDavReadOnly(output, uri); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1125 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1126 return true; |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1127 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1128 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1129 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1130 throw OrthancException(ErrorCode_InternalError); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1131 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1132 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1133 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1134 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1135 return false; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1136 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1137 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1138 { |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1139 /** |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1140 * WebDAV - Unapplicable method (such as POST and DELETE) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1141 **/ |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1142 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1143 return false; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1144 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1145 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1146 #endif /* ORTHANC_ENABLE_PUGIXML == 1 */ |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1147 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1148 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1149 static void InternalCallback(HttpOutput& output /* out */, |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1150 HttpMethod& method /* out */, |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1151 HttpServer& server, |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1152 struct mg_connection *connection, |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1153 const struct mg_request_info *request) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1154 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1155 bool localhost; |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1156 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1157 #if ORTHANC_ENABLE_MONGOOSE == 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1158 static const long LOCALHOST = (127ll << 24) + 1ll; |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1159 localhost = (request->remote_ip == LOCALHOST); |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1160 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1161 // The "remote_ip" field of "struct mg_request_info" is tagged as |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1162 // deprecated in Civetweb, using "remote_addr" instead. |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1163 localhost = (std::string(request->remote_addr) == "127.0.0.1"); |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1164 #else |
3069 | 1165 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1166 #endif |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1167 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1168 // Check remote calls |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1169 if (!server.IsRemoteAccessAllowed() && |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1170 !localhost) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1171 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1172 output.SendUnauthorized(server.GetRealm()); // 401 error |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1173 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1174 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1175 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1176 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1177 // Extract the HTTP headers |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
1178 HttpToolbox::Arguments headers; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1179 for (int i = 0; i < request->num_headers; i++) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1180 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1181 std::string name = request->http_headers[i].name; |
1977
ad95331c526a
trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1963
diff
changeset
|
1182 std::string value = request->http_headers[i].value; |
ad95331c526a
trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1963
diff
changeset
|
1183 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1184 std::transform(name.begin(), name.end(), name.begin(), ::tolower); |
1977
ad95331c526a
trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1963
diff
changeset
|
1185 headers.insert(std::make_pair(name, value)); |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4273
diff
changeset
|
1186 CLOG(TRACE, HTTP) << "HTTP header: [" << name << "]: [" << value << "]"; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1187 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1188 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1189 if (server.IsHttpCompressionEnabled()) |
1517 | 1190 { |
1191 ConfigureHttpCompression(output, headers); | |
1192 } | |
1193 | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1194 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1195 // Extract the GET arguments |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
1196 HttpToolbox::GetArguments argumentsGET; |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1197 if (!strcmp(request->request_method, "GET")) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1198 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1438
diff
changeset
|
1199 HttpToolbox::ParseGetArguments(argumentsGET, request->query_string); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1200 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1201 |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1202 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1203 AccessMode accessMode = IsAccessGranted(server, headers); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1204 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1205 // Authenticate this connection |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1206 if (server.IsAuthenticationEnabled() && |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1207 accessMode == AccessMode_Forbidden) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1208 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1209 output.SendUnauthorized(server.GetRealm()); // 401 error |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1210 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1211 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1212 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1213 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1214 #if ORTHANC_ENABLE_MONGOOSE == 1 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1215 // Apply the filter, if it is installed |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1216 char remoteIp[24]; |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1217 sprintf(remoteIp, "%d.%d.%d.%d", |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1218 reinterpret_cast<const uint8_t*>(&request->remote_ip) [3], |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1219 reinterpret_cast<const uint8_t*>(&request->remote_ip) [2], |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1220 reinterpret_cast<const uint8_t*>(&request->remote_ip) [1], |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1221 reinterpret_cast<const uint8_t*>(&request->remote_ip) [0]); |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1222 |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1223 const char* requestUri = request->uri; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1224 |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1225 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1226 const char* remoteIp = request->remote_addr; |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1227 const char* requestUri = request->local_uri; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1228 #else |
3069 | 1229 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1230 #endif |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1570
diff
changeset
|
1231 |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1232 if (requestUri == NULL) |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1233 { |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1234 requestUri = ""; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1235 } |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1236 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1237 // Decompose the URI into its components |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1238 UriComponents uri; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1239 try |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1240 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1241 Toolbox::SplitUriComponents(uri, requestUri); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1242 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1243 catch (OrthancException&) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1244 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1245 output.SendStatus(HttpStatus_400_BadRequest); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1246 return; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1247 } |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1248 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1249 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1250 // Compute the HTTP method, taking method faking into consideration |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1251 method = HttpMethod_Get; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1252 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1253 #if ORTHANC_ENABLE_PUGIXML == 1 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1254 bool isWebDav = false; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1255 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1256 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1257 HttpMethod filterMethod; |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1258 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1259 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1260 if (ExtractMethod(method, request, headers, argumentsGET)) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1261 { |
4295 | 1262 CLOG(INFO, HTTP) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1263 filterMethod = method; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1264 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1265 #if ORTHANC_ENABLE_PUGIXML == 1 |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1266 else if (!strcmp(request->request_method, "OPTIONS") || |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1267 !strcmp(request->request_method, "PROPFIND") || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1268 !strcmp(request->request_method, "HEAD")) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1269 { |
4295 | 1270 CLOG(INFO, HTTP) << "Incoming read-only WebDAV request: " |
1271 << request->request_method << " " << requestUri; | |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1272 filterMethod = HttpMethod_Get; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1273 isWebDav = true; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1274 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1275 else if (!strcmp(request->request_method, "PROPPATCH") || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1276 !strcmp(request->request_method, "LOCK") || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1277 !strcmp(request->request_method, "UNLOCK") || |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1278 !strcmp(request->request_method, "MKCOL")) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1279 { |
4295 | 1280 CLOG(INFO, HTTP) << "Incoming read-write WebDAV request: " |
1281 << request->request_method << " " << requestUri; | |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1282 filterMethod = HttpMethod_Put; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1283 isWebDav = true; |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1284 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1285 #endif /* ORTHANC_ENABLE_PUGIXML == 1 */ |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1286 else |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1287 { |
4295 | 1288 CLOG(INFO, HTTP) << "Unknown HTTP method: " << request->request_method; |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1289 output.SendStatus(HttpStatus_400_BadRequest); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1290 return; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1291 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1292 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1293 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1294 const std::string username = GetAuthenticatedUsername(headers); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1295 |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1296 if (accessMode != AccessMode_AuthorizationToken) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1297 { |
4343
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1298 // Check that this access is granted by the user's authorization |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1299 // filter. In the case of an authorization bearer token, grant |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1300 // full access to the API. |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1301 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1302 assert(accessMode == AccessMode_Forbidden || // Could be the case if "!server.IsAuthenticationEnabled()" |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1303 accessMode == AccessMode_RegisteredUser); |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1304 |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1305 IIncomingHttpRequestFilter *filter = server.GetIncomingHttpRequestFilter(); |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1306 if (filter != NULL && |
e1e918e790e8
New function in the SDK: OrthancPluginGenerateRestApiAuthorizationToken()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1307 !filter->IsAllowed(filterMethod, requestUri, remoteIp, |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1308 username.c_str(), headers, argumentsGET)) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1309 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1310 output.SendStatus(HttpStatus_403_Forbidden); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1311 return; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1312 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1313 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1314 |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1315 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1316 #if ORTHANC_ENABLE_PUGIXML == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1317 if (HandleWebDav(output, server.GetWebDavBuckets(), request->request_method, |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1318 headers, requestUri, connection)) |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1319 { |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1320 return; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1321 } |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1322 else if (isWebDav) |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1323 { |
4295 | 1324 CLOG(INFO, HTTP) << "No WebDAV bucket is registered against URI: " |
1325 << request->request_method << " " << requestUri; | |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1326 output.SendStatus(HttpStatus_404_NotFound); |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1327 return; |
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
1328 } |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1329 #endif |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1330 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1331 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1332 bool found = false; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1333 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1334 // Extract the body of the request for PUT and POST, or process |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1335 // the body as a stream |
1446
8dc80ba768aa
refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1443
diff
changeset
|
1336 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1337 std::string body; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1338 if (method == HttpMethod_Post || |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1339 method == HttpMethod_Put) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1340 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1341 PostDataStatus status; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1342 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1343 bool isMultipartForm = false; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1344 |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1345 std::string type, subType, boundary; |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4301
diff
changeset
|
1346 HttpToolbox::Arguments::const_iterator ct = headers.find("content-type"); |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1347 if (method == HttpMethod_Post && |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1348 ct != headers.end() && |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1349 MultipartStreamReader::ParseMultipartContentType(type, subType, boundary, ct->second) && |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1350 type == "multipart/form-data") |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1351 { |
3445 | 1352 /** |
1353 * The user uses the "upload" form of Orthanc Explorer, for | |
1354 * file uploads through a HTML form. | |
1355 **/ | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1356 isMultipartForm = true; |
4454
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1357 |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1358 status = ReadBodyToString(body, connection, headers); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1359 if (status == PostDataStatus_Success) |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1360 { |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1361 server.ProcessMultipartFormData(remoteIp, username, uri, headers, body, boundary); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1362 output.SendStatus(HttpStatus_200_Ok); |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1363 return; |
f20a7655fb1c
Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4449
diff
changeset
|
1364 } |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1365 } |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1366 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1367 if (!isMultipartForm) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1368 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3672
diff
changeset
|
1369 std::unique_ptr<IHttpHandler::IChunkedRequestReader> stream; |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1370 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1371 if (server.HasHandler()) |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1372 { |
3414 | 1373 found = server.GetHandler().CreateChunkedRequestReader |
1374 (stream, RequestOrigin_RestApi, remoteIp, username.c_str(), method, uri, headers); | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1375 } |
3414 | 1376 |
1377 if (found) | |
1378 { | |
1379 if (stream.get() == NULL) | |
1380 { | |
1381 throw OrthancException(ErrorCode_InternalError); | |
1382 } | |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1383 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1384 status = ReadBodyToStream(*stream, connection, headers); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1385 |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1386 if (status == PostDataStatus_Success) |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1387 { |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1388 stream->Execute(output); |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1389 } |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1390 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1391 else |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1392 { |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1393 status = ReadBodyToString(body, connection, headers); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1394 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1395 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1396 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1397 switch (status) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1398 { |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1399 case PostDataStatus_NoLength: |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1112
diff
changeset
|
1400 output.SendStatus(HttpStatus_411_LengthRequired); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1401 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1402 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1403 case PostDataStatus_Failure: |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1112
diff
changeset
|
1404 output.SendStatus(HttpStatus_400_BadRequest); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1405 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1406 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1407 case PostDataStatus_Pending: |
1521 | 1408 output.AnswerEmpty(); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1409 return; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1410 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1411 case PostDataStatus_Success: |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1412 break; |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1413 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1414 default: |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1415 throw OrthancException(ErrorCode_InternalError); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1416 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1417 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1418 |
3395
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1419 if (!found && |
0ce9b4f5fdf5
new abstraction: IHttpHandler::CreateStreamHandler()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
1420 server.HasHandler()) |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1421 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1422 found = server.GetHandler().Handle(output, RequestOrigin_RestApi, remoteIp, username.c_str(), |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1423 method, uri, headers, argumentsGET, body.c_str(), body.size()); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1424 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1425 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1426 if (!found) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1427 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1428 throw OrthancException(ErrorCode_UnknownResource); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1429 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1430 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1431 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1432 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1433 static void ProtectedCallback(struct mg_connection *connection, |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1434 const struct mg_request_info *request) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1435 { |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1436 try |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1437 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1438 #if ORTHANC_ENABLE_MONGOOSE == 1 |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1439 void *that = request->user_data; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1440 const char* requestUri = request->uri; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1441 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1442 // https://github.com/civetweb/civetweb/issues/409 |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1443 void *that = mg_get_user_data(mg_get_context(connection)); |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1444 const char* requestUri = request->local_uri; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1445 #else |
3069 | 1446 # error |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1447 #endif |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1448 |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1449 if (requestUri == NULL) |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1450 { |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1451 requestUri = ""; |
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1452 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1453 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1454 HttpServer* server = reinterpret_cast<HttpServer*>(that); |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1455 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1456 if (server == NULL) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1457 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1458 MongooseOutputStream stream(connection); |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1459 HttpOutput output(stream, false /* assume no keep-alive */, 0); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1460 output.SendStatus(HttpStatus_500_InternalServerError); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1461 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1462 } |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1463 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1464 MongooseOutputStream stream(connection); |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1465 HttpOutput output(stream, server->IsKeepAliveEnabled(), server->GetKeepAliveTimeout()); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1466 HttpMethod method = HttpMethod_Get; |
1569 | 1467 |
1468 try | |
1570 | 1469 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1470 try |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1471 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1472 InternalCallback(output, method, *server, connection, request); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1473 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1474 catch (OrthancException&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1475 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1476 throw; // Pass the exception to the main handler below |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1477 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1478 // Now convert native exceptions as OrthancException |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1479 catch (boost::bad_lexical_cast&) |
1570 | 1480 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1481 throw OrthancException(ErrorCode_BadParameterType, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1482 "Syntax error in some user-supplied data"); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1483 } |
3672
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1484 catch (boost::filesystem::filesystem_error& e) |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1485 { |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1486 throw OrthancException(ErrorCode_InternalError, |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1487 "Error while accessing the filesystem: " + e.path1().string()); |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1488 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1489 catch (std::runtime_error&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1490 { |
3672
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1491 throw OrthancException(ErrorCode_BadRequest, |
ea8c1c0e81eb
Fix issue #65 (Logging improvements)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1492 "Presumably an error while parsing the JSON body"); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1493 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1494 catch (std::bad_alloc&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1495 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1496 throw OrthancException(ErrorCode_NotEnoughMemory, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1497 "The server hosting Orthanc is running out of memory"); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1498 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1499 catch (...) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1500 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1501 throw OrthancException(ErrorCode_InternalError, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2903
diff
changeset
|
1502 "An unhandled exception was generated inside the HTTP server"); |
1570 | 1503 } |
1504 } | |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1505 catch (OrthancException& e) |
1570 | 1506 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1507 assert(server != NULL); |
1569 | 1508 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1509 // Using this candidate handler results in an exception |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1510 try |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1511 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1512 if (server->GetExceptionFormatter() == NULL) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1513 { |
4295 | 1514 CLOG(ERROR, HTTP) << "Exception in the HTTP handler: " << e.What(); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1515 output.SendStatus(e.GetHttpStatus()); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1516 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1517 else |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1518 { |
3068
ad37c21ec4db
fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1519 server->GetExceptionFormatter()->Format(output, e, method, requestUri); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1520 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1521 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1522 catch (OrthancException&) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1523 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1524 // An exception here reflects the fact that the status code |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1525 // was already set by the HTTP handler. |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1526 } |
1570 | 1527 } |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1528 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1529 catch (...) |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1530 { |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1531 // We should never arrive at this point, where it is even impossible to send an answer |
4295 | 1532 CLOG(ERROR, HTTP) << "Catastrophic error inside the HTTP server, giving up"; |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1533 } |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1534 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1535 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1536 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1537 #if MONGOOSE_USE_CALLBACKS == 0 |
0 | 1538 static void* Callback(enum mg_event event, |
1539 struct mg_connection *connection, | |
1540 const struct mg_request_info *request) | |
1541 { | |
1542 if (event == MG_NEW_REQUEST) | |
1543 { | |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1544 ProtectedCallback(connection, request); |
0 | 1545 |
1546 // Mark as processed | |
1547 return (void*) ""; | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1548 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1549 else |
0 | 1550 { |
1551 return NULL; | |
1552 } | |
1553 } | |
1554 | |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1555 #elif MONGOOSE_USE_CALLBACKS == 1 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1556 static int Callback(struct mg_connection *connection) |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1557 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1558 const struct mg_request_info *request = mg_get_request_info(connection); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1559 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2133
diff
changeset
|
1560 ProtectedCallback(connection, request); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1561 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1562 return 1; // Do not let Mongoose handle the request by itself |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1563 } |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1564 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1565 #else |
3069 | 1566 # error Please set MONGOOSE_USE_CALLBACKS |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1567 #endif |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1568 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1569 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1570 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1571 |
0 | 1572 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1573 bool HttpServer::IsRunning() const |
0 | 1574 { |
1575 return (pimpl_->context_ != NULL); | |
1576 } | |
1577 | |
1578 | |
4201 | 1579 HttpServer::HttpServer() : |
1580 pimpl_(new PImpl), | |
1581 handler_(NULL), | |
1582 remoteAllowed_(false), | |
1583 authentication_(false), | |
1584 sslVerifyPeers_(false), | |
1585 ssl_(false), | |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1586 sslMinimumVersion_(0), // Default to any of "SSL2+SSL3+TLS1.0+TLS1.1+TLS1.2" |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1587 sslHasCiphers_(false), |
4201 | 1588 port_(8000), |
1589 filter_(NULL), | |
1590 keepAlive_(false), | |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1591 keepAliveTimeout_(1), |
4201 | 1592 httpCompression_(true), |
1593 exceptionFormatter_(NULL), | |
1594 realm_(ORTHANC_REALM), | |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1595 threadsCount_(50), // Default value in mongoose/civetweb |
4201 | 1596 tcpNoDelay_(true), |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1597 requestTimeout_(30) // Default value in mongoose/civetweb (30 seconds) |
0 | 1598 { |
3145
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1599 #if ORTHANC_ENABLE_MONGOOSE == 1 |
4295 | 1600 CLOG(INFO, HTTP) << "This Orthanc server uses Mongoose as its embedded HTTP server"; |
3145
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1601 #endif |
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1602 |
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1603 #if ORTHANC_ENABLE_CIVETWEB == 1 |
4295 | 1604 CLOG(INFO, HTTP) << "This Orthanc server uses CivetWeb as its embedded HTTP server"; |
3145
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1605 #endif |
239331e4ee0b
log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3138
diff
changeset
|
1606 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
1607 #if ORTHANC_ENABLE_SSL == 1 |
749 | 1608 // Check for the Heartbleed exploit |
748
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1609 // https://en.wikipedia.org/wiki/OpenSSL#Heartbleed_bug |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1610 if (OPENSSL_VERSION_NUMBER < 0x1000107fL /* openssl-1.0.1g */ && |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1611 OPENSSL_VERSION_NUMBER >= 0x1000100fL /* openssl-1.0.1 */) |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1612 { |
4295 | 1613 CLOG(WARNING, HTTP) << "This version of OpenSSL is vulnerable to the Heartbleed exploit"; |
748
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1614 } |
de9763f63510
upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
1615 #endif |
0 | 1616 } |
1617 | |
1618 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1619 HttpServer::~HttpServer() |
0 | 1620 { |
1621 Stop(); | |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1622 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1623 #if ORTHANC_ENABLE_PUGIXML == 1 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1624 for (WebDavBuckets::iterator it = webDavBuckets_.begin(); it != webDavBuckets_.end(); ++it) |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1625 { |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1626 assert(it->second != NULL); |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1627 delete it->second; |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1628 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
1629 #endif |
0 | 1630 } |
1631 | |
1632 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1633 void HttpServer::SetPortNumber(uint16_t port) |
0 | 1634 { |
1635 Stop(); | |
1636 port_ = port; | |
1637 } | |
1638 | |
4298 | 1639 uint16_t HttpServer::GetPortNumber() const |
1640 { | |
1641 return port_; | |
1642 } | |
1643 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1644 void HttpServer::Start() |
0 | 1645 { |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1646 #if ORTHANC_ENABLE_MONGOOSE == 1 |
4295 | 1647 CLOG(INFO, HTTP) << "Starting embedded Web server using Mongoose"; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1648 #elif ORTHANC_ENABLE_CIVETWEB == 1 |
4295 | 1649 CLOG(INFO, HTTP) << "Starting embedded Web server using Civetweb"; |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1650 #else |
3069 | 1651 # error |
2377
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1652 #endif |
32bea64e070b
Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2268
diff
changeset
|
1653 |
0 | 1654 if (!IsRunning()) |
1655 { | |
1656 std::string port = boost::lexical_cast<std::string>(port_); | |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1657 std::string numThreads = boost::lexical_cast<std::string>(threadsCount_); |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
1658 std::string requestTimeoutMilliseconds = boost::lexical_cast<std::string>(requestTimeout_ * 1000); |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1659 std::string keepAliveTimeoutMilliseconds = boost::lexical_cast<std::string>(keepAliveTimeout_ * 1000); |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1660 std::string sslMinimumVersion = boost::lexical_cast<std::string>(sslMinimumVersion_); |
0 | 1661 |
23 | 1662 if (ssl_) |
1663 { | |
1664 port += "s"; | |
1665 } | |
1666 | |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1667 std::vector<const char*> options; |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1668 |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1669 // Set the TCP port for the HTTP server |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1670 options.push_back("listening_ports"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1671 options.push_back(port.c_str()); |
1110
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
1672 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1673 // Optimization reported by Chris Hafey |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1674 // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1675 options.push_back("enable_keep_alive"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1676 options.push_back(keepAlive_ ? "yes" : "no"); |
1110
becde5351e47
preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1100
diff
changeset
|
1677 |
2579 | 1678 #if ORTHANC_ENABLE_CIVETWEB == 1 |
4301
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1679 /** |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1680 * The "keep_alive_timeout_ms" cannot use milliseconds, as the |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1681 * value of "timeout" in the HTTP header "Keep-Alive" must be |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1682 * expressed in seconds (at least for the Java client). |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1683 * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1684 * https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#enable_keep_alive-no |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1685 * https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#keep_alive_timeout_ms-500-or-0 |
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1686 **/ |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1687 options.push_back("keep_alive_timeout_ms"); |
4301
6919242d2265
Fix keep-alive in the embedded HTTP server by setting the "Keep-Alive" HTTP header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4298
diff
changeset
|
1688 options.push_back(keepAlive_ ? keepAliveTimeoutMilliseconds.c_str() : "0"); |
2577
6783a7c02990
keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1689 #endif |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
1690 |
3136
f948deef53d9
using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3069
diff
changeset
|
1691 #if ORTHANC_ENABLE_CIVETWEB == 1 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1692 // Disable TCP Nagle's algorithm to maximize speed (this |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1693 // option is not available in Mongoose). |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1694 // https://groups.google.com/d/topic/civetweb/35HBR9seFjU/discussion |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1695 // https://eklitzke.org/the-caveats-of-tcp-nodelay |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1696 options.push_back("tcp_nodelay"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1697 options.push_back(tcpNoDelay_ ? "1" : "0"); |
3136
f948deef53d9
using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3069
diff
changeset
|
1698 #endif |
f948deef53d9
using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3069
diff
changeset
|
1699 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1700 // Set the number of threads |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1701 options.push_back("num_threads"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1702 options.push_back(numThreads.c_str()); |
2577
6783a7c02990
keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1703 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1704 // Set the timeout for the HTTP server |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1705 options.push_back("request_timeout_ms"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1706 options.push_back(requestTimeoutMilliseconds.c_str()); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1707 |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1708 // Set the client authentication |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1709 options.push_back("ssl_verify_peer"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1710 options.push_back(sslVerifyPeers_ ? "yes" : "no"); |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
1711 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1712 if (sslVerifyPeers_) |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1713 { |
4190
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1714 // Set the trusted client certificates (for X509 mutual authentication) |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1715 options.push_back("ssl_ca_file"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1716 options.push_back(trustedClientCertificates_.c_str()); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1717 } |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1718 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1719 if (ssl_) |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1720 { |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1721 // Restrict minimum SSL/TLS protocol version |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1722 options.push_back("ssl_protocol_version"); |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1723 options.push_back(sslMinimumVersion.c_str()); |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1724 |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1725 // Set the accepted ciphers list |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1726 if (sslHasCiphers_) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1727 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1728 options.push_back("ssl_cipher_list"); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1729 options.push_back(sslCiphers_.c_str()); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1730 } |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1731 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1732 // Set the SSL certificate, if any |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1733 options.push_back("ssl_certificate"); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1734 options.push_back(certificate_.c_str()); |
0 | 1735 }; |
1736 | |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1737 assert(options.size() % 2 == 0); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1738 options.push_back(NULL); |
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1739 |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1740 #if MONGOOSE_USE_CALLBACKS == 0 |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1741 pimpl_->context_ = mg_start(&Callback, this, &options[0]); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1742 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1743 #elif MONGOOSE_USE_CALLBACKS == 1 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1744 struct mg_callbacks callbacks; |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1745 memset(&callbacks, 0, sizeof(callbacks)); |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1746 callbacks.begin_request = Callback; |
4193
ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4190
diff
changeset
|
1747 pimpl_->context_ = mg_start(&callbacks, this, &options[0]); |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1748 |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1749 #else |
3069 | 1750 # error Please set MONGOOSE_USE_CALLBACKS |
1112
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1751 #endif |
a119f9ae3640
upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1110
diff
changeset
|
1752 |
0 | 1753 if (!pimpl_->context_) |
1754 { | |
3801
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1755 bool isSslError = false; |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1756 |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1757 #if ORTHANC_ENABLE_SSL == 1 |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1758 for (;;) |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1759 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1760 unsigned long code = ERR_get_error(); |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1761 if (code == 0) |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1762 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1763 break; |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1764 } |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1765 else |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1766 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1767 isSslError = true; |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1768 char message[1024]; |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1769 ERR_error_string_n(code, message, sizeof(message) - 1); |
4295 | 1770 CLOG(ERROR, HTTP) << "OpenSSL error: " << message; |
3801
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1771 } |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1772 } |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1773 #endif |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1774 |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1775 if (isSslError) |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1776 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1777 throw OrthancException(ErrorCode_SslInitialization); |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1778 } |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1779 else |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1780 { |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1781 throw OrthancException(ErrorCode_HttpPortInUse, |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1782 " (port = " + boost::lexical_cast<std::string>(port_) + ")"); |
9fe1d64a748c
upgrade to civetweb 1.12, error reporting if OpenSSL failure
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
1783 } |
0 | 1784 } |
2633
40c7926b75f8
log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2579
diff
changeset
|
1785 |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1786 #if ORTHANC_ENABLE_PUGIXML == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1787 for (WebDavBuckets::iterator it = webDavBuckets_.begin(); it != webDavBuckets_.end(); ++it) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1788 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1789 assert(it->second != NULL); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1790 it->second->Start(); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1791 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1792 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1793 |
4295 | 1794 CLOG(WARNING, HTTP) << "HTTP server listening on port: " << GetPortNumber() |
1795 << " (HTTPS encryption is " | |
1796 << (IsSslEnabled() ? "enabled" : "disabled") | |
1797 << ", remote access is " | |
1798 << (IsRemoteAccessAllowed() ? "" : "not ") | |
1799 << "allowed)"; | |
0 | 1800 } |
1801 } | |
1802 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1803 void HttpServer::Stop() |
0 | 1804 { |
1805 if (IsRunning()) | |
1806 { | |
1807 mg_stop(pimpl_->context_); | |
4228
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1808 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1809 #if ORTHANC_ENABLE_PUGIXML == 1 |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1810 for (WebDavBuckets::iterator it = webDavBuckets_.begin(); it != webDavBuckets_.end(); ++it) |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1811 { |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1812 assert(it->second != NULL); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1813 it->second->Stop(); |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1814 } |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1815 #endif |
c8c0bbaaace3
write access to webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4227
diff
changeset
|
1816 |
0 | 1817 pimpl_->context_ = NULL; |
1818 } | |
1819 } | |
1820 | |
1821 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1822 void HttpServer::ClearUsers() |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1823 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1824 Stop(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1825 registeredUsers_.clear(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1826 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1827 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1828 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1829 void HttpServer::RegisterUser(const char* username, |
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1830 const char* password) |
23 | 1831 { |
1832 Stop(); | |
24 | 1833 |
1834 std::string tag = std::string(username) + ":" + std::string(password); | |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
1835 std::string encoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
1836 Toolbox::EncodeBase64(encoded, tag); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
749
diff
changeset
|
1837 registeredUsers_.insert(encoded); |
23 | 1838 } |
1839 | |
4298 | 1840 bool HttpServer::IsAuthenticationEnabled() const |
1841 { | |
1842 return authentication_; | |
1843 } | |
1844 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1845 void HttpServer::SetSslEnabled(bool enabled) |
23 | 1846 { |
1847 Stop(); | |
1848 | |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
1849 #if ORTHANC_ENABLE_SSL == 0 |
23 | 1850 if (enabled) |
1851 { | |
1674
4fc502d469f4
fix build if SSL is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1649
diff
changeset
|
1852 throw OrthancException(ErrorCode_SslDisabled); |
23 | 1853 } |
1854 else | |
1855 { | |
1856 ssl_ = false; | |
1857 } | |
1858 #else | |
1859 ssl_ = enabled; | |
1860 #endif | |
1861 } | |
1862 | |
4190
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1863 void HttpServer::SetSslVerifyPeers(bool enabled) |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1864 { |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1865 Stop(); |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1866 |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1867 #if ORTHANC_ENABLE_SSL == 0 |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1868 if (enabled) |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1869 { |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1870 throw OrthancException(ErrorCode_SslDisabled); |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1871 } |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1872 else |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1873 { |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1874 sslVerifyPeers_ = false; |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1875 } |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1876 #else |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1877 sslVerifyPeers_ = enabled; |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1878 #endif |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
1879 } |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1880 |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1881 void HttpServer::SetSslMinimumVersion(unsigned int version) |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1882 { |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1883 Stop(); |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1884 sslMinimumVersion_ = version; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1885 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1886 std::string info; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1887 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1888 switch (version) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1889 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1890 case 0: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1891 info = "SSL2+SSL3+TLS1.0+TLS1.1+TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1892 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1893 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1894 case 1: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1895 info = "SSL3+TLS1.0+TLS1.1+TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1896 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1897 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1898 case 2: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1899 info = "TLS1.0+TLS1.1+TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1900 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1901 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1902 case 3: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1903 info = "TLS1.1+TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1904 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1905 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1906 case 4: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1907 info = "TLS1.2"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1908 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1909 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1910 default: |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1911 info = "Unknown value (" + boost::lexical_cast<std::string>(version) + ")"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1912 break; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1913 } |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1914 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1915 CLOG(INFO, HTTP) << "Minimal accepted version of SSL/TLS protocol: " << info; |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1916 } |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1917 |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1918 void HttpServer::SetSslCiphers(const std::list<std::string>& ciphers) |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1919 { |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1920 Stop(); |
4382
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1921 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1922 sslHasCiphers_ = true; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1923 sslCiphers_.clear(); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1924 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1925 for (std::list<std::string>::const_iterator |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1926 it = ciphers.begin(); it != ciphers.end(); ++it) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1927 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1928 if (it->empty()) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1929 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1930 throw OrthancException(ErrorCode_ParameterOutOfRange, "Empty name for a cipher"); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1931 } |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1932 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1933 if (!sslCiphers_.empty()) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1934 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1935 sslCiphers_ += ':'; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1936 } |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1937 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1938 sslCiphers_ += (*it); |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1939 } |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1940 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1941 CLOG(INFO, HTTP) << "List of accepted SSL ciphers: " << sslCiphers_; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1942 |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1943 if (sslCiphers_.empty()) |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1944 { |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1945 CLOG(WARNING, HTTP) << "No cipher is accepted for SSL"; |
3aacd2bd8bbc
review changeset 4381:df313e410f0c
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4381
diff
changeset
|
1946 } |
4381
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1947 } |
df313e410f0c
Add support to configure minimimum accepted TLS version and cipher suite
Andrew Wallis <andrew.wallis@varian.com>>
parents:
4343
diff
changeset
|
1948 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1949 void HttpServer::SetKeepAliveEnabled(bool enabled) |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1950 { |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1951 Stop(); |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1952 keepAlive_ = enabled; |
4295 | 1953 CLOG(INFO, HTTP) << "HTTP keep alive is " << (enabled ? "enabled" : "disabled"); |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1954 |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1955 #if ORTHANC_ENABLE_MONGOOSE == 1 |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1956 if (enabled) |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1957 { |
4295 | 1958 CLOG(WARNING, HTTP) << "You should disable HTTP keep alive, as you are using Mongoose"; |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1959 } |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
1960 #endif |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1961 } |
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1962 |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1963 void HttpServer::SetKeepAliveTimeout(unsigned int timeout) |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1964 { |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1965 Stop(); |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1966 keepAliveTimeout_ = timeout; |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1967 CLOG(INFO, HTTP) << "HTTP keep alive Timeout is now " << keepAliveTimeout_ << " seconds"; |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1968 |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1969 #if ORTHANC_ENABLE_MONGOOSE == 1 |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1970 if (enabled) |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1971 { |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1972 CLOG(WARNING, HTTP) << "You should disable HTTP keep alive, as you are using Mongoose"; |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1973 } |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1974 #endif |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1975 } |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
1976 |
4298 | 1977 const std::string &HttpServer::GetSslCertificate() const |
1978 { | |
1979 return certificate_; | |
1980 } | |
1981 | |
1115
da56a7916e8a
Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
1982 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1983 void HttpServer::SetAuthenticationEnabled(bool enabled) |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1984 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1985 Stop(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1986 authentication_ = enabled; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1987 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1988 |
4298 | 1989 bool HttpServer::IsSslEnabled() const |
1990 { | |
1991 return ssl_; | |
1992 } | |
1993 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
1994 void HttpServer::SetSslCertificate(const char* path) |
23 | 1995 { |
1996 Stop(); | |
1997 certificate_ = path; | |
1998 } | |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
1999 |
4298 | 2000 bool HttpServer::IsRemoteAccessAllowed() const |
2001 { | |
2002 return remoteAllowed_; | |
2003 } | |
2004 | |
4190
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
2005 void HttpServer::SetSslTrustedClientCertificates(const char* path) |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
2006 { |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
2007 Stop(); |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
2008 trustedClientCertificates_ = path; |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
2009 } |
9ce5c89328f5
New configuration options to enable HTTP peers identification through certificates
Alain Mazy <alain@mazy.be>
parents:
4152
diff
changeset
|
2010 |
4298 | 2011 bool HttpServer::IsKeepAliveEnabled() const |
2012 { | |
2013 return keepAlive_; | |
2014 } | |
2015 | |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
2016 unsigned int HttpServer::GetKeepAliveTimeout() const |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
2017 { |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
2018 return keepAliveTimeout_; |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
2019 } |
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
5097
diff
changeset
|
2020 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2021 void HttpServer::SetRemoteAccessAllowed(bool allowed) |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
2022 { |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
2023 Stop(); |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
2024 remoteAllowed_ = allowed; |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
2025 } |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
2026 |
4298 | 2027 bool HttpServer::IsHttpCompressionEnabled() const |
2028 { | |
2029 return httpCompression_;; | |
2030 } | |
2031 | |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2032 void HttpServer::SetHttpCompressionEnabled(bool enabled) |
1517 | 2033 { |
2034 Stop(); | |
2035 httpCompression_ = enabled; | |
4295 | 2036 CLOG(WARNING, HTTP) << "HTTP compression is " << (enabled ? "enabled" : "disabled"); |
1517 | 2037 } |
4298 | 2038 |
2039 IIncomingHttpRequestFilter *HttpServer::GetIncomingHttpRequestFilter() const | |
2040 { | |
2041 return filter_; | |
2042 } | |
1592
d73124f6b439
configuration option HttpDescribeErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
2043 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2044 void HttpServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter) |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2045 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2046 Stop(); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2047 filter_ = &filter; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2048 } |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
2049 |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
2050 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2051 void HttpServer::SetHttpExceptionFormatter(IHttpExceptionFormatter& formatter) |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
2052 { |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
2053 Stop(); |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
2054 exceptionFormatter_ = &formatter; |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
2055 } |
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
2056 |
4298 | 2057 IHttpExceptionFormatter *HttpServer::GetExceptionFormatter() |
2058 { | |
2059 return exceptionFormatter_; | |
2060 } | |
2061 | |
2062 const std::string &HttpServer::GetRealm() const | |
2063 { | |
2064 return realm_; | |
2065 } | |
2066 | |
2067 void HttpServer::SetRealm(const std::string &realm) | |
2068 { | |
2069 realm_ = realm; | |
2070 } | |
2071 | |
1645
1558b3226b18
IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1644
diff
changeset
|
2072 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2073 bool HttpServer::IsValidBasicHttpAuthentication(const std::string& basic) const |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
2074 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
2075 return registeredUsers_.find(basic) != registeredUsers_.end(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
2076 } |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2077 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2078 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2079 void HttpServer::Register(IHttpHandler& handler) |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2080 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2081 Stop(); |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2082 handler_ = &handler; |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2083 } |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2084 |
4298 | 2085 bool HttpServer::HasHandler() const |
2086 { | |
2087 return handler_ != NULL; | |
2088 } | |
2089 | |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2090 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2091 IHttpHandler& HttpServer::GetHandler() const |
1443
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2092 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2093 if (handler_ == NULL) |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2094 { |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2095 throw OrthancException(ErrorCode_InternalError); |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2096 } |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2097 |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2098 return *handler_; |
895ab369d63c
refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
2099 } |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2100 |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2101 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2102 void HttpServer::SetThreadsCount(unsigned int threads) |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2103 { |
4201 | 2104 if (threads == 0) |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2105 { |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2106 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2107 } |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2108 |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2109 Stop(); |
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2110 threadsCount_ = threads; |
3180
07a2f637b76d
new option: "HttpThreadsCount" to set the number of threads in the embedded HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3178
diff
changeset
|
2111 |
4295 | 2112 CLOG(INFO, HTTP) << "The embedded HTTP server will use " << threads << " threads"; |
2903
1153b1a128fe
MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
2113 } |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2114 |
4298 | 2115 unsigned int HttpServer::GetThreadsCount() const |
2116 { | |
2117 return threadsCount_; | |
2118 } | |
2119 | |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2120 |
3138
ab46e537f92e
renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3137
diff
changeset
|
2121 void HttpServer::SetTcpNoDelay(bool tcpNoDelay) |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2122 { |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2123 Stop(); |
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2124 tcpNoDelay_ = tcpNoDelay; |
4295 | 2125 CLOG(INFO, HTTP) << "TCP_NODELAY for the HTTP sockets is set to " |
2126 << (tcpNoDelay ? "true" : "false"); | |
3137
5a3b961e9524
New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3136
diff
changeset
|
2127 } |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2128 |
4298 | 2129 bool HttpServer::IsTcpNoDelay() const |
2130 { | |
2131 return tcpNoDelay_; | |
2132 } | |
2133 | |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2134 |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2135 void HttpServer::SetRequestTimeout(unsigned int seconds) |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2136 { |
4201 | 2137 if (seconds == 0) |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2138 { |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2139 throw OrthancException(ErrorCode_ParameterOutOfRange, |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2140 "Request timeout must be a stricly positive integer"); |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2141 } |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2142 |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2143 Stop(); |
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2144 requestTimeout_ = seconds; |
4295 | 2145 CLOG(INFO, HTTP) << "Request timeout in the HTTP server is set to " << seconds << " seconds"; |
3537
9cc09f4c0fa9
New configuration option: "HttpRequestTimeout"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3445
diff
changeset
|
2146 } |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2147 |
4298 | 2148 unsigned int HttpServer::GetRequestTimeout() const |
2149 { | |
2150 return requestTimeout_; | |
2151 } | |
2152 | |
2153 | |
2154 #if ORTHANC_ENABLE_PUGIXML == 1 | |
2155 HttpServer::WebDavBuckets& HttpServer::GetWebDavBuckets() | |
2156 { | |
2157 return webDavBuckets_; | |
2158 } | |
2159 #endif | |
2160 | |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2161 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2162 #if ORTHANC_ENABLE_PUGIXML == 1 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2163 void HttpServer::Register(const std::vector<std::string>& root, |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2164 IWebDavBucket* bucket) |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2165 { |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2166 std::unique_ptr<IWebDavBucket> protection(bucket); |
4229 | 2167 |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2168 if (bucket == NULL) |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2169 { |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2170 throw OrthancException(ErrorCode_NullPointer); |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2171 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2172 |
4229 | 2173 Stop(); |
2174 | |
2175 #if CIVETWEB_HAS_WEBDAV_WRITING == 0 | |
2176 if (webDavBuckets_.size() == 0) | |
2177 { | |
4295 | 2178 CLOG(WARNING, HTTP) << "Your version of the Orthanc framework was compiled " |
2179 << "without support for writing into WebDAV collections"; | |
4229 | 2180 } |
2181 #endif | |
2182 | |
4227
7fff7e683d65
basic implementation of WebDAV handler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4226
diff
changeset
|
2183 const std::string s = Toolbox::FlattenUri(root); |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2184 |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2185 if (webDavBuckets_.find(s) != webDavBuckets_.end()) |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2186 { |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2187 throw OrthancException(ErrorCode_ParameterOutOfRange, |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2188 "Cannot register two WebDAV buckets at the same root: " + s); |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2189 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2190 else |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2191 { |
4295 | 2192 CLOG(INFO, HTTP) << "Branching WebDAV bucket at: " << s; |
4226
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2193 webDavBuckets_[s] = protection.release(); |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2194 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2195 } |
7bd5eab3ba25
prototyping IWebDavBucket
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
2196 #endif |
0 | 2197 } |