0
|
1 /**
|
59
|
2 * Orthanc - A Lightweight, RESTful DICOM Store
|
0
|
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
|
|
4 * Belgium
|
|
5 *
|
|
6 * This program is free software: you can redistribute it and/or
|
|
7 * modify it under the terms of the GNU General Public License as
|
|
8 * published by the Free Software Foundation, either version 3 of the
|
|
9 * License, or (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful, but
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 **/
|
|
19
|
|
20
|
|
21 #include "EmbeddedResourceHttpHandler.h"
|
|
22
|
59
|
23 #include "../OrthancException.h"
|
0
|
24
|
|
25 #include <stdio.h>
|
|
26
|
|
27
|
59
|
28 namespace Orthanc
|
0
|
29 {
|
|
30 EmbeddedResourceHttpHandler::EmbeddedResourceHttpHandler(
|
|
31 const std::string& baseUri,
|
|
32 EmbeddedResources::DirectoryResourceId resourceId)
|
|
33 {
|
|
34 Toolbox::SplitUriComponents(baseUri_, baseUri);
|
|
35 resourceId_ = resourceId;
|
|
36 }
|
|
37
|
|
38
|
|
39 bool EmbeddedResourceHttpHandler::IsServedUri(const UriComponents& uri)
|
|
40 {
|
|
41 return Toolbox::IsChildUri(baseUri_, uri);
|
|
42 }
|
|
43
|
|
44
|
|
45 void EmbeddedResourceHttpHandler::Handle(
|
|
46 HttpOutput& output,
|
|
47 const std::string& method,
|
|
48 const UriComponents& uri,
|
|
49 const Arguments& headers,
|
|
50 const Arguments& arguments,
|
|
51 const std::string&)
|
|
52 {
|
|
53 if (method != "GET")
|
|
54 {
|
|
55 output.SendMethodNotAllowedError("GET");
|
|
56 return;
|
|
57 }
|
|
58
|
|
59 std::string resourcePath = Toolbox::FlattenUri(uri, baseUri_.size());
|
|
60 std::string contentType = Toolbox::AutodetectMimeType(resourcePath);
|
|
61
|
|
62 try
|
|
63 {
|
|
64 const void* buffer = EmbeddedResources::GetDirectoryResourceBuffer(resourceId_, resourcePath.c_str());
|
|
65 size_t size = EmbeddedResources::GetDirectoryResourceSize(resourceId_, resourcePath.c_str());
|
|
66 output.AnswerBufferWithContentType(buffer, size, contentType);
|
|
67 }
|
59
|
68 catch (OrthancException& e)
|
0
|
69 {
|
59
|
70 output.SendHeader(Orthanc_HttpStatus_404_NotFound);
|
0
|
71 }
|
|
72 }
|
|
73 }
|