Mercurial > hg > orthanc
annotate Core/HttpServer/HttpContentNegociation.h @ 3822:0d5f3a438e14 transcoding
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 10 Apr 2020 11:39:40 +0200 |
parents | 2a170a8f1faf |
children | f9863630ec7f |
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 |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 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 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
35 #include "../Compatibility.h" |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
36 |
1783 | 37 #include <memory> |
38 #include <boost/noncopyable.hpp> | |
39 #include <map> | |
40 #include <list> | |
41 #include <string> | |
42 #include <vector> | |
43 #include <stdint.h> | |
44 | |
45 | |
46 namespace Orthanc | |
47 { | |
48 class HttpContentNegociation : public boost::noncopyable | |
49 { | |
50 public: | |
51 typedef std::map<std::string, std::string> HttpHeaders; | |
52 | |
53 class IHandler : public boost::noncopyable | |
54 { | |
55 public: | |
56 virtual ~IHandler() | |
57 { | |
58 } | |
59 | |
60 virtual void Handle(const std::string& type, | |
61 const std::string& subtype) = 0; | |
62 }; | |
63 | |
64 private: | |
65 struct Handler | |
66 { | |
67 std::string type_; | |
68 std::string subtype_; | |
69 IHandler& handler_; | |
70 | |
71 Handler(const std::string& type, | |
72 const std::string& subtype, | |
73 IHandler& handler); | |
74 | |
75 bool IsMatch(const std::string& type, | |
76 const std::string& subtype) const; | |
77 | |
78 void Call() const | |
79 { | |
80 handler_.Handle(type_, subtype_); | |
81 } | |
82 }; | |
83 | |
84 | |
85 struct Reference; | |
86 | |
87 typedef std::vector<std::string> Tokens; | |
88 typedef std::list<Handler> Handlers; | |
89 | |
90 Handlers handlers_; | |
91 | |
92 | |
93 static bool SplitPair(std::string& first /* out */, | |
94 std::string& second /* out */, | |
95 const std::string& source, | |
96 char separator); | |
97 | |
98 static float GetQuality(const Tokens& parameters); | |
99 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
100 static void SelectBestMatch(std::unique_ptr<Reference>& best, |
1783 | 101 const Handler& handler, |
102 const std::string& type, | |
103 const std::string& subtype, | |
104 float quality); | |
105 | |
106 public: | |
107 void Register(const std::string& mime, | |
108 IHandler& handler); | |
109 | |
110 bool Apply(const HttpHeaders& headers); | |
111 | |
112 bool Apply(const std::string& accept); | |
113 }; | |
114 } |