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.
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 @@
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 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_;