Mercurial > hg > orthanc
comparison Plugins/Samples/Common/OrthancPluginCppWrapper.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 | 9019279dbfd7 |
comparison
equal
deleted
inserted
replaced
3392:ad434967a68c | 3393:2cd0369a156f |
---|---|
90 #else | 90 #else |
91 # define HAS_ORTHANC_PLUGIN_HTTP_CLIENT 0 | 91 # define HAS_ORTHANC_PLUGIN_HTTP_CLIENT 0 |
92 #endif | 92 #endif |
93 | 93 |
94 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 7) | 94 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 7) |
95 # define HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY 1 | 95 # define HAS_ORTHANC_PLUGIN_STREAMING_HTTP_CLIENT 1 |
96 #else | 96 #else |
97 # define HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY 0 | 97 # define HAS_ORTHANC_PLUGIN_STREAMING_HTTP_CLIENT 0 |
98 #endif | 98 #endif |
99 | 99 |
100 | 100 |
101 | 101 |
102 namespace OrthancPlugins | 102 namespace OrthancPlugins |
787 | 787 |
788 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 | 788 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 |
789 class HttpClient : public boost::noncopyable | 789 class HttpClient : public boost::noncopyable |
790 { | 790 { |
791 public: | 791 public: |
792 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY == 1 | 792 typedef std::map<std::string, std::string> HttpHeaders; |
793 class IRequestChunkedBody : public boost::noncopyable | 793 |
794 class IRequestBody : public boost::noncopyable | |
794 { | 795 { |
795 public: | 796 public: |
796 virtual ~IRequestChunkedBody() | 797 virtual ~IRequestBody() |
797 { | 798 { |
798 } | 799 } |
799 | 800 |
800 virtual bool ReadNextChunk(std::string& chunk) = 0; | 801 virtual bool ReadNextChunk(std::string& chunk) = 0; |
801 }; | 802 }; |
802 #endif | 803 |
803 | 804 #if HAS_ORTHANC_PLUGIN_STREAMING_HTTP_CLIENT == 1 |
805 class IAnswer : public boost::noncopyable | |
806 { | |
807 public: | |
808 virtual ~IAnswer() | |
809 { | |
810 } | |
811 | |
812 virtual void AddHeader(const std::string& key, | |
813 const std::string& value) = 0; | |
814 | |
815 virtual void AddChunk(const void* data, | |
816 size_t size) = 0; | |
817 }; | |
818 #endif | |
819 | |
804 | 820 |
805 private: | 821 private: |
806 typedef std::map<std::string, std::string> HttpHeaders; | 822 class RequestBodyWrapper; |
807 | 823 |
808 MemoryBuffer answerBody_; | |
809 MemoryBuffer answerHeaders_; | |
810 uint16_t httpStatus_; | 824 uint16_t httpStatus_; |
811 OrthancPluginHttpMethod method_; | 825 OrthancPluginHttpMethod method_; |
812 std::string url_; | 826 std::string url_; |
813 HttpHeaders headers_; | 827 HttpHeaders headers_; |
814 std::string username_; | 828 std::string username_; |
817 std::string certificateFile_; | 831 std::string certificateFile_; |
818 std::string certificateKeyFile_; | 832 std::string certificateKeyFile_; |
819 std::string certificateKeyPassword_; | 833 std::string certificateKeyPassword_; |
820 bool pkcs11_; | 834 bool pkcs11_; |
821 std::string body_; | 835 std::string body_; |
822 | 836 IRequestBody* streamingBody_; |
823 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY == 1 | 837 |
824 class RequestChunkedBody; | 838 #if HAS_ORTHANC_PLUGIN_STREAMING_HTTP_CLIENT == 1 |
825 IRequestChunkedBody* chunkedBody_; | 839 void ExecuteWithStream(uint16_t& httpStatus, // out |
826 #else | 840 IAnswer& answer, // out |
827 // Dummy variable for backward compatibility | 841 IRequestBody& body) const; |
828 void* chunkedBody_; | 842 #endif |
829 #endif | 843 |
830 | 844 void ExecuteWithoutStream(uint16_t& httpStatus, // out |
845 HttpHeaders& answerHeaders, // out | |
846 std::string& answerBody, // out | |
847 const std::string& body) const; | |
848 | |
831 public: | 849 public: |
832 HttpClient(); | 850 HttpClient(); |
833 | |
834 const MemoryBuffer& GetAnswerBody() const | |
835 { | |
836 return answerBody_; | |
837 } | |
838 | |
839 const MemoryBuffer& GetAnswerHeaders() const | |
840 { | |
841 return answerHeaders_; | |
842 } | |
843 | 851 |
844 uint16_t GetHttpStatus() const | 852 uint16_t GetHttpStatus() const |
845 { | 853 { |
846 return httpStatus_; | 854 return httpStatus_; |
847 } | 855 } |
892 | 900 |
893 void SwapBody(std::string& body); | 901 void SwapBody(std::string& body); |
894 | 902 |
895 void SetBody(const std::string& body); | 903 void SetBody(const std::string& body); |
896 | 904 |
897 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY == 1 | 905 void SetBody(IRequestBody& body); |
898 void SetBody(IRequestChunkedBody& body); | 906 |
899 #endif | 907 #if HAS_ORTHANC_PLUGIN_STREAMING_HTTP_CLIENT == 1 |
900 | 908 void Execute(IAnswer& answer); |
901 void Execute(); | 909 #endif |
910 | |
911 void Execute(HttpHeaders& answerHeaders /* out */, | |
912 std::string& answerBody /* out */); | |
902 }; | 913 }; |
903 #endif | 914 #endif |
904 } | 915 } |