annotate Core/HttpServer/HttpContentNegociation.h @ 2057:54417b0831c4

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