OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 76 of file ThriftClient.cpp.

Constructor & Destructor Documentation

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

Definition at line 79 of file ThriftClient.cpp.

82  : THttpClient(transport, host, path) {}
ProxyTHttpClient::ProxyTHttpClient ( std::string  host,
int  port,
std::string  path 
)
inline

Definition at line 84 of file ThriftClient.cpp.

85  : THttpClient(host, port, path) {}
ProxyTHttpClient::~ProxyTHttpClient ( )
inlineoverride

Definition at line 87 of file ThriftClient.cpp.

87 {}

Member Function Documentation

void ProxyTHttpClient::flush ( )
inlineoverride

Definition at line 99 of file ThriftClient.cpp.

References cookies_, join(), and to_string().

99  {
100  /*
101  * Unfortunately the decision to write the header and the body in the same
102  * method precludes using the parent class's flush method here; in what is
103  * effectively a copy of 'flush' in THttpClient with the addition of
104  * cookies, a better error report for a header that is too large and
105  * 'Connection: keep-alive'.
106  */
107  uint8_t* buf;
108  uint32_t len;
109  writeBuffer_.getBuffer(&buf, &len);
110 
111  std::ostringstream h;
112  h << "POST " << path_ << " HTTP/1.1" << THttpClient::CRLF << "Host: " << host_
113  << THttpClient::CRLF << "Content-Type: application/x-thrift" << THttpClient::CRLF
114  << "Content-Length: " << len << THttpClient::CRLF << "Accept: application/x-thrift"
115  << THttpClient::CRLF << "User-Agent: Thrift/" << THRIFT_PACKAGE_VERSION
116  << " (C++/THttpClient)" << THttpClient::CRLF << "Connection: keep-alive"
117  << THttpClient::CRLF;
118  if (!cookies_.empty()) {
119  std::string cookie = "Cookie:" + boost::algorithm::join(cookies_, ";");
120  h << cookie << THttpClient::CRLF;
121  }
122  h << THttpClient::CRLF;
123 
124  cookies_.clear();
125  std::string header = h.str();
126  if (header.size() > (std::numeric_limits<uint32_t>::max)()) {
127  throw TTransportException(
128  "Header too big [" + std::to_string(header.size()) +
129  "]. Max = " + std::to_string((std::numeric_limits<uint32_t>::max)()));
130  }
131  // Write the header, then the data, then flush
132  transport_->write((const uint8_t*)header.c_str(),
133  static_cast<uint32_t>(header.size()));
134  transport_->write(buf, len);
135  transport_->flush();
136 
137  // Reset the buffer and header variables
138  writeBuffer_.resetBuffer();
139  readHeaders_ = true;
140  }
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:

void ProxyTHttpClient::parseHeader ( char *  header)
inlineoverride

Definition at line 89 of file ThriftClient.cpp.

References cookies_.

89  {
90  // note boost::istarts_with is case insensitive
91  if (boost::istarts_with(header, "set-cookie:")) {
92  std::string tmp(header);
93  std::string cookie = tmp.substr(tmp.find(":") + 1, std::string::npos);
94  cookies_.push_back(cookie);
95  }
96  THttpClient::parseHeader(header);
97  }
std::vector< std::string > cookies_

Member Data Documentation

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

Definition at line 142 of file ThriftClient.cpp.

Referenced by flush(), and parseHeader().


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