annotate OrthancFramework/Sources/HttpServer/FilesystemHttpHandler.cpp @ 4105:c02a2d9efbc2

move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 06 Jul 2020 13:48:10 +0200
parents d25f4c0fa160
children bf7b9edf6b81
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: 1582
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3401
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
11 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
12 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
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: 110
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
16 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
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: 110
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: 110
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: 110
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: 110
diff changeset
21 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
22 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
34 #include "../PrecompiledHeaders.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "FilesystemHttpHandler.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
37 #include "../OrthancException.h"
2143
fd5875662670 creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
38 #include "../SystemToolbox.h"
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
39 #include "FilesystemHttpSender.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <boost/filesystem.hpp>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
44 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 struct FilesystemHttpHandler::PImpl
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 UriComponents baseUri_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 boost::filesystem::path root_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 static void OutputDirectoryContent(HttpOutput& output,
1515
c94353fbd4e9 cont http compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
55 const IHttpHandler::Arguments& headers,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const UriComponents& uri,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 const boost::filesystem::path& p)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 namespace fs = boost::filesystem;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
61 std::string s;
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
62 s += "<html>";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
63 s += " <body>";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
64 s += " <h1>Subdirectories</h1>";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
65 s += " <ul>";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if (uri.size() > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 std::string h = Toolbox::FlattenUri(uri) + "/..";
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
70 s += "<li><a href=\"" + h + "\">..</a></li>";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 fs::directory_iterator end;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 for (fs::directory_iterator it(p) ; it != end; ++it)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
76 #if BOOST_HAS_FILESYSTEM_V3 == 1
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 std::string f = it->path().filename().string();
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
78 #else
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
79 std::string f = it->path().filename();
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
80 #endif
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
81
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 std::string h = Toolbox::FlattenUri(uri) + "/" + f;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 if (fs::is_directory(it->status()))
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
84 s += "<li><a href=\"" + h + "\">" + f + "</a></li>";
0
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
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
87 s += " </ul>";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
88 s += " <h1>Files</h1>";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
89 s += " <ul>";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 for (fs::directory_iterator it(p) ; it != end; ++it)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
93 #if BOOST_HAS_FILESYSTEM_V3 == 1
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 std::string f = it->path().filename().string();
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
95 #else
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
96 std::string f = it->path().filename();
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
97 #endif
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
98
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 std::string h = Toolbox::FlattenUri(uri) + "/" + f;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
100 if (SystemToolbox::IsRegularFile(it->path().string()))
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
101 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
102 s += "<li><a href=\"" + h + "\">" + f + "</a></li>";
1911
7a05144cb919 fix issue 11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
103 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
106 s += " </ul>";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
107 s += " </body>";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
108 s += "</html>";
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
109
2908
9d277f8ad698 new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
110 output.SetContentType(MimeType_Html);
1521
3606278d305e refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
111 output.Answer(s);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 FilesystemHttpHandler::FilesystemHttpHandler(const std::string& baseUri,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 const std::string& root) : pimpl_(new PImpl)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 Toolbox::SplitUriComponents(pimpl_->baseUri_, baseUri);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 pimpl_->root_ = root;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 listDirectoryContent_ = false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 namespace fs = boost::filesystem;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 if (!fs::exists(pimpl_->root_) ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 !fs::is_directory(pimpl_->root_))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
126 throw OrthancException(ErrorCode_DirectoryExpected);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
895
7e8cde5905fd allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
131 bool FilesystemHttpHandler::Handle(
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 HttpOutput& output,
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
133 RequestOrigin /*origin*/,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
134 const char* /*remoteIp*/,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1521
diff changeset
135 const char* /*username*/,
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
136 HttpMethod method,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 const UriComponents& uri,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 const Arguments& headers,
1363
feaf2840917c Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
139 const GetArguments& arguments,
3401
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
140 const void* /*bodyData*/,
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
141 size_t /*bodySize*/)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
143 if (!Toolbox::IsChildUri(pimpl_->baseUri_, uri))
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
144 {
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
145 // This URI is not served by this handler
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
146 return false;
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
147 }
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
148
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
149 if (method != HttpMethod_Get)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 908
diff changeset
151 output.SendMethodNotAllowed("GET");
895
7e8cde5905fd allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
152 return true;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
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 namespace fs = boost::filesystem;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 fs::path p = pimpl_->root_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 for (size_t i = pimpl_->baseUri_.size(); i < uri.size(); i++)
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 p /= uri[i];
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
163 if (SystemToolbox::IsRegularFile(p.string()))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
165 FilesystemHttpSender sender(p);
3023
c9c2faf76bec replaced 'var' by 'let' in Orthanc Explorer's JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2908
diff changeset
166 sender.SetContentType(SystemToolbox::AutodetectMimeType(p.string()));
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
167 output.Answer(sender); // TODO COMPRESSION
0
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 else if (listDirectoryContent_ &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 fs::exists(p) &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 fs::is_directory(p))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
1515
c94353fbd4e9 cont http compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
173 OutputDirectoryContent(output, headers, uri, p);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
177 output.SendStatus(HttpStatus_404_NotFound);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
895
7e8cde5905fd allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
179
7e8cde5905fd allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
180 return true;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }