annotate Core/HttpServer/HttpContentNegociation.h @ 3430:4c45e018bd3d

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