Mercurial > hg > orthanc
annotate OrthancServer/Sources/EmbeddedResourceHttpHandler.cpp @ 5152:c81f363d3aa3 malloc-trim
housekeeper thread to call malloc_trim and give back memory to the system
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 01 Feb 2023 18:38:39 +0100 |
parents | 6eff25f70121 |
children | 0ea402b4d901 |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1113
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
4031
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
23 #include "PrecompiledHeadersServer.h" |
0 | 24 #include "EmbeddedResourceHttpHandler.h" |
25 | |
4045 | 26 #include "../../OrthancFramework/Sources/HttpServer/HttpOutput.h" |
27 #include "../../OrthancFramework/Sources/Logging.h" | |
28 #include "../../OrthancFramework/Sources/OrthancException.h" | |
29 #include "../../OrthancFramework/Sources/SystemToolbox.h" | |
0 | 30 |
31 | |
59 | 32 namespace Orthanc |
0 | 33 { |
34 EmbeddedResourceHttpHandler::EmbeddedResourceHttpHandler( | |
35 const std::string& baseUri, | |
4031
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
36 ServerResources::DirectoryResourceId resourceId) |
0 | 37 { |
38 Toolbox::SplitUriComponents(baseUri_, baseUri); | |
39 resourceId_ = resourceId; | |
40 } | |
41 | |
42 | |
895
7e8cde5905fd
allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
43 bool EmbeddedResourceHttpHandler::Handle( |
0 | 44 HttpOutput& output, |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1521
diff
changeset
|
45 RequestOrigin /*origin*/, |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1521
diff
changeset
|
46 const char* /*remoteIp*/, |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1521
diff
changeset
|
47 const char* /*username*/, |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
48 HttpMethod method, |
0 | 49 const UriComponents& uri, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
50 const HttpToolbox::Arguments& headers, |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
51 const HttpToolbox::GetArguments& arguments, |
3401 | 52 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
|
53 size_t /*bodySize*/) |
0 | 54 { |
901
7d88f3f4a3b3
refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
895
diff
changeset
|
55 if (!Toolbox::IsChildUri(baseUri_, uri)) |
7d88f3f4a3b3
refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
895
diff
changeset
|
56 { |
7d88f3f4a3b3
refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
895
diff
changeset
|
57 // 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
|
58 return false; |
7d88f3f4a3b3
refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
895
diff
changeset
|
59 } |
7d88f3f4a3b3
refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
895
diff
changeset
|
60 |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
61 if (method != HttpMethod_Get) |
0 | 62 { |
1042
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
901
diff
changeset
|
63 output.SendMethodNotAllowed("GET"); |
895
7e8cde5905fd
allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
64 return true; |
0 | 65 } |
66 | |
67 std::string resourcePath = Toolbox::FlattenUri(uri, baseUri_.size()); | |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
68 MimeType contentType = SystemToolbox::AutodetectMimeType(resourcePath); |
0 | 69 |
70 try | |
71 { | |
4031
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
72 const void* buffer = ServerResources::GetDirectoryResourceBuffer(resourceId_, resourcePath.c_str()); |
e3b3af80732d
ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
73 size_t size = ServerResources::GetDirectoryResourceSize(resourceId_, resourcePath.c_str()); |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
74 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
75 output.SetContentType(contentType); |
1521 | 76 output.Answer(buffer, size); |
0 | 77 } |
627 | 78 catch (OrthancException&) |
0 | 79 { |
125 | 80 LOG(WARNING) << "Unable to find HTTP resource: " << resourcePath; |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
81 output.SendStatus(HttpStatus_404_NotFound); |
0 | 82 } |
895
7e8cde5905fd
allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
83 |
7e8cde5905fd
allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
84 return true; |
0 | 85 } |
86 } |