annotate Core/HttpServer/HttpServer.cpp @ 3353:54cdad5a7228 emscripten-logging

Added a public function that will use emscripten-specific logging functions when using its SDK + scaffolding work. Build and UT OK on msvc15 x64. Not actually tested under *nix or emscripten yet
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 23 Apr 2019 21:40:57 +0200
parents 10e2b9f4162f
children f744730c294b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1823
diff changeset
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
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2954
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
11 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
12 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
13 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
16 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
20 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
21 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
22 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 // http://en.highscore.de/cpp/boost/stringhandling.html
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
36 #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
37 #include "HttpServer.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
39 #include "../Logging.h"
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
40 #include "../ChunkedBuffer.h"
2895
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2836
diff changeset
41 #include "../OrthancException.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
42 #include "HttpToolbox.h"
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
43
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
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
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
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
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
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
53
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
54 #else
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
55 # 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
56 #endif
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
57
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 #include <algorithm>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 #include <string.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 #include <boost/lexical_cast.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 #include <boost/algorithm/string.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 #include <iostream>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 #include <string.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 #include <stdio.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 #include <boost/thread.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
2137
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
67 #if !defined(ORTHANC_ENABLE_SSL)
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
68 # error The macro ORTHANC_ENABLE_SSL must be defined
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
69 #endif
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2136
diff changeset
70
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
71 #if ORTHANC_ENABLE_SSL == 1
748
de9763f63510 upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
72 #include <openssl/opensslv.h>
de9763f63510 upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
73 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
75 #define ORTHANC_REALM "Orthanc Secure Area"
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
76
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
77
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
78 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 static const char multipart[] = "multipart/form-data; boundary=";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 static unsigned int multipartLength = sizeof(multipart) / sizeof(char) - 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 namespace
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 // Anonymous namespace to avoid clashes between compilation modules
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
87 class MongooseOutputStream : public IHttpOutputStream
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 private:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 struct mg_connection* connection_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
92 public:
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
93 MongooseOutputStream(struct mg_connection* connection) : connection_(connection)
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
94 {
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
95 }
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
96
909
ef71057d8b26 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
97 virtual void Send(bool isHeader, const void* buffer, size_t length)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
99 if (length > 0)
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
100 {
1430
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
101 int status = mg_write(connection_, buffer, length);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
102 if (status != static_cast<int>(length))
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
103 {
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
104 // status == 0 when the connection has been closed, -1 on error
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
105 throw OrthancException(ErrorCode_NetworkProtocol);
ad94a3583b07 Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
106 }
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
107 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 901
diff changeset
109
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
110 virtual void OnHttpStatusReceived(HttpStatus status)
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 901
diff changeset
111 {
911
306afd58a0b3 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 909
diff changeset
112 // Ignore this
908
e078ea944089 refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 901
diff changeset
113 }
3154
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
114
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
115 virtual void DisableKeepAlive()
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
116 {
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
117 #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
118 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
119 "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
120
3154
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
121 #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
122 # if CIVETWEB_HAS_DISABLE_KEEP_ALIVE == 1
3154
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
123 mg_disable_keep_alive(connection_);
3178
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
124 # else
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
125 # warning The function "mg_disable_keep_alive()" is not available, DICOMweb might run slowly
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
126 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
127 "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
128 # endif
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
129
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
130 #else
6d558598d713 Fix build with unpatched versions of Civetweb (missing "mg_disable_keep_alive()")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3154
diff changeset
131 # 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
132 #endif
6e8822be2f08 Fix compatibility with DICOMweb plugin (allow multipart answers over HTTP Keep-Alive)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3145
diff changeset
133 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 enum PostDataStatus
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 PostDataStatus_Success,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 PostDataStatus_NoLength,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 PostDataStatus_Pending,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 PostDataStatus_Failure
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 // TODO Move this to external file
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 class ChunkedFile : public ChunkedBuffer
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 private:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 std::string filename_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 public:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ChunkedFile(const std::string& filename) :
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 filename_(filename)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 const std::string& GetFilename() const
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 return filename_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 class ChunkStore
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 private:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 typedef std::list<ChunkedFile*> Content;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 Content content_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 unsigned int numPlaces_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 boost::mutex mutex_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 std::set<std::string> discardedFiles_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 void Clear()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 for (Content::iterator it = content_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
182 it != content_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 delete *it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 Content::iterator Find(const std::string& filename)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 for (Content::iterator it = content_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
191 it != content_.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 if ((*it)->GetFilename() == filename)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 return it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 return content_.end();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 void Remove(const std::string& filename)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 Content::iterator it = Find(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (it != content_.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 delete *it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 content_.erase(it);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 public:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 ChunkStore()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 numPlaces_ = 10;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 ~ChunkStore()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 Clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 PostDataStatus Store(std::string& completed,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 const char* chunkData,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 size_t chunkSize,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 const std::string& filename,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 size_t filesize)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 boost::mutex::scoped_lock lock(mutex_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 std::set<std::string>::iterator wasDiscarded = discardedFiles_.find(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 if (wasDiscarded != discardedFiles_.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 discardedFiles_.erase(wasDiscarded);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 return PostDataStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 ChunkedFile* f;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 Content::iterator it = Find(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 if (it == content_.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 f = new ChunkedFile(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 // Make some room
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 if (content_.size() >= numPlaces_)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 discardedFiles_.insert(content_.front()->GetFilename());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 delete content_.front();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 content_.pop_front();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 content_.push_back(f);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 f = *it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 f->AddChunk(chunkData, chunkSize);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 if (f->GetNumBytes() > filesize)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 Remove(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 else if (f->GetNumBytes() == filesize)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 f->Flatten(completed);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 Remove(filename);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 return PostDataStatus_Success;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 return PostDataStatus_Pending;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 /*void Print()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 boost::mutex::scoped_lock lock(mutex_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 printf("ChunkStore status:\n");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 for (Content::const_iterator i = content_.begin();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 i != content_.end(); i++)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 printf(" [%s]: %d\n", (*i)->GetFilename().c_str(), (*i)->GetNumBytes());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 printf("-----\n");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }*/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
290 struct HttpServer::PImpl
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 struct mg_context *context_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 ChunkStore chunkStore_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
297 ChunkStore& HttpServer::GetChunkStore()
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 return pimpl_->chunkStore_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
304 static PostDataStatus ReadBody(std::string& postData,
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
305 struct mg_connection *connection,
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
306 const IHttpHandler::Arguments& headers)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
308 IHttpHandler::Arguments::const_iterator cs = headers.find("content-length");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 if (cs == headers.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 return PostDataStatus_NoLength;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 int length;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 length = boost::lexical_cast<int>(cs->second);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2790
diff changeset
319 catch (boost::bad_lexical_cast&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 return PostDataStatus_NoLength;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 if (length < 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 length = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 postData.resize(length);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 size_t pos = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 while (length > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 int r = mg_read(connection, &postData[pos], length);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 if (r <= 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 return PostDataStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 }
418
b79bf2f4ab2e execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
339
8
3a584803783e build with visual studio
jodogne
parents: 0
diff changeset
340 assert(r <= length);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 length -= r;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 pos += r;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 return PostDataStatus_Success;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 static PostDataStatus ParseMultipartPost(std::string &completedFile,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 struct mg_connection *connection,
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
352 const IHttpHandler::Arguments& headers,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 const std::string& contentType,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 ChunkStore& chunkStore)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 std::string boundary = "--" + contentType.substr(multipartLength);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 std::string postData;
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
359 PostDataStatus status = ReadBody(postData, connection, headers);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 if (status != PostDataStatus_Success)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 return status;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
366 /*for (IHttpHandler::Arguments::const_iterator i = headers.begin(); i != headers.end(); i++)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 std::cout << "Header [" << i->first << "] = " << i->second << "\n";
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 printf("CHUNK\n");*/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
372 typedef IHttpHandler::Arguments::const_iterator ArgumentIterator;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 ArgumentIterator requestedWith = headers.find("x-requested-with");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 ArgumentIterator fileName = headers.find("x-file-name");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 ArgumentIterator fileSizeStr = headers.find("x-file-size");
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
338
3a3b3ba8c1e0 fix for uploads through internet explorer 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 333
diff changeset
378 if (requestedWith != headers.end() &&
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 requestedWith->second != "XMLHttpRequest")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 return PostDataStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 size_t fileSize = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 if (fileSizeStr != headers.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 fileSize = boost::lexical_cast<size_t>(fileSizeStr->second);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2790
diff changeset
391 catch (boost::bad_lexical_cast&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 return PostDataStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 typedef boost::find_iterator<std::string::iterator> FindIterator;
10
27e2bbc11200 Better signal handling
Administrator@jodogne-w01
parents: 8
diff changeset
398 typedef boost::iterator_range<char*> Range;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 //chunkStore.Print();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 FindIterator last;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 for (FindIterator it =
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 make_find_iterator(postData, boost::first_finder(boundary));
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 it!=FindIterator();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 ++it)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 if (last != FindIterator())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 {
10
27e2bbc11200 Better signal handling
Administrator@jodogne-w01
parents: 8
diff changeset
412 Range part(&last->back(), &it->front());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 Range content = boost::find_first(part, "\r\n\r\n");
345
jodogne
parents: 338
diff changeset
414 if (/*content != Range()*/!content.empty())
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 Range c(&content.back() + 1, &it->front() - 2);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 size_t chunkSize = c.size();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 if (chunkSize > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 const char* chunkData = &c.front();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 if (fileName == headers.end())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 // This file is stored in a single chunk
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 completedFile.resize(chunkSize);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 if (chunkSize > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 memcpy(&completedFile[0], chunkData, chunkSize);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 return PostDataStatus_Success;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 return chunkStore.Store(completedFile, chunkData, chunkSize, fileName->second, fileSize);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 }
10
27e2bbc11200 Better signal handling
Administrator@jodogne-w01
parents: 8
diff changeset
438 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 last = it;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2790
diff changeset
444 catch (std::length_error&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 return PostDataStatus_Failure;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 return PostDataStatus_Pending;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
453 static bool IsAccessGranted(const HttpServer& that,
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
454 const IHttpHandler::Arguments& headers)
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
455 {
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
456 bool granted = false;
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
457
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
458 IHttpHandler::Arguments::const_iterator auth = headers.find("authorization");
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
459 if (auth != headers.end())
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
460 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
461 std::string s = auth->second;
1213
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1202
diff changeset
462 if (s.size() > 6 &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1202
diff changeset
463 s.substr(0, 6) == "Basic ")
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
464 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
465 std::string b64 = s.substr(6);
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
466 granted = that.IsValidBasicHttpAuthentication(b64);
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
467 }
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
468 }
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
469
1202
476a17cfdf42 Fix crash when bad HTTP credentials are provided
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
470 return granted;
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
471 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
472
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
473
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
474 static std::string GetAuthenticatedUsername(const IHttpHandler::Arguments& headers)
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
475 {
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
476 IHttpHandler::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
477
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
478 if (auth == headers.end())
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
479 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
480 return "";
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
481 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
482
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
483 std::string s = auth->second;
1213
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1202
diff changeset
484 if (s.size() <= 6 ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1202
diff changeset
485 s.substr(0, 6) != "Basic ")
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
486 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
487 return "";
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
488 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
489
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
490 std::string b64 = s.substr(6);
809
8ce2f69436ca do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 749
diff changeset
491 std::string decoded;
8ce2f69436ca do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 749
diff changeset
492 Toolbox::DecodeBase64(decoded, b64);
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
493 size_t semicolons = decoded.find(':');
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
494
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
495 if (semicolons == std::string::npos)
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
496 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
497 // Bad-formatted request
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
498 return "";
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
499 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
500 else
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
501 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
502 return decoded.substr(0, semicolons);
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
503 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
504 }
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
505
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
506
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
507 static bool ExtractMethod(HttpMethod& method,
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
508 const struct mg_request_info *request,
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
509 const IHttpHandler::Arguments& headers,
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
510 const IHttpHandler::GetArguments& argumentsGET)
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
511 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
512 std::string overriden;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
513
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
514 // Check whether some PUT/DELETE faking is done
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
515
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
516 // 1. Faking with Google's approach
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
517 IHttpHandler::Arguments::const_iterator methodOverride =
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
518 headers.find("x-http-method-override");
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
519
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
520 if (methodOverride != headers.end())
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
521 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
522 overriden = methodOverride->second;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
523 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
524 else if (!strcmp(request->request_method, "GET"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
525 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
526 // 2. Faking with Ruby on Rail's approach
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
527 // 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
528 for (size_t i = 0; i < argumentsGET.size(); i++)
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
529 {
1363
feaf2840917c Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
530 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
531 {
feaf2840917c Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
532 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
533 break;
feaf2840917c Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
534 }
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
535 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
536 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
537
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
538 if (overriden.size() > 0)
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
539 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
540 // A faking has been done within this request
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
541 Toolbox::ToUpperCase(overriden);
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
542
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
543 LOG(INFO) << "HTTP method faking has been detected for " << overriden;
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
544
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
545 if (overriden == "PUT")
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
546 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
547 method = HttpMethod_Put;
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
548 return true;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
549 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
550 else if (overriden == "DELETE")
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
551 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
552 method = HttpMethod_Delete;
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 415
diff changeset
553 return true;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
554 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
555 else
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
556 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
557 return false;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
558 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
559 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
560
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
561 // No PUT/DELETE faking was present
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
562 if (!strcmp(request->request_method, "GET"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
563 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
564 method = HttpMethod_Get;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
565 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
566 else if (!strcmp(request->request_method, "POST"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
567 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
568 method = HttpMethod_Post;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
569 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
570 else if (!strcmp(request->request_method, "DELETE"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
571 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
572 method = HttpMethod_Delete;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
573 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
574 else if (!strcmp(request->request_method, "PUT"))
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
575 {
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 418
diff changeset
576 method = HttpMethod_Put;
414
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
577 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
578 else
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
579 {
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
580 return false;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
581 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
582
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
583 return true;
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
584 }
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
585
26290b46056b http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
586
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
587 static void ConfigureHttpCompression(HttpOutput& output,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
588 const IHttpHandler::Arguments& headers)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
589 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
590 // Look if the client wishes HTTP compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
591 // https://en.wikipedia.org/wiki/HTTP_compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
592 IHttpHandler::Arguments::const_iterator it = headers.find("accept-encoding");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
593 if (it != headers.end())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
594 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
595 std::vector<std::string> encodings;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
596 Toolbox::TokenizeString(encodings, it->second, ',');
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
597
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
598 for (size_t i = 0; i < encodings.size(); i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
599 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
600 std::string s = Toolbox::StripSpaces(encodings[i]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
601
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
602 if (s == "deflate")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
603 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
604 output.SetDeflateAllowed(true);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
605 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
606 else if (s == "gzip")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
607 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
608 output.SetGzipAllowed(true);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
609 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
610 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
611 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
612 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
613
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
614
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
615 static void InternalCallback(HttpOutput& output /* out */,
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
616 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
617 HttpServer& server,
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
618 struct mg_connection *connection,
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
619 const struct mg_request_info *request)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
620 {
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
621 bool localhost;
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
622
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
623 #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
624 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
625 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
626 #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
627 // 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
628 // 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
629 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
630 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
631 # error
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
632 #endif
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
633
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
634 // Check remote calls
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
635 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
636 !localhost)
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
637 {
2790
c7313e1f7644 MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2635
diff changeset
638 output.SendUnauthorized(server.GetRealm());
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
639 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
640 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
641
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
642
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
643 // Extract the HTTP headers
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
644 IHttpHandler::Arguments headers;
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
645 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
646 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
647 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
648 std::string value = request->http_headers[i].value;
ad95331c526a trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1963
diff changeset
649
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
650 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
651 headers.insert(std::make_pair(name, value));
ad95331c526a trace log of http headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1963
diff changeset
652 VLOG(1) << "HTTP header: [" << name << "]: [" << value << "]";
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
653 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
654
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
655 if (server.IsHttpCompressionEnabled())
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
656 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
657 ConfigureHttpCompression(output, headers);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
658 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
659
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
660
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
661 // Extract the GET arguments
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
662 IHttpHandler::GetArguments argumentsGET;
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
663 if (!strcmp(request->request_method, "GET"))
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
664 {
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
665 HttpToolbox::ParseGetArguments(argumentsGET, request->query_string);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
666 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
667
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
668
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
669 // Compute the HTTP method, taking method faking into consideration
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
670 method = HttpMethod_Get;
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
671 if (!ExtractMethod(method, request, headers, argumentsGET))
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
672 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
673 output.SendStatus(HttpStatus_400_BadRequest);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
674 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
675 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
676
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
677
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
678 // Authenticate this connection
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
679 if (server.IsAuthenticationEnabled() &&
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
680 !IsAccessGranted(server, headers))
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
681 {
2790
c7313e1f7644 MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2635
diff changeset
682 output.SendUnauthorized(server.GetRealm());
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
683 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
684 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
685
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
686
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
687 #if ORTHANC_ENABLE_MONGOOSE == 1
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
688 // 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
689 char remoteIp[24];
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
690 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
691 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
692 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
693 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
694 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
695
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
696 const char* requestUri = request->uri;
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
697
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
698 #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
699 const char* remoteIp = request->remote_addr;
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
700 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
701 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
702 # error
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
703 #endif
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
704
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
705 if (requestUri == NULL)
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
706 {
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
707 requestUri = "";
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
708 }
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
709
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
710 std::string username = GetAuthenticatedUsername(headers);
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1570
diff changeset
711
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
712 IIncomingHttpRequestFilter *filter = server.GetIncomingHttpRequestFilter();
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
713 if (filter != NULL)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
714 {
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
715 if (!filter->IsAllowed(method, requestUri, remoteIp,
2268
ce5c13b95dac New function: OrthancPluginRegisterIncomingHttpRequestFilter2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
716 username.c_str(), headers, argumentsGET))
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
717 {
2790
c7313e1f7644 MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2635
diff changeset
718 //output.SendUnauthorized(server.GetRealm());
1963
af0c90ae0915 Use 403 Forbidden status if the incoming HTTP request is disallowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1959
diff changeset
719 output.SendStatus(HttpStatus_403_Forbidden);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
720 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
721 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
722 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
723
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
724
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
725 // Extract the body of the request for PUT and POST
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
726
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
727 // TODO Avoid unneccessary memcopy of the body
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1443
diff changeset
728
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
729 std::string body;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
730 if (method == HttpMethod_Post ||
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
731 method == HttpMethod_Put)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
732 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
733 PostDataStatus status;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
734
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1438
diff changeset
735 IHttpHandler::Arguments::const_iterator ct = headers.find("content-type");
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
736 if (ct == headers.end())
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
737 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
738 // No content-type specified. Assume no multi-part content occurs at this point.
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
739 status = ReadBody(body, connection, headers);
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
740 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
741 else
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
742 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
743 std::string contentType = ct->second;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
744 if (contentType.size() >= multipartLength &&
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
745 !memcmp(contentType.c_str(), multipart, multipartLength))
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
746 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
747 status = ParseMultipartPost(body, connection, headers, contentType, server.GetChunkStore());
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
748 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
749 else
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
750 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
751 status = ReadBody(body, connection, headers);
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
752 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
753 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
754
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
755 switch (status)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
756 {
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
757 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
758 output.SendStatus(HttpStatus_411_LengthRequired);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
759 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
760
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
761 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
762 output.SendStatus(HttpStatus_400_BadRequest);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
763 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
764
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
765 case PostDataStatus_Pending:
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
766 output.AnswerEmpty();
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
767 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
768
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
769 default:
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
770 break;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
771 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
772 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
773
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
774
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
775 // Decompose the URI into its components
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
776 UriComponents uri;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
777 try
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
778 {
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
779 Toolbox::SplitUriComponents(uri, requestUri);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
780 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
781 catch (OrthancException&)
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
782 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
783 output.SendStatus(HttpStatus_400_BadRequest);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
784 return;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
785 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
786
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
787
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
788 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri);
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
789
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
790 bool found = false;
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
791
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
792 if (server.HasHandler())
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
793 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
794 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
795 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
796 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
797
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
798 if (!found)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
799 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
800 throw OrthancException(ErrorCode_UnknownResource);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
801 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
802 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
803
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
804
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
805 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
806 const struct mg_request_info *request)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
807 {
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
808 try
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
809 {
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
810 #if ORTHANC_ENABLE_MONGOOSE == 1
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
811 void *that = request->user_data;
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
812 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
813 #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
814 // 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
815 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
816 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
817 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
818 # error
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
819 #endif
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
820
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
821 if (requestUri == NULL)
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
822 {
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
823 requestUri = "";
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
824 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
825
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
826 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
827
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
828 if (server == NULL)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
829 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
830 MongooseOutputStream stream(connection);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
831 HttpOutput output(stream, false /* assume no keep-alive */);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
832 output.SendStatus(HttpStatus_500_InternalServerError);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
833 return;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
834 }
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
835
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
836 MongooseOutputStream stream(connection);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
837 HttpOutput output(stream, server->IsKeepAliveEnabled());
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
838 HttpMethod method = HttpMethod_Get;
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1568
diff changeset
839
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1568
diff changeset
840 try
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
841 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
842 try
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
843 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
844 InternalCallback(output, method, *server, connection, request);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
845 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
846 catch (OrthancException&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
847 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
848 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
849 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
850 // Now convert native exceptions as OrthancException
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
851 catch (boost::bad_lexical_cast&)
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
852 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
853 throw OrthancException(ErrorCode_BadParameterType,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
854 "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
855 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
856 catch (std::runtime_error&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
857 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
858 // Presumably an error while parsing the JSON body
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
859 throw OrthancException(ErrorCode_BadRequest);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
860 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
861 catch (std::bad_alloc&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
862 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
863 throw OrthancException(ErrorCode_NotEnoughMemory,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
864 "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
865 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
866 catch (...)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
867 {
2954
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
868 throw OrthancException(ErrorCode_InternalError,
d924f9bb61cc taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2903
diff changeset
869 "An unhandled exception was generated inside the HTTP server");
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
870 }
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
871 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
872 catch (OrthancException& e)
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
873 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
874 assert(server != NULL);
1569
27774f6f84e4 improved error handling in http answers
jodogne
parents: 1568
diff changeset
875
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
876 // 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
877 try
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
878 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
879 if (server->GetExceptionFormatter() == NULL)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
880 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
881 LOG(ERROR) << "Exception in the HTTP handler: " << e.What();
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
882 output.SendStatus(e.GetHttpStatus());
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
883 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
884 else
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
885 {
3068
ad37c21ec4db fix compatibility with civetweb 1.11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
886 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
887 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
888 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
889 catch (OrthancException&)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
890 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
891 // 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
892 // 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
893 }
1570
2bd2c280f9b5 fix indentation
jodogne
parents: 1569
diff changeset
894 }
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
895 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
896 catch (...)
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
897 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
898 // We should never arrive at this point, where it is even impossible to send an answer
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
899 LOG(ERROR) << "Catastrophic error inside the HTTP server, giving up";
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
900 }
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
901 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
902
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
903
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
904 #if MONGOOSE_USE_CALLBACKS == 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 static void* Callback(enum mg_event event,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 struct mg_connection *connection,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 const struct mg_request_info *request)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 if (event == MG_NEW_REQUEST)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
911 ProtectedCallback(connection, request);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 // Mark as processed
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 return (void*) "";
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
915 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
916 else
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
922 #elif MONGOOSE_USE_CALLBACKS == 1
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
923 static int Callback(struct mg_connection *connection)
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
924 {
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
925 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
926
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2133
diff changeset
927 ProtectedCallback(connection, request);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
928
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
929 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
930 }
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
931
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
932 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
933 # error Please set MONGOOSE_USE_CALLBACKS
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
934 #endif
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
935
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
936
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
937
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
938
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
940 bool HttpServer::IsRunning() const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 return (pimpl_->context_ != NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
946 HttpServer::HttpServer() : pimpl_(new PImpl)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 pimpl_->context_ = NULL;
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
949 handler_ = NULL;
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
950 remoteAllowed_ = false;
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
951 authentication_ = false;
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
952 ssl_ = false;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 port_ = 8000;
417
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
954 filter_ = NULL;
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
955 keepAlive_ = false;
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
956 httpCompression_ = true;
1645
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
957 exceptionFormatter_ = NULL;
2790
c7313e1f7644 MongooseServer::SetRealm()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2635
diff changeset
958 realm_ = ORTHANC_REALM;
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
959 threadsCount_ = 50; // Default value in 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
960 tcpNoDelay_ = true;
748
de9763f63510 upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
961
3145
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
962 #if ORTHANC_ENABLE_MONGOOSE == 1
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
963 LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server";
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
964 #endif
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
965
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
966 #if ORTHANC_ENABLE_CIVETWEB == 1
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
967 LOG(INFO) << "This Orthanc server uses CivetWeb as its embedded HTTP server";
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
968 #endif
239331e4ee0b log about what HTTP server is running
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3138
diff changeset
969
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
970 #if ORTHANC_ENABLE_SSL == 1
749
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 748
diff changeset
971 // 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
972 // 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
973 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
974 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
975 {
749
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 748
diff changeset
976 LOG(WARNING) << "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
977 }
de9763f63510 upgrade to openssl-1.0.1g because of heartbeat exploit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
978 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
982 HttpServer::~HttpServer()
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 Stop();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
988 void HttpServer::SetPortNumber(uint16_t port)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 Stop();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 port_ = port;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
994 void HttpServer::Start()
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 {
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
996 #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
997 LOG(INFO) << "Starting embedded Web server using Mongoose";
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
998 #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
999 LOG(INFO) << "Starting embedded Web server using Civetweb";
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1000 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
1001 # error
2377
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1002 #endif
32bea64e070b Experimental support of actively maintained Civetweb to replace Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2268
diff changeset
1003
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 if (!IsRunning())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 std::string port = boost::lexical_cast<std::string>(port_);
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1007 std::string numThreads = boost::lexical_cast<std::string>(threadsCount_);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1009 if (ssl_)
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1010 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1011 port += "s";
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1012 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1013
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 const char *options[] = {
1110
becde5351e47 preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1100
diff changeset
1015 // Set the TCP port for the HTTP server
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 "listening_ports", port.c_str(),
1110
becde5351e47 preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1100
diff changeset
1017
becde5351e47 preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1100
diff changeset
1018 // Optimization reported by Chris Hafey
becde5351e47 preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1100
diff changeset
1019 // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1020 "enable_keep_alive", (keepAlive_ ? "yes" : "no"),
1110
becde5351e47 preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1100
diff changeset
1021
2579
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2577
diff changeset
1022 #if ORTHANC_ENABLE_CIVETWEB == 1
2577
6783a7c02990 keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1023 // https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#enable_keep_alive-no
6783a7c02990 keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1024 "keep_alive_timeout_ms", (keepAlive_ ? "500" : "0"),
6783a7c02990 keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1025 #endif
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1026
3136
f948deef53d9 using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3069
diff changeset
1027 #if ORTHANC_ENABLE_CIVETWEB == 1
f948deef53d9 using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3069
diff changeset
1028 // Disable TCP Nagle's algorithm to maximize speed (this
3137
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1029 // option is not available in Mongoose).
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1030 // https://groups.google.com/d/topic/civetweb/35HBR9seFjU/discussion
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1031 // https://eklitzke.org/the-caveats-of-tcp-nodelay
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1032 "tcp_nodelay", (tcpNoDelay_ ? "1" : "0"),
3136
f948deef53d9 using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3069
diff changeset
1033 #endif
f948deef53d9 using tcp_nodelay in civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3069
diff changeset
1034
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1035 // Set the number of threads
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1036 "num_threads", numThreads.c_str(),
2577
6783a7c02990 keep_alive_timeout_ms for civetweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1037
1110
becde5351e47 preparing to update mongoose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1100
diff changeset
1038 // Set the SSL certificate, if any. This must be the last option.
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1039 ssl_ ? "ssl_certificate" : NULL,
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1040 certificate_.c_str(),
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 NULL
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1044 #if MONGOOSE_USE_CALLBACKS == 0
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045 pimpl_->context_ = mg_start(&Callback, this, options);
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1046
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1047 #elif MONGOOSE_USE_CALLBACKS == 1
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1048 struct mg_callbacks callbacks;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1049 memset(&callbacks, 0, sizeof(callbacks));
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1050 callbacks.begin_request = Callback;
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1051 pimpl_->context_ = mg_start(&callbacks, this, options);
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1052
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1053 #else
3069
3db9697a0a58 cosmetic
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3068
diff changeset
1054 # error Please set MONGOOSE_USE_CALLBACKS
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1055 #endif
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
1056
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 if (!pimpl_->context_)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 {
3330
10e2b9f4162f more details in errors
Alain Mazy <alain@mazy.be>
parents: 3180
diff changeset
1059 throw OrthancException(ErrorCode_HttpPortInUse,
10e2b9f4162f more details in errors
Alain Mazy <alain@mazy.be>
parents: 3180
diff changeset
1060 " (port = " + boost::lexical_cast<std::string>(port_) + ")");
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 }
2633
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1062
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1063 LOG(WARNING) << "HTTP server listening on port: " << GetPortNumber()
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1064 << " (HTTPS encryption is "
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1065 << (IsSslEnabled() ? "enabled" : "disabled")
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1066 << ", remote access is "
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1067 << (IsRemoteAccessAllowed() ? "" : "not ")
40c7926b75f8 log about remote access allowed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2579
diff changeset
1068 << "allowed)";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1072 void HttpServer::Stop()
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074 if (IsRunning())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 mg_stop(pimpl_->context_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 pimpl_->context_ = NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1082 void HttpServer::ClearUsers()
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1083 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1084 Stop();
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1085 registeredUsers_.clear();
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1086 }
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1087
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1088
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1089 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
1090 const char* password)
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1091 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1092 Stop();
24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
1093
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 23
diff changeset
1094 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
1095 std::string encoded;
8ce2f69436ca do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 749
diff changeset
1096 Toolbox::EncodeBase64(encoded, tag);
8ce2f69436ca do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 749
diff changeset
1097 registeredUsers_.insert(encoded);
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1098 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1099
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1100 void HttpServer::SetSslEnabled(bool enabled)
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1101 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1102 Stop();
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1103
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
1104 #if ORTHANC_ENABLE_SSL == 0
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1105 if (enabled)
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1106 {
1674
4fc502d469f4 fix build if SSL is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1649
diff changeset
1107 throw OrthancException(ErrorCode_SslDisabled);
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1108 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1109 else
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1110 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1111 ssl_ = false;
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1112 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1113 #else
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1114 ssl_ = enabled;
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1115 #endif
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1116 }
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1117
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1118
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1119 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
1120 {
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1121 Stop();
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1122 keepAlive_ = enabled;
2069
fabf7820d1f1 New configuration options: "DicomScuTimeout" and "DicomScpTimeout" + validation of non-negative options
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1977
diff changeset
1123 LOG(INFO) << "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
1124
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1125 #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
1126 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
1127 {
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1128 LOG(WARNING) << "You should disable HTTP keep alive, as you are using Mongoose";
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1129 }
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1130 #endif
1115
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1131 }
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1132
da56a7916e8a Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
1133
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1134 void HttpServer::SetAuthenticationEnabled(bool enabled)
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1135 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1136 Stop();
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1137 authentication_ = enabled;
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1138 }
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1139
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1140 void HttpServer::SetSslCertificate(const char* path)
23
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1141 {
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1142 Stop();
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1143 certificate_ = path;
62bd05fe4b7c support for ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
1144 }
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1145
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1146 void HttpServer::SetRemoteAccessAllowed(bool allowed)
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1147 {
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1148 Stop();
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1149 remoteAllowed_ = allowed;
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1150 }
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1151
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1152 void HttpServer::SetHttpCompressionEnabled(bool enabled)
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
1153 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
1154 Stop();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
1155 httpCompression_ = enabled;
1518
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
1156 LOG(WARNING) << "HTTP compression is " << (enabled ? "enabled" : "disabled");
1517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
1157 }
1592
d73124f6b439 configuration option HttpDescribeErrors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
1158
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1159 void HttpServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter)
409
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
1160 {
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
1161 Stop();
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
1162 filter_ = &filter;
63f707278fc8 lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
1163 }
34
96e57b863dd9 option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 25
diff changeset
1164
1645
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1165
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1166 void HttpServer::SetHttpExceptionFormatter(IHttpExceptionFormatter& formatter)
1645
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1167 {
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1168 Stop();
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1169 exceptionFormatter_ = &formatter;
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1170 }
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1171
1558b3226b18 IHttpExceptionFormatter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1644
diff changeset
1172
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1173 bool HttpServer::IsValidBasicHttpAuthentication(const std::string& basic) const
25
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1174 {
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1175 return registeredUsers_.find(basic) != registeredUsers_.end();
dd1489098265 basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
1176 }
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1177
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1178
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1179 void HttpServer::Register(IHttpHandler& handler)
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1180 {
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1181 Stop();
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1182 handler_ = &handler;
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1183 }
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1184
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1185
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1186 IHttpHandler& HttpServer::GetHandler() const
1443
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1187 {
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1188 if (handler_ == NULL)
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1189 {
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1190 throw OrthancException(ErrorCode_InternalError);
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1191 }
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1192
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1193 return *handler_;
895ab369d63c refactoring: OrthancHttpHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
1194 }
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1195
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1196
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1197 void HttpServer::SetThreadsCount(unsigned int threads)
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1198 {
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1199 if (threads <= 0)
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1200 {
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1201 throw OrthancException(ErrorCode_ParameterOutOfRange);
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1202 }
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1203
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1204 Stop();
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1205 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
1206
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
1207 LOG(INFO) << "The embedded HTTP server will use " << threads << " threads";
2903
1153b1a128fe MongooseServer::SetThreadsCount()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
1208 }
3137
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1209
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1210
3138
ab46e537f92e renamed class MongooseServer as HttpServer, CivetWeb made default HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3137
diff changeset
1211 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
1212 {
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1213 Stop();
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1214 tcpNoDelay_ = tcpNoDelay;
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1215 LOG(INFO) << "TCP_NODELAY for the HTTP sockets is set to "
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1216 << (tcpNoDelay ? "true" : "false");
5a3b961e9524 New configuration option: 'TcpNoDelay' to disable Nagle's algorithm in HTTP server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3136
diff changeset
1217 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 }