/* */ #ifndef D_HTTP_HEADER_PROCESSOR_H #define D_HTTP_HEADER_PROCESSOR_H #include "common.h" #include #include #include namespace aria2 { class HttpHeader; class HttpHeaderProcessor { public: enum ParserMode { CLIENT_PARSER, SERVER_PARSER }; HttpHeaderProcessor(ParserMode mode); ~HttpHeaderProcessor(); /** * Parses incoming data. Returns true if end of header is reached. * This function stops processing data when end of header is * reached. */ bool parse(const unsigned char* data, size_t length); bool parse(const std::string& data); /** * Retruns the number of bytes processed in the last invocation of * parse(). */ size_t getLastBytesProcessed() const; /** * Processes the received header as a http response header and * returns HttpHeader object. This method transfers the ownership of * resulting HttpHeader to the caller. */ std::unique_ptr getResult(); std::string getHeaderString() const; /** * Resets internal status and ready for next header processing. */ void clear(); private: ParserMode mode_; int state_; size_t lastBytesProcessed_; std::string buf_; std::string lastFieldName_; int lastFieldHdKey_; std::unique_ptr result_; std::string headers_; }; } // namespace aria2 #endif // D_HTTP_HEADER_PROCESSOR_H