Support data streaming on server side.

This commit is contained in:
Chunting Gu
2019-08-13 17:35:01 +08:00
parent 0ea4ab7526
commit 9b13dceab9
13 changed files with 167 additions and 59 deletions
+14 -2
View File
@@ -1,12 +1,16 @@
#ifndef WEBCC_REQUEST_PARSER_H_
#define WEBCC_REQUEST_PARSER_H_
#include <functional>
#include <string>
#include "webcc/parser.h"
namespace webcc {
using ViewMatcher =
std::function<bool(const std::string&, const std::string&, bool*)>;
class Request;
class RequestParser : public Parser {
@@ -15,10 +19,14 @@ public:
~RequestParser() override = default;
void Init(Request* request);
void Init(Request* request, ViewMatcher view_matcher);
private:
void CreateBodyHandler() override;
// Override to match the URL against views and check if the matched view
// asks for data streaming.
bool OnHeadersEnd() override;
bool Stream() const;
bool ParseStartLine(const std::string& line) override;
@@ -39,6 +47,10 @@ private:
private:
Request* request_;
// A function for matching view once the headers of a request has been
// received. The parsing will stop and fail if no view can be matched.
ViewMatcher view_matcher_;
// Form data parsing step.
enum Step {
kStart,