выкинул зависимость boost::url
This commit is contained in:
@@ -1,8 +1,38 @@
|
||||
#include "request_parser.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "request.hpp"
|
||||
|
||||
|
||||
namespace http::server {
|
||||
static void parseParams(Url& u, const std::string& query) {
|
||||
std::istringstream iss(query);
|
||||
std::string param;
|
||||
while (std::getline(iss, param, '&')) {
|
||||
size_t equal_pos = param.find('=');
|
||||
if (equal_pos != std::string::npos) {
|
||||
const std::string key = param.substr(0, equal_pos);
|
||||
const std::string value = param.substr(equal_pos + 1);
|
||||
u.params[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Url::Url(const std::string &url) {
|
||||
size_t question_mark_pos = url.find('?');
|
||||
if (question_mark_pos != std::string::npos) {
|
||||
path = url.substr(0, question_mark_pos);
|
||||
const std::string query = url.substr(question_mark_pos + 1);
|
||||
parseParams(*this, query);
|
||||
} else {
|
||||
path = url;
|
||||
}
|
||||
}
|
||||
|
||||
Url::~Url() = default;
|
||||
|
||||
|
||||
RequestParser::RequestParser()
|
||||
: state_(method_start) {
|
||||
}
|
||||
@@ -38,7 +68,7 @@ namespace http::server {
|
||||
} else if (is_ctl(input)) {
|
||||
return bad;
|
||||
} else {
|
||||
req.uri.push_back(input);
|
||||
req.queryUri.push_back(input);
|
||||
return indeterminate;
|
||||
}
|
||||
case http_version_h:
|
||||
@@ -131,7 +161,7 @@ namespace http::server {
|
||||
} else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
|
||||
return bad;
|
||||
} else {
|
||||
req.headers.push_back(header());
|
||||
req.headers.emplace_back();
|
||||
req.headers.back().name.push_back(input);
|
||||
state_ = header_name;
|
||||
return indeterminate;
|
||||
@@ -184,7 +214,11 @@ namespace http::server {
|
||||
return bad;
|
||||
}
|
||||
case expecting_newline_3:
|
||||
return (input == '\n') ? good : bad;
|
||||
if (input == '\n') {
|
||||
req.url = std::make_unique<Url>(req.queryUri);
|
||||
return good;
|
||||
}
|
||||
return bad;
|
||||
default:
|
||||
return bad;
|
||||
}
|
||||
|
Reference in New Issue
Block a user