20 #ifndef INCLUDE_RCF_HTTPFRAMEFILTER_HPP 21 #define INCLUDE_RCF_HTTPFRAMEFILTER_HPP 27 #include <RCF/ByteBuffer.hpp> 28 #include <RCF/Filter.hpp> 29 #include <RCF/RecursionLimiter.hpp> 40 typedef std::shared_ptr<MemOstream> MemOstreamPtr;
41 typedef std::shared_ptr<ReallocBuffer> ReallocBufferPtr;
44 const std::string & stringToSplit,
46 std::vector<std::string> & lines);
54 virtual void applyHeader(
const std::vector<ByteBuffer>& messageBuffers, std::string& headerName, std::string& headerValue) = 0;
62 class RCF_EXPORT HttpMessage
77 bool parseHttpMessage(
const char * pFrame, std::size_t bytesAvailable);
79 void getHttpStatus(std::string& httpStatus, std::string& httpStatusMsg);
80 void getHeaderValue(
const std::string& headerName, std::string& headerValue)
const;
82 typedef std::vector< std::pair< std::string, std::string > > HeaderList;
83 HeaderList mHeaderList;
85 std::size_t mHeaderLen;
86 std::size_t mContentLen;
87 std::size_t mFrameLen;
88 std::string mHttpMessageHeader;
89 std::vector<std::string> mMessageLines;
90 std::string mRequestLine;
91 std::string mResponseLine;
94 class HttpFrameFilter :
public Filter
99 HttpFrameFilter(
RCF::RcfServer & server, std::size_t maxMessageLength);
103 const std::string & serverAddr,
105 const std::string & serverUrlPath);
114 std::size_t bytesRequested);
116 void write(
const std::vector<ByteBuffer> &byteBuffers);
118 void onReadCompleted(
const ByteBuffer &byteBuffer);
120 void onWriteCompleted(std::size_t bytesTransferred);
122 int getFilterId()
const;
124 virtual std::size_t getFrameSize();
126 const std::string & getHttpSessionId();
127 std::uint32_t getHttpSessionIndex();
128 const std::string & getConnectionHeader();
130 void sendHttpTextResponse(
const std::string & httpStatus,
const std::string & responseText);
131 void sendHttpErrorResponse(MemOstreamPtr osPtr);
135 bool mChunkedResponseMode;
136 std::size_t mChunkedResponseCounter;
138 bool tryParseHttpHeader();
140 bool tryParseHttpChunkHeader();
142 void getHttpFrameInfo(
143 std::string& requestLine,
144 std::vector< std::pair<std::string, std::string> >& headers);
146 bool verifyReceivedMessage();
150 void processSetCookieHeader(
const std::string& headerValue);
151 void processLocationHeader();
154 void sendServerError(
int error);
156 void resizeReadBuffer(std::size_t newSize);
158 const std::string & getServerHeader();
162 std::string mServerAddr;
164 std::string mServerUrlPath;
165 std::string mServerHeaderValue;
168 std::string mHttpSessionId;
169 std::uint32_t mHttpSessionIndex;
170 std::string mConnectionHeader;
171 std::string mTransferEncoding;
173 MemOstreamPtr mOsPtr;
174 std::vector<ByteBuffer> mWriteBuffers;
175 std::size_t mWritePos;
178 std::size_t mOrigBytesRequested;
180 ReallocBufferPtr mReadBufferPtr;
181 std::size_t mBytesReceived;
182 std::size_t mReadPos;
184 bool mProtocolChecked;
185 std::size_t mChunkHeaderLen;
186 std::size_t mChunkLen;
187 std::size_t mMaxReadPos;
188 std::size_t mMaxMessageLength;
189 bool mMaxMessageLengthSet;
191 std::string mPrevHttpSessionId;
192 std::uint32_t mPrevHttpSessionIndex;
194 HttpMessage mHttpMessage;
196 std::map<std::string, HttpCookie> mCookies;
198 RecursionState<ByteBuffer, std::size_t> mRecursionStateRead;
203 #endif // ! INCLUDE_RCF_HTTPFRAMEFILTER_HPP Base class for all RCF exceptions.
Definition: Exception.hpp:67
std::shared_ptr< HttpMessageVerifier > HttpMessageVerifierPtr
Reference counted wrapper for RCF::HttpMessageVerifier.
Definition: HttpFrameFilter.hpp:60
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...
Provides RCF server-side functionality.
Definition: RcfServer.hpp:53
Definition: ByteBuffer.hpp:39
HTTP message verification mechanism, to allow applications to verify HTTP message payloads using cust...
Definition: HttpFrameFilter.hpp:49
Definition: AmiIoHandler.hpp:23
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...