Mercurial > hg > orthanc
comparison Core/HttpServer/EmbeddedResourceHttpHandler.cpp @ 0:3959d33612cc
initial commit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Jul 2012 14:32:22 +0200 |
parents | |
children | 9be852ad33d2 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3959d33612cc |
---|---|
1 /** | |
2 * Palantir - A Lightweight, RESTful DICOM Store | |
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 | |
23 #include "../PalantirException.h" | |
24 | |
25 #include <stdio.h> | |
26 | |
27 | |
28 namespace Palantir | |
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 } | |
68 catch (PalantirException& e) | |
69 { | |
70 output.SendHeader(HttpStatus_404_NotFound); | |
71 } | |
72 } | |
73 } |