comparison Core/RestApi/RestApiHierarchy.cpp @ 1441:f3672356c121

refactoring: IHttpHandler and HttpToolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 10:38:39 +0200
parents bba8a47922d1
children b2b09a3dbd8e
comparison
equal deleted inserted replaced
1440:3567503c00a7 1441:f3672356c121
197 child->RegisterInternal(path, handler, level + 1); 197 child->RegisterInternal(path, handler, level + 1);
198 } 198 }
199 } 199 }
200 200
201 201
202 bool RestApiHierarchy::LookupResource(HttpHandler::Arguments& components, 202 bool RestApiHierarchy::LookupResource(IHttpHandler::Arguments& components,
203 const UriComponents& uri, 203 const UriComponents& uri,
204 IVisitor& visitor, 204 IVisitor& visitor,
205 size_t level) 205 size_t level)
206 { 206 {
207 if (uri.size() != 0 && 207 if (uri.size() != 0 &&
238 238
239 // Try and go down in the hierarchy, using wildcard rules for children 239 // Try and go down in the hierarchy, using wildcard rules for children
240 for (child = wildcardChildren_.begin(); 240 for (child = wildcardChildren_.begin();
241 child != wildcardChildren_.end(); ++child) 241 child != wildcardChildren_.end(); ++child)
242 { 242 {
243 HttpHandler::Arguments subComponents = components; 243 IHttpHandler::Arguments subComponents = components;
244 subComponents[child->first] = uri[level]; 244 subComponents[child->first] = uri[level];
245 245
246 if (child->second->LookupResource(subComponents, uri, visitor, level + 1)) 246 if (child->second->LookupResource(subComponents, uri, visitor, level + 1))
247 { 247 {
248 return true; 248 return true;
402 402
403 403
404 bool RestApiHierarchy::LookupResource(const UriComponents& uri, 404 bool RestApiHierarchy::LookupResource(const UriComponents& uri,
405 IVisitor& visitor) 405 IVisitor& visitor)
406 { 406 {
407 HttpHandler::Arguments components; 407 IHttpHandler::Arguments components;
408 return LookupResource(components, uri, visitor, 0); 408 return LookupResource(components, uri, visitor, 0);
409 } 409 }
410 410
411 411
412 412
424 { 424 {
425 } 425 }
426 426
427 virtual bool Visit(const RestApiHierarchy::Resource& resource, 427 virtual bool Visit(const RestApiHierarchy::Resource& resource,
428 const UriComponents& uri, 428 const UriComponents& uri,
429 const HttpHandler::Arguments& components, 429 const IHttpHandler::Arguments& components,
430 const UriComponents& trailing) 430 const UriComponents& trailing)
431 { 431 {
432 if (trailing.size() == 0) // Ignore universal handlers 432 if (trailing.size() == 0) // Ignore universal handlers
433 { 433 {
434 if (resource.HasHandler(HttpMethod_Get)) 434 if (resource.HasHandler(HttpMethod_Get))
458 } 458 }
459 459
460 void RestApiHierarchy::GetAcceptedMethods(std::set<HttpMethod>& methods, 460 void RestApiHierarchy::GetAcceptedMethods(std::set<HttpMethod>& methods,
461 const UriComponents& uri) 461 const UriComponents& uri)
462 { 462 {
463 HttpHandler::Arguments components; 463 IHttpHandler::Arguments components;
464 AcceptedMethodsVisitor visitor(methods); 464 AcceptedMethodsVisitor visitor(methods);
465 LookupResource(components, uri, visitor, 0); 465 LookupResource(components, uri, visitor, 0);
466 466
467 Json::Value d; 467 Json::Value d;
468 if (GetDirectory(d, uri)) 468 if (GetDirectory(d, uri))