26 self->
req.method =
static_cast<HTTPMethod
>(self->method);
30 static int on_url(
http_parser* self_,
const char* at,
size_t length)
35 self->
req.
url = self->
req.
raw_url.substr(0, self->qs_point != 0 ? self->qs_point : std::string::npos);
41 static int on_header_field(
http_parser* self_,
const char* at,
size_t length)
44 switch (self->header_building_state)
47 if (!self->header_value.empty())
49 self->
req.headers.emplace(std::move(self->header_field), std::move(self->header_value));
51 self->header_field.assign(at, at + length);
52 self->header_building_state = 1;
55 self->header_field.insert(self->header_field.end(), at, at + length);
60 static int on_header_value(
http_parser* self_,
const char* at,
size_t length)
63 switch (self->header_building_state)
66 self->header_value.insert(self->header_value.end(), at, at + length);
69 self->header_building_state = 0;
70 self->header_value.assign(at, at + length);
78 if (!self->header_field.empty())
80 self->
req.headers.emplace(std::move(self->header_field), std::move(self->header_value));
83 self->set_connection_parameters();
85 self->process_header();
88 static int on_body(
http_parser* self_,
const char* at,
size_t length)
91 self->
req.body.insert(self->
req.body.end(), at, at + length);
98 self->message_complete =
true;
99 self->process_message();
106 http_parser_init(
this);
111 bool feed(
const char* buffer,
int length)
113 if (message_complete)
127 int nparsed = http_parser_execute(
this, &settings_, buffer, length);
128 if (http_errno != CHPE_OK)
132 return nparsed == length;
137 return feed(
nullptr, 0);
143 header_field.clear();
144 header_value.clear();
145 header_building_state = 0;
147 message_complete =
false;
148 state = CROW_NEW_MESSAGE();
151 inline void process_url()
153 handler_->handle_url();
156 inline void process_header()
158 handler_->handle_header();
161 inline void process_message()
166 inline void set_connection_parameters()
169 req.http_ver_minor = http_minor;
175 ((
flags & F_CONNECTION_KEEP_ALIVE) ? true :
false) :
176 ((
http_major == 1 && http_minor == 1) ? true : false);
180 ((
flags & F_CONNECTION_KEEP_ALIVE) ? false :
true) :
181 ((
http_major == 1 && http_minor == 1) ? ((
flags & F_CONNECTION_CLOSE) ? true : false) : false);
191 int header_building_state = 0;
192 bool message_complete =
false;
193 std::string header_field;
194 std::string header_value;