comparison Core/HttpServer/MongooseServer.cpp @ 355:753e69f9326e

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Jan 2013 17:56:44 +0100
parents 795ce0fa8e8a
children bdd72233b105
comparison
equal deleted inserted replaced
354:4d76fce206ef 355:753e69f9326e
462 if (event == MG_NEW_REQUEST) 462 if (event == MG_NEW_REQUEST)
463 { 463 {
464 MongooseServer* that = (MongooseServer*) (request->user_data); 464 MongooseServer* that = (MongooseServer*) (request->user_data);
465 MongooseOutput output(connection); 465 MongooseOutput output(connection);
466 466
467 // Compute the method
468 Orthanc_HttpMethod method;
469 if (!strcmp(request->request_method, "GET"))
470 {
471 method = Orthanc_HttpMethod_Get;
472 }
473 else if (!strcmp(request->request_method, "POST"))
474 {
475 method = Orthanc_HttpMethod_Post;
476 }
477 else if (!strcmp(request->request_method, "DELETE"))
478 {
479 method = Orthanc_HttpMethod_Delete;
480 }
481 else if (!strcmp(request->request_method, "PUT"))
482 {
483 method = Orthanc_HttpMethod_Put;
484 }
485 else
486 {
487 output.SendHeader(Orthanc_HttpStatus_405_MethodNotAllowed);
488 return (void*) "";
489 }
490
467 if (!that->IsRemoteAccessAllowed() && 491 if (!that->IsRemoteAccessAllowed() &&
468 request->remote_ip != LOCALHOST) 492 request->remote_ip != LOCALHOST)
469 { 493 {
470 SendUnauthorized(output); 494 SendUnauthorized(output);
471 return (void*) ""; 495 return (void*) "";
487 return (void*) ""; 511 return (void*) "";
488 } 512 }
489 513
490 std::string postData; 514 std::string postData;
491 515
492 if (!strcmp(request->request_method, "GET")) 516 if (method == Orthanc_HttpMethod_Get)
493 { 517 {
494 HttpHandler::ParseGetQuery(arguments, request->query_string); 518 HttpHandler::ParseGetQuery(arguments, request->query_string);
495 } 519 }
496 else if (!strcmp(request->request_method, "POST") || 520 else if (method == Orthanc_HttpMethod_Post ||
497 !strcmp(request->request_method, "PUT")) 521 method == Orthanc_HttpMethod_Put)
498 { 522 {
499 HttpHandler::Arguments::const_iterator ct = headers.find("content-type"); 523 HttpHandler::Arguments::const_iterator ct = headers.find("content-type");
500 if (ct == headers.end()) 524 if (ct == headers.end())
501 { 525 {
502 output.SendHeader(Orthanc_HttpStatus_400_BadRequest); 526 output.SendHeader(Orthanc_HttpStatus_400_BadRequest);
541 HttpHandler* handler = that->FindHandler(uri); 565 HttpHandler* handler = that->FindHandler(uri);
542 if (handler) 566 if (handler)
543 { 567 {
544 try 568 try
545 { 569 {
546 handler->Handle(output, std::string(request->request_method), 570 handler->Handle(output, method, uri, headers, arguments, postData);
547 uri, headers, arguments, postData);
548 } 571 }
549 catch (OrthancException& e) 572 catch (OrthancException& e)
550 { 573 {
551 LOG(ERROR) << "MongooseServer Exception [" << e.What() << "]"; 574 LOG(ERROR) << "MongooseServer Exception [" << e.What() << "]";
552 output.SendHeader(Orthanc_HttpStatus_500_InternalServerError); 575 output.SendHeader(Orthanc_HttpStatus_500_InternalServerError);