нововведение: QoS (пока пустой). добавил чтение настроек модема, пока что оно не работает в браузере и не все параметры есть. найден баг с крашем приложения при получении параметров dpdm и acm

This commit is contained in:
2024-11-06 18:00:29 +03:00
parent 6f62c3e1fa
commit eaee827261
10 changed files with 352 additions and 192 deletions

View File

@@ -36,6 +36,7 @@ std::string http::server::mime_types::toString(Mime m) {
case text_plain: return "text/plain";
case text_html: return "text/html";
case text_css: return "text/css";
case video_mp4: return "video/mp4";
case json: return "application/json";
case javascript: return "application/javascript";
case blob:

View File

@@ -15,6 +15,7 @@ namespace http::server::mime_types {
text_plain, // text/plain
text_html, // text/html
text_css, // text/css
video_mp4, // video/mp4
json, // application/json
javascript, // application/javascript
blob // application/octet-stream

View File

@@ -70,6 +70,12 @@ namespace http::server {
RequestParser::result_type RequestParser::consume(Request &req, char input) {
switch (state_) {
case expecting_payload:
req.payload.push_back(input);
if (req.payload.size() <= contentLenghtHeader - 1) {
return indeterminate;
}
return good;
case method_start:
if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
return bad;
@@ -82,36 +88,34 @@ namespace http::server {
if (input == ' ') {
state_ = uri;
return indeterminate;
} else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
return bad;
} else {
req.method.push_back(input);
return indeterminate;
}
if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
return bad;
}
req.method.push_back(input);
return indeterminate;
case uri:
if (input == ' ') {
state_ = http_version_h;
return indeterminate;
} else if (is_ctl(input)) {
return bad;
} else {
req.queryUri.push_back(input);
return indeterminate;
}
if (is_ctl(input)) {
return bad;
}
req.queryUri.push_back(input);
return indeterminate;
case http_version_h:
if (input == 'H') {
state_ = http_version_t_1;
return indeterminate;
} else {
return bad;
}
return bad;
case http_version_t_1:
if (input == 'T') {
state_ = http_version_t_2;
return indeterminate;
} else {
return bad;
}
return bad;
case http_version_t_2:
if (input == 'T') {
state_ = http_version_p;
@@ -210,12 +214,12 @@ namespace http::server {
if (input == ':') {
state_ = space_before_header_value;
return indeterminate;
} else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
return bad;
} else {
req.headers.back().name.push_back(input);
return indeterminate;
}
if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
return bad;
}
req.headers.back().name.push_back(input);
return indeterminate;
case space_before_header_value:
if (input == ' ') {
state_ = header_value;
@@ -249,15 +253,12 @@ namespace http::server {
}
contentLenghtHeader = std::stol(content_len);
state_ = expecting_payload;
if (contentLenghtHeader > HTTP_MAX_PAYLOAD) {
return bad;
}
return indeterminate;
}
return bad;
case expecting_payload:
req.payload.push_back(input);
if (req.payload.size() <= contentLenghtHeader - 1) {
return indeterminate;
}
return good;
default:
return bad;

View File

@@ -1,6 +1,7 @@
#include "server.hpp"
#include <utility>
#include <boost/beast/core/basic_stream.hpp>
#include <boost/log/trivial.hpp>
namespace http::server {
@@ -126,7 +127,12 @@ namespace http::server {
if (res->path != req.url->path) {
continue;
}
res->handle(req, rep);
try {
res->handle(req, rep);
} catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "Server::requestHandler(): what = " << e.what();
stockReply(internal_server_error, rep);
}
return;
}