Mercurial > hg > orthanc
annotate Core/HttpServer/HttpContentNegociation.h @ 2919:2ca9cd064b15
PamReader::ReadFromMemory
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 Nov 2018 15:41:21 +0100 |
parents | 878b59270859 |
children | 4e43e67f8ecf |
rev | line source |
---|---|
1783 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1783 | 4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
1783 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 #pragma once | |
34 | |
35 #include <memory> | |
36 #include <boost/noncopyable.hpp> | |
37 #include <map> | |
38 #include <list> | |
39 #include <string> | |
40 #include <vector> | |
41 #include <stdint.h> | |
42 | |
43 | |
44 namespace Orthanc | |
45 { | |
46 class HttpContentNegociation : public boost::noncopyable | |
47 { | |
48 public: | |
49 typedef std::map<std::string, std::string> HttpHeaders; | |
50 | |
51 class IHandler : public boost::noncopyable | |
52 { | |
53 public: | |
54 virtual ~IHandler() | |
55 { | |
56 } | |
57 | |
58 virtual void Handle(const std::string& type, | |
59 const std::string& subtype) = 0; | |
60 }; | |
61 | |
62 private: | |
63 struct Handler | |
64 { | |
65 std::string type_; | |
66 std::string subtype_; | |
67 IHandler& handler_; | |
68 | |
69 Handler(const std::string& type, | |
70 const std::string& subtype, | |
71 IHandler& handler); | |
72 | |
73 bool IsMatch(const std::string& type, | |
74 const std::string& subtype) const; | |
75 | |
76 void Call() const | |
77 { | |
78 handler_.Handle(type_, subtype_); | |
79 } | |
80 }; | |
81 | |
82 | |
83 struct Reference; | |
84 | |
85 typedef std::vector<std::string> Tokens; | |
86 typedef std::list<Handler> Handlers; | |
87 | |
88 Handlers handlers_; | |
89 | |
90 | |
91 static bool SplitPair(std::string& first /* out */, | |
92 std::string& second /* out */, | |
93 const std::string& source, | |
94 char separator); | |
95 | |
96 static float GetQuality(const Tokens& parameters); | |
97 | |
98 static void SelectBestMatch(std::auto_ptr<Reference>& best, | |
99 const Handler& handler, | |
100 const std::string& type, | |
101 const std::string& subtype, | |
102 float quality); | |
103 | |
104 public: | |
105 void Register(const std::string& mime, | |
106 IHandler& handler); | |
107 | |
108 bool Apply(const HttpHeaders& headers); | |
109 | |
110 bool Apply(const std::string& accept); | |
111 }; | |
112 } |