Audacity 3.2.0
NetworkManager.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file NetworkManager.cpp
6 @brief Define a class for performing HTTP requests.
7
8 Dmitry Vedenko
9 **********************************************************************/
10
11/*!********************************************************************
12
13 @class NetworkManager
14 @brief Class for performing HTTP requests.
15
16 **********************************************************************/
17
18#include "NetworkManager.h"
19
20#include "IResponseFactory.h"
22
23#include "MultipartData.h"
24
25#include "RequestPayload.h"
26
27namespace audacity
28{
29namespace network_manager
30{
31
33{
34 mResponseFactory = std::make_unique<CurlResponseFactory> ();
35}
36
38{}
39
41{
42 static NetworkManager instance;
43
44 return instance;
45}
46
48{
49 GetInstance ().mResponseFactory->terminate ();
50}
51
53{
54 return mResponseFactory->performRequest (RequestVerb::Get, request);
55}
56
58{
59 return mResponseFactory->performRequest (RequestVerb::Head, request);
60}
61
63{
64 return mResponseFactory->performRequest (RequestVerb::Delete, request);
65}
66
67ResponsePtr NetworkManager::doPost (const Request& request, const void* data, size_t size)
68{
69 return mResponseFactory->performRequest(
71}
72
74 const Request& request, RequestPayloadStreamPtr payloadStream)
75{
76 return mResponseFactory->performRequest(
77 RequestVerb::Post, request, std::move(payloadStream));
78}
79
81 const Request& request, std::unique_ptr<MultipartData> form)
82{
83 return mResponseFactory->performRequest(RequestVerb::Post, request, std::move(form));
84}
85
86ResponsePtr NetworkManager::doPut (const Request& request, const void* data, size_t size)
87{
88 return mResponseFactory->performRequest(
89 RequestVerb::Put, request, CreateRequestPayloadStream(data, size, true));
90}
91
93 const Request& request, RequestPayloadStreamPtr payloadStream)
94{
95 return mResponseFactory->performRequest(
96 RequestVerb::Put, request, std::move(payloadStream));
97}
98
100 const Request& request, std::unique_ptr<MultipartData> form)
101{
102 return mResponseFactory->performRequest(RequestVerb::Put, request, std::move(form));
103}
104
106NetworkManager::doPatch(const Request& request, const void* data, size_t size)
107{
108 return mResponseFactory->performRequest(
109 RequestVerb::Patch, request,
110 CreateRequestPayloadStream(data, size, true));
111}
112
114 const Request& request, RequestPayloadStreamPtr payloadStream)
115{
116 return mResponseFactory->performRequest(
117 RequestVerb::Patch, request, std::move(payloadStream));
118}
119
120void NetworkManager::setProxy (const std::string& proxy)
121{
122 mResponseFactory->setProxy (proxy);
123}
124
125}
126}
Declare an implementation of IResponseFactory using libcurl.
Declare a class for performing HTTP requests.
Declare a class for constructing HTTP requests.
ResponsePtr doHead(const Request &request)
ResponsePtr doPost(const Request &request, const void *data, size_t size)
ResponsePtr doDelete(const Request &request)
std::unique_ptr< IResponseFactory > mResponseFactory
ResponsePtr doPatch(const Request &request, const void *data, size_t size)
void setProxy(const std::string &proxy)
ResponsePtr doGet(const Request &request)
ResponsePtr doPut(const Request &request, const void *data, size_t size)
std::shared_ptr< IResponse > ResponsePtr
std::shared_ptr< RequestPayloadStream > RequestPayloadStreamPtr
Definition: CurlResponse.h:33
RequestPayloadStreamPtr CreateRequestPayloadStream(const void *data, int64_t size, bool copyData)