Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:03

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements. See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership. The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License. You may obtain a copy of the License at
0009  *
0010  *   http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing,
0013  * software distributed under the License is distributed on an
0014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015  * KIND, either express or implied. See the License for the
0016  * specific language governing permissions and limitations
0017  * under the License.
0018  */
0019 
0020 #ifndef _THRIFT_TRANSPORT_THTTPTRANSPORT_H_
0021 #define _THRIFT_TRANSPORT_THTTPTRANSPORT_H_ 1
0022 
0023 #include <thrift/transport/TBufferTransports.h>
0024 #include <thrift/transport/TVirtualTransport.h>
0025 
0026 namespace apache {
0027 namespace thrift {
0028 namespace transport {
0029 
0030 /**
0031  * HTTP implementation of the thrift transport. This was irritating
0032  * to write, but the alternatives in C++ land are daunting. Linking CURL
0033  * requires 23 dynamic libraries last time I checked (WTF?!?). All we have
0034  * here is a VERY basic HTTP/1.1 client which supports HTTP 100 Continue,
0035  * chunked transfer encoding, keepalive, etc. Tested against Apache.
0036  */
0037 class THttpTransport : public TVirtualTransport<THttpTransport> {
0038 public:
0039   THttpTransport(std::shared_ptr<TTransport> transport, std::shared_ptr<TConfiguration> config = nullptr);
0040 
0041   ~THttpTransport() override;
0042 
0043   void open() override { transport_->open(); }
0044 
0045   bool isOpen() const override { return transport_->isOpen(); }
0046 
0047   bool peek() override { return transport_->peek(); }
0048 
0049   void close() override { transport_->close(); }
0050 
0051   uint32_t read(uint8_t* buf, uint32_t len);
0052 
0053   uint32_t readEnd() override;
0054 
0055   void write(const uint8_t* buf, uint32_t len);
0056 
0057   void flush() override {
0058     resetConsumedMessageSize();
0059   };
0060 
0061   const std::string getOrigin() const override;
0062 
0063 protected:
0064   std::shared_ptr<TTransport> transport_;
0065   std::string origin_;
0066 
0067   TMemoryBuffer writeBuffer_;
0068   TMemoryBuffer readBuffer_;
0069 
0070   bool readHeaders_;
0071   bool chunked_;
0072   bool chunkedDone_;
0073   uint32_t chunkSize_;
0074   uint32_t contentLength_;
0075 
0076   char* httpBuf_;
0077   uint32_t httpPos_;
0078   uint32_t httpBufLen_;
0079   uint32_t httpBufSize_;
0080 
0081   virtual void init();
0082 
0083   uint32_t readMoreData();
0084   char* readLine();
0085 
0086   void readHeaders();
0087   virtual void parseHeader(char* header) = 0;
0088   virtual bool parseStatusLine(char* status) = 0;
0089 
0090   uint32_t readChunked();
0091   void readChunkedFooters();
0092   uint32_t parseChunkSize(char* line);
0093 
0094   uint32_t readContent(uint32_t size);
0095 
0096   void refill();
0097   void shift();
0098 
0099   static const char* CRLF;
0100   static const int CRLF_LEN;
0101 };
0102 }
0103 }
0104 } // apache::thrift::transport
0105 
0106 #endif // #ifndef _THRIFT_TRANSPORT_THTTPCLIENT_H_