Mercurial > hg > orthanc
comparison Core/HttpServer/MongooseServer.cpp @ 895:7e8cde5905fd plugins
allow superposition of REST handlers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Jun 2014 17:47:58 +0200 |
parents | a811bdf8b8eb |
children | c4053ac5db04 |
comparison
equal
deleted
inserted
replaced
894:690aeb4cb899 | 895:7e8cde5905fd |
---|---|
253 return pimpl_->chunkStore_; | 253 return pimpl_->chunkStore_; |
254 } | 254 } |
255 | 255 |
256 | 256 |
257 | 257 |
258 HttpHandler* MongooseServer::FindHandler(const UriComponents& forUri) const | 258 void MongooseServer::FindHandlers(std::list<HttpHandler*>& result, |
259 const UriComponents& forUri) const | |
259 { | 260 { |
260 for (Handlers::const_iterator it = | 261 for (Handlers::const_iterator it = |
261 handlers_.begin(); it != handlers_.end(); ++it) | 262 handlers_.begin(); it != handlers_.end(); ++it) |
262 { | 263 { |
263 if ((*it)->IsServedUri(forUri)) | 264 if ((*it)->IsServedUri(forUri)) |
264 { | 265 { |
265 return *it; | 266 result.push_back(*it); |
266 } | 267 } |
267 } | 268 } |
268 | |
269 return NULL; | |
270 } | 269 } |
271 | 270 |
272 | 271 |
273 | 272 |
274 | 273 |
701 output.SendHeader(HttpStatus_400_BadRequest); | 700 output.SendHeader(HttpStatus_400_BadRequest); |
702 return (void*) ""; | 701 return (void*) ""; |
703 } | 702 } |
704 | 703 |
705 | 704 |
706 HttpHandler* handler = that->FindHandler(uri); | 705 std::list<HttpHandler*> handlers; |
707 if (handler) | 706 that->FindHandlers(handlers, uri); |
707 | |
708 bool found = false; | |
709 | |
710 for (std::list<HttpHandler*>::const_iterator | |
711 it = handlers.begin(); it != handlers.end() && !found; it++) | |
708 { | 712 { |
709 try | 713 try |
710 { | 714 { |
711 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); | 715 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); |
712 handler->Handle(output, method, uri, headers, argumentsGET, body); | 716 found = (*it)->Handle(output, method, uri, headers, argumentsGET, body); |
713 } | 717 } |
714 catch (OrthancException& e) | 718 catch (OrthancException& e) |
715 { | 719 { |
716 LOG(ERROR) << "MongooseServer Exception [" << e.What() << "]"; | 720 LOG(ERROR) << "MongooseServer Exception [" << e.What() << "]"; |
717 output.SendHeader(HttpStatus_500_InternalServerError); | 721 output.SendHeader(HttpStatus_500_InternalServerError); |
722 found = true; | |
718 } | 723 } |
719 catch (boost::bad_lexical_cast&) | 724 catch (boost::bad_lexical_cast&) |
720 { | 725 { |
721 LOG(ERROR) << "MongooseServer Exception: Bad lexical cast"; | 726 LOG(ERROR) << "MongooseServer Exception: Bad lexical cast"; |
722 output.SendHeader(HttpStatus_400_BadRequest); | 727 output.SendHeader(HttpStatus_400_BadRequest); |
728 found = true; | |
723 } | 729 } |
724 catch (std::runtime_error&) | 730 catch (std::runtime_error&) |
725 { | 731 { |
726 LOG(ERROR) << "MongooseServer Exception: Presumably a bad JSON request"; | 732 LOG(ERROR) << "MongooseServer Exception: Presumably a bad JSON request"; |
727 output.SendHeader(HttpStatus_400_BadRequest); | 733 output.SendHeader(HttpStatus_400_BadRequest); |
728 } | 734 found = true; |
729 } | 735 } |
730 else | 736 } |
737 | |
738 if (!found) | |
731 { | 739 { |
732 output.SendHeader(HttpStatus_404_NotFound); | 740 output.SendHeader(HttpStatus_404_NotFound); |
733 } | 741 } |
734 | 742 |
735 // Mark as processed | 743 // Mark as processed |