OmniSciDB  04ee39c94c
ProxyTHttpClient Class Reference
+ Inheritance diagram for ProxyTHttpClient:
+ Collaboration diagram for ProxyTHttpClient:

Public Member Functions

 ProxyTHttpClient (mapd::shared_ptr< TTransport > transport, std::string host, std::string path)
 
 ProxyTHttpClient (std::string host, int port, std::string path)
 
 ~ProxyTHttpClient () override
 
void parseHeader (char *header) override
 
void flush () override
 

Public Attributes

std::vector< std::string > cookies_
 

Detailed Description

Definition at line 57 of file ThriftClient.cpp.

Constructor & Destructor Documentation

◆ ProxyTHttpClient() [1/2]

ProxyTHttpClient::ProxyTHttpClient ( mapd::shared_ptr< TTransport >  transport,
std::string  host,
std::string  path 
)
inline

Definition at line 60 of file ThriftClient.cpp.

63  : THttpClient(transport, host, path) {}

◆ ProxyTHttpClient() [2/2]

ProxyTHttpClient::ProxyTHttpClient ( std::string  host,
int  port,
std::string  path 
)
inline

Definition at line 65 of file ThriftClient.cpp.

66  : THttpClient(host, port, path) {}

◆ ~ProxyTHttpClient()

ProxyTHttpClient::~ProxyTHttpClient ( )
inlineoverride

Definition at line 68 of file ThriftClient.cpp.

68 {}

Member Function Documentation

◆ flush()

void ProxyTHttpClient::flush ( )
inlineoverride

Definition at line 80 of file ThriftClient.cpp.

References join(), and to_string().

80  {
81  /*
82  * Unfortunately the decision to write the header and the body in the same
83  * method precludes using the parent class's flush method here; in what is
84  * effectively a copy of 'flush' in THttpClient with the addition of
85  * cookies, a better error report for a header that is too large and
86  * 'Connection: keep-alive'.
87  */
88  uint8_t* buf;
89  uint32_t len;
90  writeBuffer_.getBuffer(&buf, &len);
91 
92  std::ostringstream h;
93  h << "POST " << path_ << " HTTP/1.1" << THttpClient::CRLF << "Host: " << host_
94  << THttpClient::CRLF << "Content-Type: application/x-thrift" << THttpClient::CRLF
95  << "Content-Length: " << len << THttpClient::CRLF << "Accept: application/x-thrift"
96  << THttpClient::CRLF << "User-Agent: Thrift/" << THRIFT_PACKAGE_VERSION
97  << " (C++/THttpClient)" << THttpClient::CRLF << "Connection: keep-alive"
98  << THttpClient::CRLF;
99  if (!cookies_.empty()) {
100  std::string cookie = "Cookie:" + boost::algorithm::join(cookies_, ";");
101  h << cookie << THttpClient::CRLF;
102  }
103  h << THttpClient::CRLF;
104 
105  cookies_.clear();
106  std::string header = h.str();
107  if (header.size() > (std::numeric_limits<uint32_t>::max)()) {
108  throw TTransportException(
109  "Header too big [" + std::to_string(header.size()) +
110  "]. Max = " + std::to_string((std::numeric_limits<uint32_t>::max)()));
111  }
112  // Write the header, then the data, then flush
113  transport_->write((const uint8_t*)header.c_str(),
114  static_cast<uint32_t>(header.size()));
115  transport_->write(buf, len);
116  transport_->flush();
117 
118  // Reset the buffer and header variables
119  writeBuffer_.resetBuffer();
120  readHeaders_ = true;
121  }
std::string join(T const &container, std::string const &delim)
std::string to_string(char const *&&v)
std::vector< std::string > cookies_
+ Here is the call graph for this function:

◆ parseHeader()

void ProxyTHttpClient::parseHeader ( char *  header)
inlineoverride

Definition at line 70 of file ThriftClient.cpp.

70  {
71  // note boost::istarts_with is case insensitive
72  if (boost::istarts_with(header, "set-cookie:")) {
73  std::string tmp(header);
74  std::string cookie = tmp.substr(tmp.find(":") + 1, std::string::npos);
75  cookies_.push_back(cookie);
76  }
77  THttpClient::parseHeader(header);
78  }
std::vector< std::string > cookies_

Member Data Documentation

◆ cookies_

std::vector<std::string> ProxyTHttpClient::cookies_

Definition at line 123 of file ThriftClient.cpp.


The documentation for this class was generated from the following file: