This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new df2f5d2  THRIFT-5178: Add constructor with default host to THttpClient 
Client: cpp Patch: Mario Emmenlauer
df2f5d2 is described below

commit df2f5d2cf321f070a356872eea13dd3f68891043
Author: Mario Emmenlauer <[email protected]>
AuthorDate: Mon Apr 20 14:07:54 2020 +0200

    THRIFT-5178: Add constructor with default host to THttpClient
    Client: cpp
    Patch: Mario Emmenlauer
    
    This closes #2105
    
    The new default host is localhost. Also, the new default path is /service. 
This works around issue THRIFT-5180 where a path is required for the 
THttpTransport in Unix domain sockets.
---
 lib/cpp/src/thrift/transport/THttpClient.cpp |  4 ++++
 lib/cpp/src/thrift/transport/THttpClient.h   | 20 +++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/lib/cpp/src/thrift/transport/THttpClient.cpp 
b/lib/cpp/src/thrift/transport/THttpClient.cpp
index 04566c9..fdee787 100644
--- a/lib/cpp/src/thrift/transport/THttpClient.cpp
+++ b/lib/cpp/src/thrift/transport/THttpClient.cpp
@@ -117,6 +117,10 @@ void THttpClient::flush() {
   writeBuffer_.resetBuffer();
   readHeaders_ = true;
 }
+
+void THttpClient::setPath(std::string path) {
+  path_ = path;
+}
 }
 }
 } // apache::thrift::transport
diff --git a/lib/cpp/src/thrift/transport/THttpClient.h 
b/lib/cpp/src/thrift/transport/THttpClient.h
index fdca505..81ddc56 100644
--- a/lib/cpp/src/thrift/transport/THttpClient.h
+++ b/lib/cpp/src/thrift/transport/THttpClient.h
@@ -26,16 +26,34 @@ namespace apache {
 namespace thrift {
 namespace transport {
 
+/**
+ * @brief Client transport using HTTP. The path is an optional field that is
+ * not required by Thrift HTTP server or client. It can be used i.e. with HTTP
+ * redirection, load balancing or forwarding on the server.
+ */
 class THttpClient : public THttpTransport {
 public:
-  THttpClient(std::shared_ptr<TTransport> transport, std::string host, 
std::string path = "");
+  /**
+   * @brief Constructor that wraps an existing transport, but also sets the
+   * host and path. The host and path are not used for the connection but are
+   * set in the HTTP header of the transport.
+   */
+  THttpClient(std::shared_ptr<TTransport> transport,
+              std::string host = "localhost",
+              std::string path = "/service");
 
+  /**
+   * @brief Constructor that will create a new socket transport using the host
+   * and port.
+   */
   THttpClient(std::string host, int port, std::string path = "");
 
   ~THttpClient() override;
 
   void flush() override;
 
+  void setPath(std::string path);
+
 protected:
   std::string host_;
   std::string path_;

Reply via email to