19 #ifndef INCLUDE_RCF_HTTPFRAMEFILTER_HPP 20 #define INCLUDE_RCF_HTTPFRAMEFILTER_HPP 26 #include <RCF/ByteBuffer.hpp> 27 #include <RCF/Filter.hpp> 28 #include <RCF/RecursionLimiter.hpp> 37 typedef std::shared_ptr<MemOstream> MemOstreamPtr;
38 typedef std::shared_ptr<ReallocBuffer> ReallocBufferPtr;
41 const std::string & stringToSplit,
43 std::vector<std::string> & lines);
61 bool parseHttpMessage(
const char * pFrame, std::size_t bytesAvailable);
63 void getHttpStatus(std::string& httpStatus, std::string& httpStatusMsg);
64 void getHeaderValue(
const std::string& headerName, std::string& headerValue);
66 typedef std::vector< std::pair< std::string, std::string > > HeaderList;
67 HeaderList mHeaderList;
69 std::size_t mHeaderLen;
70 std::size_t mContentLen;
71 std::size_t mFrameLen;
72 std::string mHttpMessageHeader;
73 std::vector<std::string> mHeaderLines;
74 std::string mRequestLine;
75 std::string mResponseLine;
78 class HttpFrameFilter :
public Filter
83 HttpFrameFilter(std::size_t maxMessageLength);
87 const std::string serverAddr,
96 const ByteBuffer & byteBuffer,
97 std::size_t bytesRequested);
99 void write(
const std::vector<ByteBuffer> &byteBuffers);
101 void onReadCompleted(
const ByteBuffer &byteBuffer);
103 void onWriteCompleted(std::size_t bytesTransferred);
105 int getFilterId()
const;
107 virtual std::size_t getFrameSize();
109 const std::string & getHttpSessionId();
110 std::uint32_t getHttpSessionIndex();
111 const std::string & getConnectionHeader();
113 void onError(
const Exception& e);
116 bool mChunkedResponseMode;
117 std::size_t mChunkedResponseCounter;
119 void tryParseHttpHeader();
120 void tryParseHttpChunkHeader();
122 void getHttpFrameInfo(
123 std::string& requestLine,
124 std::vector< std::pair<std::string, std::string> >& headers);
129 void sendServerError(
int error);
131 void resizeReadBuffer(std::size_t newSize);
133 std::string mServerAddr;
137 std::string mHttpSessionId;
138 std::uint32_t mHttpSessionIndex;
139 std::string mConnectionHeader;
140 std::string mTransferEncoding;
142 MemOstreamPtr mOsPtr;
143 std::vector<ByteBuffer> mWriteBuffers;
144 std::size_t mWritePos;
146 ByteBuffer mOrigReadBuffer;
147 std::size_t mOrigBytesRequested;
149 ReallocBufferPtr mReadBufferPtr;
150 std::size_t mBytesReceived;
151 std::size_t mReadPos;
153 bool mProtocolChecked;
154 std::size_t mChunkHeaderLen;
155 std::size_t mChunkLen;
156 std::size_t mMaxReadPos;
157 std::size_t mMaxMessageLength;
158 bool mMaxMessageLengthSet;
160 std::string mPrevHttpSessionId;
161 std::uint32_t mPrevHttpSessionIndex;
163 HttpMessage mHttpMessage;
165 RecursionState<ByteBuffer, std::size_t> mRecursionStateRead;
170 #endif // ! INCLUDE_RCF_HTTPFRAMEFILTER_HPP Definition: AmiIoHandler.hpp:24
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...