Mercurial > hg > orthanc
annotate OrthancFramework/Sources/HttpServer/HttpContentNegociation.cpp @ 5338:78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Jun 2023 08:29:43 +0200 |
parents | 0ea402b4d901 |
children | cb11e5ced4e3 |
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 |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1783 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
1783 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
1783 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1783 | 21 **/ |
22 | |
23 | |
24 #include "../PrecompiledHeaders.h" | |
25 #include "HttpContentNegociation.h" | |
26 | |
27 #include "../Logging.h" | |
28 #include "../OrthancException.h" | |
29 #include "../Toolbox.h" | |
30 | |
31 #include <boost/lexical_cast.hpp> | |
32 | |
33 namespace Orthanc | |
34 { | |
35 HttpContentNegociation::Handler::Handler(const std::string& type, | |
36 const std::string& subtype, | |
37 IHandler& handler) : | |
38 type_(type), | |
39 subtype_(subtype), | |
40 handler_(handler) | |
41 { | |
42 } | |
43 | |
44 | |
45 bool HttpContentNegociation::Handler::IsMatch(const std::string& type, | |
46 const std::string& subtype) const | |
47 { | |
48 if (type == "*" && subtype == "*") | |
49 { | |
50 return true; | |
51 } | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
52 else if (subtype == "*" && type == type_) |
1783 | 53 { |
54 return true; | |
55 } | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
56 else |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
57 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
58 return type == type_ && subtype == subtype_; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
59 } |
1783 | 60 } |
61 | |
62 | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
63 class HttpContentNegociation::Reference : public boost::noncopyable |
1783 | 64 { |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
65 private: |
1783 | 66 const Handler& handler_; |
67 uint8_t level_; | |
68 float quality_; | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
69 std::string application_; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
70 Dictionary parameters_; |
1783 | 71 |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
72 static float GetQuality(const Dictionary& parameters) |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
73 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
74 Dictionary::const_iterator found = parameters.find("q"); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
75 |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
76 if (found != parameters.end()) |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
77 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
78 float quality; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
79 bool ok = false; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
80 |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
81 try |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
82 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
83 quality = boost::lexical_cast<float>(found->second); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
84 ok = (quality >= 0.0f && quality <= 1.0f); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
85 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
86 catch (boost::bad_lexical_cast&) |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
87 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
88 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
89 |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
90 if (ok) |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
91 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
92 return quality; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
93 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
94 else |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
95 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
96 throw OrthancException( |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
97 ErrorCode_BadRequest, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
98 "Quality parameter out of range in a HTTP request (must be between 0 and 1): " + found->second); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
99 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
100 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
101 else |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
102 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
103 return 1.0f; // Default quality |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
104 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
105 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
106 |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
107 public: |
1783 | 108 Reference(const Handler& handler, |
109 const std::string& type, | |
110 const std::string& subtype, | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
111 const Dictionary& parameters) : |
1783 | 112 handler_(handler), |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
113 quality_(GetQuality(parameters)), |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
114 application_(type + "/" + subtype), |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
115 parameters_(parameters) |
1783 | 116 { |
117 if (type == "*" && subtype == "*") | |
118 { | |
119 level_ = 0; | |
120 } | |
121 else if (subtype == "*") | |
122 { | |
123 level_ = 1; | |
124 } | |
125 else | |
126 { | |
127 level_ = 2; | |
128 } | |
129 } | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
130 |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
131 void Call() const |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
132 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
133 handler_.Call(parameters_); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
134 } |
1783 | 135 |
136 bool operator< (const Reference& other) const | |
137 { | |
138 if (level_ < other.level_) | |
139 { | |
140 return true; | |
141 } | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
142 else if (level_ > other.level_) |
1783 | 143 { |
144 return false; | |
145 } | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
146 else |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
147 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
148 return quality_ < other.quality_; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
149 } |
1783 | 150 } |
151 }; | |
152 | |
153 | |
154 bool HttpContentNegociation::SplitPair(std::string& first /* out */, | |
155 std::string& second /* out */, | |
156 const std::string& source, | |
157 char separator) | |
158 { | |
159 size_t pos = source.find(separator); | |
160 | |
161 if (pos == std::string::npos) | |
162 { | |
163 return false; | |
164 } | |
165 else | |
166 { | |
167 first = Toolbox::StripSpaces(source.substr(0, pos)); | |
168 second = Toolbox::StripSpaces(source.substr(pos + 1)); | |
169 return true; | |
170 } | |
171 } | |
172 | |
173 | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
174 void HttpContentNegociation::SelectBestMatch(std::unique_ptr<Reference>& target, |
1783 | 175 const Handler& handler, |
176 const std::string& type, | |
177 const std::string& subtype, | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
178 const Dictionary& parameters) |
1783 | 179 { |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
180 std::unique_ptr<Reference> match(new Reference(handler, type, subtype, parameters)); |
1783 | 181 |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
182 if (target.get() == NULL || |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
183 *target < *match) |
1783 | 184 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
185 #if __cplusplus < 201103L |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
186 target.reset(match.release()); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
187 #else |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
188 target = std::move(match); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
189 #endif |
1783 | 190 } |
191 } | |
192 | |
193 | |
194 void HttpContentNegociation::Register(const std::string& mime, | |
195 IHandler& handler) | |
196 { | |
197 std::string type, subtype; | |
198 | |
199 if (SplitPair(type, subtype, mime, '/') && | |
200 type != "*" && | |
201 subtype != "*") | |
202 { | |
203 handlers_.push_back(Handler(type, subtype, handler)); | |
204 } | |
205 else | |
206 { | |
207 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
208 } | |
209 } | |
210 | |
211 | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
212 bool HttpContentNegociation::Apply(const Dictionary& headers) |
1783 | 213 { |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
214 Dictionary::const_iterator accept = headers.find("accept"); |
1783 | 215 if (accept != headers.end()) |
216 { | |
217 return Apply(accept->second); | |
218 } | |
219 else | |
220 { | |
221 return Apply("*/*"); | |
222 } | |
223 } | |
224 | |
225 | |
226 bool HttpContentNegociation::Apply(const std::string& accept) | |
227 { | |
228 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 | |
229 // https://en.wikipedia.org/wiki/Content_negotiation | |
230 // http://www.newmediacampaigns.com/blog/browser-rest-http-accept-headers | |
231 | |
232 Tokens mediaRanges; | |
233 Toolbox::TokenizeString(mediaRanges, accept, ','); | |
234 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
235 std::unique_ptr<Reference> bestMatch; |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
236 Dictionary bestParameters; |
1783 | 237 |
238 for (Tokens::const_iterator it = mediaRanges.begin(); | |
239 it != mediaRanges.end(); ++it) | |
240 { | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
241 Tokens tokens; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
242 Toolbox::TokenizeString(tokens, *it, ';'); |
1783 | 243 |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
244 if (tokens.size() > 0) |
1783 | 245 { |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
246 Dictionary parameters; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
247 for (size_t i = 1; i < tokens.size(); i++) |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
248 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
249 std::string key, value; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
250 |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
251 if (!SplitPair(key, value, tokens[i], '=')) |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
252 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
253 key = Toolbox::StripSpaces(tokens[i]); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
254 value = ""; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
255 } |
1783 | 256 |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
257 parameters[key] = value; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
258 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
259 |
1783 | 260 std::string type, subtype; |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
261 if (SplitPair(type, subtype, tokens[0], '/')) |
1783 | 262 { |
263 for (Handlers::const_iterator it2 = handlers_.begin(); | |
264 it2 != handlers_.end(); ++it2) | |
265 { | |
266 if (it2->IsMatch(type, subtype)) | |
267 { | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
268 SelectBestMatch(bestMatch, *it2, type, subtype, parameters); |
1783 | 269 } |
270 } | |
271 } | |
272 } | |
273 } | |
274 | |
275 if (bestMatch.get() == NULL) // No match was found | |
276 { | |
277 return false; | |
278 } | |
279 else | |
280 { | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
281 bestMatch->Call(); |
1783 | 282 return true; |
283 } | |
284 } | |
285 } |