comparison Core/HttpServer/MongooseServer.cpp @ 901:7d88f3f4a3b3 plugins

refactoring IsServedUri, answer PNG images, regular expression groups
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Jun 2014 15:22:13 +0200
parents bb0a51561016
children e078ea944089
comparison
equal deleted inserted replaced
900:1b92ce45cc8d 901:7d88f3f4a3b3
253 return pimpl_->chunkStore_; 253 return pimpl_->chunkStore_;
254 } 254 }
255 255
256 256
257 257
258 void MongooseServer::FindHandlers(std::list<HttpHandler*>& result,
259 const UriComponents& forUri) const
260 {
261 for (Handlers::const_iterator it =
262 handlers_.begin(); it != handlers_.end(); ++it)
263 {
264 if ((*it)->IsServedUri(forUri))
265 {
266 result.push_back(*it);
267 }
268 }
269 }
270
271
272
273
274 static PostDataStatus ReadBody(std::string& postData, 258 static PostDataStatus ReadBody(std::string& postData,
275 struct mg_connection *connection, 259 struct mg_connection *connection,
276 const HttpHandler::Arguments& headers) 260 const HttpHandler::Arguments& headers)
277 { 261 {
278 HttpHandler::Arguments::const_iterator cs = headers.find("content-length"); 262 HttpHandler::Arguments::const_iterator cs = headers.find("content-length");
700 output.SendHeader(HttpStatus_400_BadRequest); 684 output.SendHeader(HttpStatus_400_BadRequest);
701 return (void*) ""; 685 return (void*) "";
702 } 686 }
703 687
704 688
705 // Locate the candidate handlers for this URI 689 // Loop over the candidate handlers for this URI
706 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); 690 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri);
707 std::list<HttpHandler*> handlers;
708 that->FindHandlers(handlers, uri);
709
710 bool found = false; 691 bool found = false;
711 bool isError = false; 692 bool isError = false;
712 HttpStatus errorStatus; 693 HttpStatus errorStatus;
713 std::string errorDescription; 694 std::string errorDescription;
714 695
715 696 for (MongooseServer::Handlers::const_iterator it =
716 // Loop over the candidate handlers for this URI 697 that->GetHandlers().begin(); it != that->GetHandlers().end(); ++it)
717 for (std::list<HttpHandler*>::const_iterator
718 it = handlers.begin(); it != handlers.end() && !found; it++)
719 { 698 {
720 try 699 try
721 { 700 {
722 found = (*it)->Handle(output, method, uri, headers, argumentsGET, body); 701 found = (*it)->Handle(output, method, uri, headers, argumentsGET, body);
723 } 702 }