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> mMessageLines;
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 sendHttpErrorResponse(MemOstreamPtr osPtr);
114 void onError(
const Exception& e);
117 bool mChunkedResponseMode;
118 std::size_t mChunkedResponseCounter;
120 bool tryParseHttpHeader();
121 bool tryParseHttpChunkHeader();
123 void getHttpFrameInfo(
124 std::string& requestLine,
125 std::vector< std::pair<std::string, std::string> >& headers);
130 void sendServerError(
int error);
132 void resizeReadBuffer(std::size_t newSize);
134 std::string mServerAddr;
138 std::string mHttpSessionId;
139 std::uint32_t mHttpSessionIndex;
140 std::string mConnectionHeader;
141 std::string mTransferEncoding;
143 MemOstreamPtr mOsPtr;
144 std::vector<ByteBuffer> mWriteBuffers;
145 std::size_t mWritePos;
147 ByteBuffer mOrigReadBuffer;
148 std::size_t mOrigBytesRequested;
150 ReallocBufferPtr mReadBufferPtr;
151 std::size_t mBytesReceived;
152 std::size_t mReadPos;
154 bool mProtocolChecked;
155 std::size_t mChunkHeaderLen;
156 std::size_t mChunkLen;
157 std::size_t mMaxReadPos;
158 std::size_t mMaxMessageLength;
159 bool mMaxMessageLengthSet;
161 std::string mPrevHttpSessionId;
162 std::uint32_t mPrevHttpSessionIndex;
164 HttpMessage mHttpMessage;
166 std::map<std::string, HttpCookie> mCookies;
168 RecursionState<ByteBuffer, std::size_t> mRecursionStateRead;
173 #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())...