Mercurial > hg > orthanc
diff OrthancFramework/Sources/HttpServer/HttpToolbox.cpp @ 4329:9dc0e42f868b
moving static methods from HttpToolbox to IHttpHandler
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Nov 2020 13:46:49 +0100 |
parents | 9684a690ca63 |
children | a01b1c9cbef4 |
line wrap: on
line diff
--- a/OrthancFramework/Sources/HttpServer/HttpToolbox.cpp Wed Nov 25 13:34:58 2020 +0100 +++ b/OrthancFramework/Sources/HttpServer/HttpToolbox.cpp Wed Nov 25 13:46:49 2020 +0100 @@ -23,15 +23,7 @@ #include "../PrecompiledHeaders.h" #include "HttpToolbox.h" -#include "HttpOutput.h" -#include "StringHttpOutput.h" - -#include <stdio.h> #include <string.h> -#include <iostream> - - -static const char* LOCALHOST = "127.0.0.1"; namespace Orthanc @@ -185,102 +177,4 @@ compiled[source[i].first] = source[i].second; } } - - - bool HttpToolbox::SimpleGet(std::string& result, - IHttpHandler& handler, - RequestOrigin origin, - const std::string& uri, - const IHttpHandler::Arguments& httpHeaders) - { - UriComponents curi; - IHttpHandler::GetArguments getArguments; - ParseGetQuery(curi, getArguments, uri.c_str()); - - StringHttpOutput stream; - HttpOutput http(stream, false /* no keep alive */); - - if (handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Get, curi, - httpHeaders, getArguments, NULL /* no body for GET */, 0)) - { - stream.GetOutput(result); - return true; - } - else - { - return false; - } - } - - - static bool SimplePostOrPut(std::string& result, - IHttpHandler& handler, - RequestOrigin origin, - HttpMethod method, - const std::string& uri, - const void* bodyData, - size_t bodySize, - const IHttpHandler::Arguments& httpHeaders) - { - IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT - - UriComponents curi; - Toolbox::SplitUriComponents(curi, uri); - - StringHttpOutput stream; - HttpOutput http(stream, false /* no keep alive */); - - if (handler.Handle(http, origin, LOCALHOST, "", method, curi, - httpHeaders, getArguments, bodyData, bodySize)) - { - stream.GetOutput(result); - return true; - } - else - { - return false; - } - } - - - bool HttpToolbox::SimplePost(std::string& result, - IHttpHandler& handler, - RequestOrigin origin, - const std::string& uri, - const void* bodyData, - size_t bodySize, - const IHttpHandler::Arguments& httpHeaders) - { - return SimplePostOrPut(result, handler, origin, HttpMethod_Post, uri, bodyData, bodySize, httpHeaders); - } - - - bool HttpToolbox::SimplePut(std::string& result, - IHttpHandler& handler, - RequestOrigin origin, - const std::string& uri, - const void* bodyData, - size_t bodySize, - const IHttpHandler::Arguments& httpHeaders) - { - return SimplePostOrPut(result, handler, origin, HttpMethod_Put, uri, bodyData, bodySize, httpHeaders); - } - - - bool HttpToolbox::SimpleDelete(IHttpHandler& handler, - RequestOrigin origin, - const std::string& uri, - const IHttpHandler::Arguments& httpHeaders) - { - UriComponents curi; - Toolbox::SplitUriComponents(curi, uri); - - IHttpHandler::GetArguments getArguments; // No GET argument for DELETE - - StringHttpOutput stream; - HttpOutput http(stream, false /* no keep alive */); - - return handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Delete, curi, - httpHeaders, getArguments, NULL /* no body for DELETE */, 0); - } }