diff 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
line wrap: on
line diff
--- a/Core/HttpClient.h	Thu Jun 06 10:35:16 2019 +0200
+++ b/Core/HttpClient.h	Thu Jun 06 16:12:55 2019 +0200
@@ -57,19 +57,35 @@
   public:
     typedef std::map<std::string, std::string>  HttpHeaders;
 
-    class IRequestChunkedBody : public boost::noncopyable
+    class IRequestBody : public boost::noncopyable
     {
     public:
-      virtual ~IRequestChunkedBody()
+      virtual ~IRequestBody()
       {
       }
       
       virtual bool ReadNextChunk(std::string& chunk) = 0;
     };
 
+    class IAnswer : public boost::noncopyable
+    {
+    public:
+      virtual ~IAnswer()
+      {
+      }
+
+      virtual void AddHeader(const std::string& key,
+                             const std::string& value) = 0;
+      
+      virtual void AddChunk(const void* data,
+                            size_t size) = 0;
+    };
+
   private:
     class CurlHeaders;
-    class CurlRequestChunkedBody;
+    class CurlRequestBody;
+    class CurlAnswer;
+    class DefaultAnswer;
     class GlobalParameters;
 
     struct PImpl;
@@ -97,6 +113,8 @@
     void operator= (const HttpClient&);  // Assignment forbidden
     HttpClient(const HttpClient& base);  // Copy forbidden
 
+    bool ApplyInternal(CurlAnswer& answer);
+
     bool ApplyInternal(std::string& answerBody,
                        HttpHeaders* answerHeaders);
 
@@ -158,7 +176,7 @@
       return body_;
     }
 
-    void SetBody(IRequestChunkedBody& body);
+    void SetBody(IRequestBody& body);
 
     void ClearBody();
 
@@ -174,6 +192,8 @@
 
     void ClearHeaders();
 
+    bool Apply(IAnswer& answer);
+
     bool Apply(std::string& answerBody)
     {
       return ApplyInternal(answerBody, NULL);
@@ -295,6 +315,8 @@
 
     static void SetDefaultTimeout(long timeout);
 
+    void ApplyAndThrowException(IAnswer& answer);
+
     void ApplyAndThrowException(std::string& answerBody);
 
     void ApplyAndThrowException(Json::Value& answerBody);