21 #ifndef INCLUDE_RCF_HTTPFRAMEFILTER_HPP 22 #define INCLUDE_RCF_HTTPFRAMEFILTER_HPP 28 #include <RCF/ByteBuffer.hpp> 29 #include <RCF/Filter.hpp> 30 #include <RCF/RecursionLimiter.hpp> 41 typedef std::shared_ptr<MemOstream> MemOstreamPtr;
42 typedef std::shared_ptr<ReallocBuffer> ReallocBufferPtr;
45 const std::string & stringToSplit,
47 std::vector<std::string> & lines);
55 virtual void applyHeader(
const std::vector<ByteBuffer>& messageBuffers, std::string& headerName, std::string& headerValue) = 0;
63 class RCF_EXPORT HttpMessage
78 bool parseHttpMessage(
const char * pFrame, std::size_t bytesAvailable);
80 void getHttpStatus(std::string& httpStatus, std::string& httpStatusMsg);
81 void getHeaderValue(
const std::string& headerName, std::string& headerValue)
const;
83 typedef std::vector< std::pair< std::string, std::string > > HeaderList;
84 HeaderList mHeaderList;
86 std::size_t mHeaderLen;
87 std::size_t mContentLen;
88 std::size_t mFrameLen;
89 std::string mHttpMessageHeader;
90 std::vector<std::string> mMessageLines;
91 std::string mRequestLine;
92 std::string mResponseLine;
95 class HttpFrameFilter :
public Filter
100 HttpFrameFilter(std::size_t maxMessageLength);
104 const std::string & serverAddr,
106 const std::string & serverUrlPath);
115 std::size_t bytesRequested);
117 void write(
const std::vector<ByteBuffer> &byteBuffers);
119 void onReadCompleted(
const ByteBuffer &byteBuffer);
121 void onWriteCompleted(std::size_t bytesTransferred);
123 int getFilterId()
const;
125 virtual std::size_t getFrameSize();
127 const std::string & getHttpSessionId();
128 std::uint32_t getHttpSessionIndex();
129 const std::string & getConnectionHeader();
131 void sendHttpTextResponse(
const std::string & httpStatus,
const std::string & responseText);
132 void sendHttpErrorResponse(MemOstreamPtr osPtr);
136 bool mChunkedResponseMode;
137 std::size_t mChunkedResponseCounter;
139 bool tryParseHttpHeader();
141 bool tryParseHttpChunkHeader();
143 void getHttpFrameInfo(
144 std::string& requestLine,
145 std::vector< std::pair<std::string, std::string> >& headers);
147 bool verifyReceivedMessage();
151 void processSetCookieHeader(
const std::string& headerValue);
152 void processLocationHeader();
155 void sendServerError(
int error);
157 void resizeReadBuffer(std::size_t newSize);
159 const std::string & getServerHeader();
161 std::string mServerAddr;
163 std::string mServerUrlPath;
164 std::string mServerHeaderValue;
167 std::string mHttpSessionId;
168 std::uint32_t mHttpSessionIndex;
169 std::string mConnectionHeader;
170 std::string mTransferEncoding;
172 MemOstreamPtr mOsPtr;
173 std::vector<ByteBuffer> mWriteBuffers;
174 std::size_t mWritePos;
177 std::size_t mOrigBytesRequested;
179 ReallocBufferPtr mReadBufferPtr;
180 std::size_t mBytesReceived;
181 std::size_t mReadPos;
183 bool mProtocolChecked;
184 std::size_t mChunkHeaderLen;
185 std::size_t mChunkLen;
186 std::size_t mMaxReadPos;
187 std::size_t mMaxMessageLength;
188 bool mMaxMessageLengthSet;
190 std::string mPrevHttpSessionId;
191 std::uint32_t mPrevHttpSessionIndex;
193 HttpMessage mHttpMessage;
195 std::map<std::string, HttpCookie> mCookies;
197 RecursionState<ByteBuffer, std::size_t> mRecursionStateRead;
202 #endif // ! INCLUDE_RCF_HTTPFRAMEFILTER_HPP Base class for all RCF exceptions.
Definition: Exception.hpp:64
std::shared_ptr< HttpMessageVerifier > HttpMessageVerifierPtr
Reference counted wrapper for RCF::HttpMessageVerifier.
Definition: HttpFrameFilter.hpp:61
virtual void verifyHeader(const HttpMessage &msg, ByteBuffer msgData)=0
Check verification header on an incoming HTTP message, based on the message payload passed in msgData...
Definition: ByteBuffer.hpp:40
HTTP message verification mechanism, to allow applications to verify HTTP message payloads using cust...
Definition: HttpFrameFilter.hpp:50
Definition: AmiIoHandler.hpp:24
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...
virtual void applyHeader(const std::vector< ByteBuffer > &messageBuffers, std::string &headerName, std::string &headerValue)=0
Set verification header on an outgoing HTTP message, based on the message payload passed in messageBu...