# HG changeset patch # User Sebastien Jodogne # Date 1359565004 -3600 # Node ID 753e69f9326eb98e1fbdd3146df9fba20d5bcc49 # Parent 4d76fce206efd078d45cda349b30e99a9abd8000 refactoring diff -r 4d76fce206ef -r 753e69f9326e Core/HttpServer/EmbeddedResourceHttpHandler.cpp --- a/Core/HttpServer/EmbeddedResourceHttpHandler.cpp Wed Jan 30 14:34:36 2013 +0100 +++ b/Core/HttpServer/EmbeddedResourceHttpHandler.cpp Wed Jan 30 17:56:44 2013 +0100 @@ -58,13 +58,13 @@ void EmbeddedResourceHttpHandler::Handle( HttpOutput& output, - const std::string& method, + Orthanc_HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& arguments, const std::string&) { - if (method != "GET") + if (method != Orthanc_HttpMethod_Get) { output.SendMethodNotAllowedError("GET"); return; diff -r 4d76fce206ef -r 753e69f9326e Core/HttpServer/EmbeddedResourceHttpHandler.h --- a/Core/HttpServer/EmbeddedResourceHttpHandler.h Wed Jan 30 14:34:36 2013 +0100 +++ b/Core/HttpServer/EmbeddedResourceHttpHandler.h Wed Jan 30 17:56:44 2013 +0100 @@ -54,7 +54,7 @@ virtual void Handle( HttpOutput& output, - const std::string& method, + Orthanc_HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& arguments, diff -r 4d76fce206ef -r 753e69f9326e Core/HttpServer/FilesystemHttpHandler.cpp --- a/Core/HttpServer/FilesystemHttpHandler.cpp Wed Jan 30 14:34:36 2013 +0100 +++ b/Core/HttpServer/FilesystemHttpHandler.cpp Wed Jan 30 17:56:44 2013 +0100 @@ -127,13 +127,13 @@ void FilesystemHttpHandler::Handle( HttpOutput& output, - const std::string& method, + Orthanc_HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& arguments, const std::string&) { - if (method != "GET") + if (method != Orthanc_HttpMethod_Get) { output.SendMethodNotAllowedError("GET"); return; diff -r 4d76fce206ef -r 753e69f9326e Core/HttpServer/FilesystemHttpHandler.h --- a/Core/HttpServer/FilesystemHttpHandler.h Wed Jan 30 14:34:36 2013 +0100 +++ b/Core/HttpServer/FilesystemHttpHandler.h Wed Jan 30 17:56:44 2013 +0100 @@ -56,7 +56,7 @@ virtual void Handle( HttpOutput& output, - const std::string& method, + Orthanc_HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& arguments, diff -r 4d76fce206ef -r 753e69f9326e Core/HttpServer/HttpHandler.h --- a/Core/HttpServer/HttpHandler.h Wed Jan 30 14:34:36 2013 +0100 +++ b/Core/HttpServer/HttpHandler.h Wed Jan 30 17:56:44 2013 +0100 @@ -36,6 +36,7 @@ #include #include #include "../Toolbox.h" +#include "../../OrthancCppClient/HttpEnumerations.h" namespace Orthanc { @@ -53,7 +54,7 @@ virtual bool IsServedUri(const UriComponents& uri) = 0; virtual void Handle(HttpOutput& output, - const std::string& method, + Orthanc_HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& getArguments, diff -r 4d76fce206ef -r 753e69f9326e Core/HttpServer/MongooseServer.cpp --- a/Core/HttpServer/MongooseServer.cpp Wed Jan 30 14:34:36 2013 +0100 +++ b/Core/HttpServer/MongooseServer.cpp Wed Jan 30 17:56:44 2013 +0100 @@ -464,6 +464,30 @@ MongooseServer* that = (MongooseServer*) (request->user_data); MongooseOutput output(connection); + // Compute the method + Orthanc_HttpMethod method; + if (!strcmp(request->request_method, "GET")) + { + method = Orthanc_HttpMethod_Get; + } + else if (!strcmp(request->request_method, "POST")) + { + method = Orthanc_HttpMethod_Post; + } + else if (!strcmp(request->request_method, "DELETE")) + { + method = Orthanc_HttpMethod_Delete; + } + else if (!strcmp(request->request_method, "PUT")) + { + method = Orthanc_HttpMethod_Put; + } + else + { + output.SendHeader(Orthanc_HttpStatus_405_MethodNotAllowed); + return (void*) ""; + } + if (!that->IsRemoteAccessAllowed() && request->remote_ip != LOCALHOST) { @@ -489,12 +513,12 @@ std::string postData; - if (!strcmp(request->request_method, "GET")) + if (method == Orthanc_HttpMethod_Get) { HttpHandler::ParseGetQuery(arguments, request->query_string); } - else if (!strcmp(request->request_method, "POST") || - !strcmp(request->request_method, "PUT")) + else if (method == Orthanc_HttpMethod_Post || + method == Orthanc_HttpMethod_Put) { HttpHandler::Arguments::const_iterator ct = headers.find("content-type"); if (ct == headers.end()) @@ -543,8 +567,7 @@ { try { - handler->Handle(output, std::string(request->request_method), - uri, headers, arguments, postData); + handler->Handle(output, method, uri, headers, arguments, postData); } catch (OrthancException& e) { diff -r 4d76fce206ef -r 753e69f9326e Core/RestApi/RestApi.cpp --- a/Core/RestApi/RestApi.cpp Wed Jan 30 14:34:36 2013 +0100 +++ b/Core/RestApi/RestApi.cpp Wed Jan 30 17:56:44 2013 +0100 @@ -180,7 +180,7 @@ } void RestApi::Handle(HttpOutput& output, - const std::string& method, + Orthanc_HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& getArguments, @@ -191,7 +191,7 @@ RestApiPath::Components components; UriComponents trailing; - if (method == "GET") + if (method == Orthanc_HttpMethod_Get) { for (GetHandlers::const_iterator it = getHandlers_.begin(); it != getHandlers_.end(); it++) @@ -213,7 +213,7 @@ } } } - else if (method == "PUT") + else if (method == Orthanc_HttpMethod_Put) { for (PutHandlers::const_iterator it = putHandlers_.begin(); it != putHandlers_.end(); it++) @@ -235,7 +235,7 @@ } } } - else if (method == "POST") + else if (method == Orthanc_HttpMethod_Post) { for (PostHandlers::const_iterator it = postHandlers_.begin(); it != postHandlers_.end(); it++) @@ -257,7 +257,7 @@ } } } - else if (method == "DELETE") + else if (method == Orthanc_HttpMethod_Delete) { for (DeleteHandlers::const_iterator it = deleteHandlers_.begin(); it != deleteHandlers_.end(); it++) diff -r 4d76fce206ef -r 753e69f9326e Core/RestApi/RestApi.h --- a/Core/RestApi/RestApi.h Wed Jan 30 14:34:36 2013 +0100 +++ b/Core/RestApi/RestApi.h Wed Jan 30 17:56:44 2013 +0100 @@ -212,7 +212,7 @@ virtual bool IsServedUri(const UriComponents& uri); virtual void Handle(HttpOutput& output, - const std::string& method, + Orthanc_HttpMethod method, const UriComponents& uri, const Arguments& headers, const Arguments& getArguments,