Mercurial > hg > orthanc
comparison Plugins/Samples/Common/OrthancPluginCppWrapper.h @ 3387:a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Jun 2019 17:17:48 +0200 |
parents | 0f721f015b85 |
children | 18cd4951fccc |
comparison
equal
deleted
inserted
replaced
3386:af9432e46c07 | 3387:a48d652f1500 |
---|---|
83 # define HAS_ORTHANC_PLUGIN_METRICS 1 | 83 # define HAS_ORTHANC_PLUGIN_METRICS 1 |
84 #else | 84 #else |
85 # define HAS_ORTHANC_PLUGIN_METRICS 0 | 85 # define HAS_ORTHANC_PLUGIN_METRICS 0 |
86 #endif | 86 #endif |
87 | 87 |
88 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 7) | |
89 # define HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY 1 | |
90 #else | |
91 # define HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY 0 | |
92 #endif | |
93 | |
88 | 94 |
89 | 95 |
90 namespace OrthancPlugins | 96 namespace OrthancPlugins |
91 { | 97 { |
92 typedef void (*RestCallback) (OrthancPluginRestOutput* output, | 98 typedef void (*RestCallback) (OrthancPluginRestOutput* output, |
769 MetricsTimer(const char* name); | 775 MetricsTimer(const char* name); |
770 | 776 |
771 ~MetricsTimer(); | 777 ~MetricsTimer(); |
772 }; | 778 }; |
773 #endif | 779 #endif |
780 | |
781 | |
782 class HttpClient : public boost::noncopyable | |
783 { | |
784 public: | |
785 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY == 1 | |
786 class IChunkedBody : public boost::noncopyable | |
787 { | |
788 public: | |
789 virtual ~IChunkedBody() | |
790 { | |
791 } | |
792 | |
793 virtual bool ReadNextChunk(std::string& chunk) = 0; | |
794 }; | |
795 #endif | |
796 | |
797 | |
798 private: | |
799 typedef std::map<std::string, std::string> HttpHeaders; | |
800 | |
801 MemoryBuffer answerBody_; | |
802 MemoryBuffer answerHeaders_; | |
803 uint16_t httpStatus_; | |
804 OrthancPluginHttpMethod method_; | |
805 std::string url_; | |
806 HttpHeaders headers_; | |
807 std::string username_; | |
808 std::string password_; | |
809 uint32_t timeout_; | |
810 std::string certificateFile_; | |
811 std::string certificateKeyFile_; | |
812 std::string certificateKeyPassword_; | |
813 bool pkcs11_; | |
814 std::string body_; | |
815 | |
816 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY == 1 | |
817 class ChunkedBody; | |
818 IChunkedBody* chunkedBody_; | |
819 #else | |
820 // Dummy variable for backward compatibility | |
821 void* chunkedBody_; | |
822 #endif | |
823 | |
824 public: | |
825 HttpClient(); | |
826 | |
827 const MemoryBuffer& GetAnswerBody() const | |
828 { | |
829 return answerBody_; | |
830 } | |
831 | |
832 const MemoryBuffer& GetAnswerHeaders() const | |
833 { | |
834 return answerHeaders_; | |
835 } | |
836 | |
837 uint16_t GetHttpStatus() const | |
838 { | |
839 return httpStatus_; | |
840 } | |
841 | |
842 void SetMethod(OrthancPluginHttpMethod method) | |
843 { | |
844 method_ = method; | |
845 } | |
846 | |
847 const std::string& GetUrl() const | |
848 { | |
849 return url_; | |
850 } | |
851 | |
852 void SetUrl(const std::string& url) | |
853 { | |
854 url_ = url; | |
855 } | |
856 | |
857 void AddHeader(const std::string& key, | |
858 const std::string& value) | |
859 { | |
860 headers_[key] = value; | |
861 } | |
862 | |
863 void SetCredentials(const std::string& username, | |
864 const std::string& password); | |
865 | |
866 void ClearCredentials(); | |
867 | |
868 void SetTimeout(unsigned int timeout) // 0 for default timeout | |
869 { | |
870 timeout_ = timeout; | |
871 } | |
872 | |
873 void SetCertificate(const std::string& certificateFile, | |
874 const std::string& keyFile, | |
875 const std::string& keyPassword); | |
876 | |
877 void ClearCertificate(); | |
878 | |
879 void SetPkcs11(bool pkcs11) | |
880 { | |
881 pkcs11_ = pkcs11; | |
882 } | |
883 | |
884 void ClearBody(); | |
885 | |
886 void SwapBody(std::string& body); | |
887 | |
888 void SetBody(const std::string& body); | |
889 | |
890 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY == 1 | |
891 void SetBody(IChunkedBody& body); | |
892 #endif | |
893 | |
894 void Execute(); | |
895 }; | |
774 } | 896 } |