comparison Core/HttpClient.h @ 3393:2cd0369a156f

support of chunked answers in HttpClient and in SDK
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Jun 2019 16:12:55 +0200
parents ad434967a68c
children 94f4a18a79cc
comparison
equal deleted inserted replaced
3392:ad434967a68c 3393:2cd0369a156f
55 class HttpClient : public boost::noncopyable 55 class HttpClient : public boost::noncopyable
56 { 56 {
57 public: 57 public:
58 typedef std::map<std::string, std::string> HttpHeaders; 58 typedef std::map<std::string, std::string> HttpHeaders;
59 59
60 class IRequestChunkedBody : public boost::noncopyable 60 class IRequestBody : public boost::noncopyable
61 { 61 {
62 public: 62 public:
63 virtual ~IRequestChunkedBody() 63 virtual ~IRequestBody()
64 { 64 {
65 } 65 }
66 66
67 virtual bool ReadNextChunk(std::string& chunk) = 0; 67 virtual bool ReadNextChunk(std::string& chunk) = 0;
68 }; 68 };
69 69
70 class IAnswer : public boost::noncopyable
71 {
72 public:
73 virtual ~IAnswer()
74 {
75 }
76
77 virtual void AddHeader(const std::string& key,
78 const std::string& value) = 0;
79
80 virtual void AddChunk(const void* data,
81 size_t size) = 0;
82 };
83
70 private: 84 private:
71 class CurlHeaders; 85 class CurlHeaders;
72 class CurlRequestChunkedBody; 86 class CurlRequestBody;
87 class CurlAnswer;
88 class DefaultAnswer;
73 class GlobalParameters; 89 class GlobalParameters;
74 90
75 struct PImpl; 91 struct PImpl;
76 boost::shared_ptr<PImpl> pimpl_; 92 boost::shared_ptr<PImpl> pimpl_;
77 93
95 void Setup(); 111 void Setup();
96 112
97 void operator= (const HttpClient&); // Assignment forbidden 113 void operator= (const HttpClient&); // Assignment forbidden
98 HttpClient(const HttpClient& base); // Copy forbidden 114 HttpClient(const HttpClient& base); // Copy forbidden
99 115
116 bool ApplyInternal(CurlAnswer& answer);
117
100 bool ApplyInternal(std::string& answerBody, 118 bool ApplyInternal(std::string& answerBody,
101 HttpHeaders* answerHeaders); 119 HttpHeaders* answerHeaders);
102 120
103 bool ApplyInternal(Json::Value& answerBody, 121 bool ApplyInternal(Json::Value& answerBody,
104 HttpHeaders* answerHeaders); 122 HttpHeaders* answerHeaders);
156 const std::string& GetBody() const 174 const std::string& GetBody() const
157 { 175 {
158 return body_; 176 return body_;
159 } 177 }
160 178
161 void SetBody(IRequestChunkedBody& body); 179 void SetBody(IRequestBody& body);
162 180
163 void ClearBody(); 181 void ClearBody();
164 182
165 void SetVerbose(bool isVerbose); 183 void SetVerbose(bool isVerbose);
166 184
171 189
172 void AddHeader(const std::string& key, 190 void AddHeader(const std::string& key,
173 const std::string& value); 191 const std::string& value);
174 192
175 void ClearHeaders(); 193 void ClearHeaders();
194
195 bool Apply(IAnswer& answer);
176 196
177 bool Apply(std::string& answerBody) 197 bool Apply(std::string& answerBody)
178 { 198 {
179 return ApplyInternal(answerBody, NULL); 199 return ApplyInternal(answerBody, NULL);
180 } 200 }
293 313
294 static void SetDefaultProxy(const std::string& proxy); 314 static void SetDefaultProxy(const std::string& proxy);
295 315
296 static void SetDefaultTimeout(long timeout); 316 static void SetDefaultTimeout(long timeout);
297 317
318 void ApplyAndThrowException(IAnswer& answer);
319
298 void ApplyAndThrowException(std::string& answerBody); 320 void ApplyAndThrowException(std::string& answerBody);
299 321
300 void ApplyAndThrowException(Json::Value& answerBody); 322 void ApplyAndThrowException(Json::Value& answerBody);
301 323
302 void ApplyAndThrowException(std::string& answerBody, 324 void ApplyAndThrowException(std::string& answerBody,