1 // Copyright (c) 2006- Facebook
2 // Distributed under the Thrift Software License
4 // See accompanying file LICENSE or visit the Thrift site at:
5 // http://developers.facebook.com/thrift/
7 #ifndef _THRIFT_TRANSPORT_THTTPCLIENT_H_
8 #define _THRIFT_TRANSPORT_THTTPCLIENT_H_ 1
10 #include <transport/TTransportUtils.h>
12 namespace facebook
{ namespace thrift
{ namespace transport
{
15 * HTTP client implementation of the thrift transport. This was irritating
16 * to write, but the alternatives in C++ land are daunting. Linking CURL
17 * requires 23 dynamic libraries last time I checked (WTF?!?). All we have
18 * here is a VERY basic HTTP/1.1 client which supports HTTP 100 Continue,
19 * chunked transfer encoding, keepalive, etc. Tested against Apache.
21 * @author Mark Slee <mcslee@facebook.com>
23 class THttpClient
: public TTransport
{
25 THttpClient(boost::shared_ptr
<TTransport
> transport
, std::string host
, std::string path
="");
27 THttpClient(std::string host
, int port
, std::string path
="");
29 virtual ~THttpClient();
36 return transport_
->isOpen();
40 return transport_
->peek();
47 uint32_t read(uint8_t* buf
, uint32_t len
);
51 void write(const uint8_t* buf
, uint32_t len
);
60 boost::shared_ptr
<TTransport
> transport_
;
62 TMemoryBuffer writeBuffer_
;
63 TMemoryBuffer readBuffer_
;
72 uint32_t contentLength_
;
77 uint32_t httpBufSize_
;
79 uint32_t readMoreData();
83 void parseHeader(char* header
);
84 bool parseStatusLine(char* status
);
86 uint32_t readChunked();
87 void readChunkedFooters();
88 uint32_t parseChunkSize(char* line
);
90 uint32_t readContent(uint32_t size
);
97 }}} // facebook::thrift::transport
99 #endif // #ifndef _THRIFT_TRANSPORT_THTTPCLIENT_H_