1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef _THRIFT_TRANSPORT_THTTPCLIENT_H_
21 #define _THRIFT_TRANSPORT_THTTPCLIENT_H_ 1
22 
23 #include <thrift/transport/THttpTransport.h>
24 
25 namespace apache {
26 namespace thrift {
27 namespace transport {
28 
29 /**
30  * @brief Client transport using HTTP. The path is an optional field that is
31  * not required by Thrift HTTP server or client. It can be used i.e. with HTTP
32  * redirection, load balancing or forwarding on the server.
33  */
34 class THttpClient : public THttpTransport {
35 public:
36   /**
37    * @brief Constructor that wraps an existing transport, but also sets the
38    * host and path. The host and path are not used for the connection but are
39    * set in the HTTP header of the transport.
40    */
41   THttpClient(std::shared_ptr<TTransport> transport,
42               std::string host = "localhost",
43               std::string path = "/service",
44               std::shared_ptr<TConfiguration> config = nullptr);
45 
46   /**
47    * @brief Constructor that will create a new socket transport using the host
48    * and port.
49    */
50   THttpClient(std::string host, int port,
51               std::string path = "",
52               std::shared_ptr<TConfiguration> config = nullptr);
53 
54   ~THttpClient() override;
55 
56   void flush() override;
57 
58   void setPath(std::string path);
59 
60 protected:
61   std::string host_;
62   std::string path_;
63 
64   void parseHeader(char* header) override;
65   bool parseStatusLine(char* status) override;
66 };
67 }
68 }
69 } // apache::thrift::transport
70 
71 #endif // #ifndef _THRIFT_TRANSPORT_THTTPCLIENT_H_
72